Skip to content

Instantly share code, notes, and snippets.

@diegolirio
Last active March 1, 2025 01:52
Show Gist options
  • Select an option

  • Save diegolirio/d98fd37d1345e2c4cb62cf9de0342f47 to your computer and use it in GitHub Desktop.

Select an option

Save diegolirio/d98fd37d1345e2c4cb62cf9de0342f47 to your computer and use it in GitHub Desktop.

Keycloak Java Source

Install gradle

image

Creating Java Application for the Keycloak

image

Remove app module and keep just src and build.gradle

image

Creating Java SPI for the Keycloak

Setting Keycloak Direct Grant

https://github.com/diegolirio/my-keycloak/?tab=readme-ov-file#spi-login-otp-send-mail

image

Java Debug on Intellij

  1. Vá para Run → Edit Configurations.
  2. Clique no + e selecione Remote JVM Debug.
  3. Configure os seguintes parâmetros:
  • Name: Keycloak Debug
  • Transport: Socket
  • Debugger mode: Attach
  • Host: localhost
  • Port: 5005
  • Command line arguments for remote JVM: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
  1. Clique em Apply e OK.

First Request to generate opt-code

curl --location 'http://localhost:8080/realms/med/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=opt-client' \
--data-urlencode 'username=35357659869' \
--data-urlencode 'password=Teste@123' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_secret=kTnp1VX7MwpQzFkA8ZwwwuipuL2bYbEw'

Second Request to generate token by using code

curl --location 'http://localhost:8080/realms/med/protocol/openid-connect/token/otp' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=opt-client' \
--data-urlencode 'username=35357659869' \
--data-urlencode 'password=Teste@123' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_secret=kTnp1VX7MwpQzFkA8ZwwwuipuL2bYbEw' \
--data-urlencode 'opt=786190'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment