/auth-test

Primary LanguageJava

Install postgresql:

Execute this command from root project

docker compose up -d  

Start application

Liquibase will create anything for you

Test with in memory (Default)

Go to DefaultSecurityConfig and comment out the lines below:

    //@Bean
    //public OAuth2AuthorizationService oAuth2AuthorizationService(JdbcTemplate template, RegisteredClientRepository registeredClientRepository) {
    //    return new JdbcOAuth2AuthorizationService(template, registeredClientRepository);
    //}

Test with database

Go to DefaultSecurityConfig and uncomment the lines below:

    @Bean
    public OAuth2AuthorizationService oAuth2AuthorizationService(JdbcTemplate template, RegisteredClientRepository registeredClientRepository) {
        return new JdbcOAuth2AuthorizationService(template, registeredClientRepository);
    }

Login:

PKCE Generator: https://developer.pingidentity.com/en/tools/pkce-code-generator.html

Open in browser and login

User: user1 Password: password

http://localhost:9009/oauth2/authorize?
response_type=code
&client_id=messaging-client
&scope=openid
&redirect_uri=http://localhost:8080
&code_challenge=t3RzPLjc8NiO_mpmIuTJYi2P6Ps8y9jP6cphOhSNozw
&code_challenge_method=S256

GET Token -> Replace code from first call

POST http://localhost:9009/oauth2/token?client_id=messaging-client
&redirect_uri=http://localhost:8080
&grant_type=authorization_code
&scope=openid
&code=vuQU-CV2pTgRud8tJpBwehskC4Ef5FXemRyh6oiW0gzgiyx6ka-o5SiFvw_e_crnwtgpIpknJFc7MgLfizAgIbiCJma5onH5J6Bj3NRcChtjya5nWiA13UMIrRGhnct-
&code_verifier=mlZDBO_BNru6SRVHWhhAMJIsVCAdVZAL8VRTpy8hXBzcOJ92gKHtXPI3Agb0FF-l5NtYIbAcrl7bsHqSVJNDVWa0sjSoe0RvdwNy4Yz6StaQ-vd7uU0IRg-1tshE19PA

> {%
client.global.set("AUTH_TOKEN",response.body.access_token);
client.global.set("ID_TOKEN",response.body.id_token);
%}
>

Response:

{
  "access_token": "eyJraWQiOiJlNDY4N2Y1My1kNTY0LTQ4OTEtOTUwNS1iNjU0YjFhYzUxODEiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJ1c2VyMSIsImF1ZCI6Im1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jESq2cxC7vzrY6OWNfNcjk0n2Vm4F85w54w6Nl9hoxY7w-vp2n_pX0OGLpjeUA9EtVgH4gPi_AKp8D17u69HDif9PA_fJ3t16Gi3GxuFrhKGfW7Si9xOD0nrj12TiXzjfeJVFqUzRlU0aKCw",
  "token_type": "Bearer",
  "expires_in": 299
}

Open https://jwt.io/ and copy paste id_token

With in memory: "sid": "_SlzQEtZOtndaZuOnnn3IJHKEWmEjHDnZsJ3KfuEIUQ" With db: missing