im stuck on a problem for a couple of days now and i can’t figure out what im doing wrong. I tried to look up multiple guides and other questions already asked but none of them helped me.
Im trying to secure my REST api endpoints in an app that uses Micronaut as framework but i keep getting error 401 Unauthorized.
What i would like is to be able to configure directly in the application.properties my keycloak client id, secret and realm url and then secure the endpoint with: @Secured however doing so i keep getting error 401 Unauthorized.
However, if i just configure the jwks url, using the same token im able to authenticate correctly.
These are the properties that don’t work and i would like to use:
micronaut.security.enabled=true
micronaut.security.token.enabled=true
micronaut.security.token.jwt.enabled=true
micronaut.security.oauth2.enabled=true
micronaut.security.oauth2.clients.keycloak.client-id=newapp
micronaut.security.oauth2.clients.keycloak.client-secret=b0ec33fc-4fbb-5a6b-br5h-e80f4cb53c05
micronaut.security.oauth2.clients.keycloak.openid.issuer=<realmUrl>
micronaut.security.token.jwt.signatures.secret.generator.secret=<reallyLongSecret>
And these are the ones that work but using jwks url that i dont like as solution:
micronaut.security.enabled=true
micronaut.security.token.enabled=true
micronaut.security.token.jwt.enabled=true micronaut.security.token.jwt.signatures.jwks.keycloak.url=<url>/certs
The response i get is the following:
{
"_links": {
"self": [
{
"href": "/api/create",
"templated": false
}
]
},
"_embedded": {
"errors": [
{
"message": "Unauthorized"
}
]
},
"message": "Unauthorized"
}