Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openid Resource Server: Authenticate with Authorization Header #77

Closed
juliuskrah opened this issue Sep 13, 2019 · 9 comments
Closed

Openid Resource Server: Authenticate with Authorization Header #77

juliuskrah opened this issue Sep 13, 2019 · 9 comments
Labels
closed: question The issue is a question

Comments

@juliuskrah
Copy link

juliuskrah commented Sep 13, 2019

Feature Request

When I use an access token directly in the Authorization Header with Scheme Bearer, I get a 401 response.

Is there a mechanism I can configure for Resource Server?

Micronaut Security: 1.2.0
OS: Windows: 10
JDK: 11

@jameskleeh
Copy link
Contributor

It's not clear to me what you're trying to do

@juliuskrah
Copy link
Author

I want to be able to validate Oauth2 Jwt tokens in a stateless manner using the JWK_Set Url for public key validation. Similar to what Spring Security 5 does for Oauth2 resource server.

What I have done now is use a filter to validate all Jwt Bearer tokens in the Authorization header.

At the moment Micronaut Security Oauth2/OIDC support is stateful using a cookie mechanism.

@jameskleeh
Copy link
Contributor

jameskleeh commented Sep 23, 2019

@juliuskrah That is already being done. The token returned by OpenID providers is validated against their key set URL. The only thing that is stateful is the storage of state/nonce so that it can be validated after the redirect.

@juliuskrah
Copy link
Author

I’m aware of this. In a Microservice architecture only one service, usually the UI will handle the Login (Authorization Code Flow), other services will deal with just the Bearer Tokens.
These tokens must be validated.

Micronaut puts these tokens in the cookie which I cannot validate in the Authorization flow.

In my case one Micronaut service works with Auth Code flow with tokens created by Micronaut stored cokies. This service communicates with another Micronaut app by sending the original Jwt from the Identity Provider in the header.
The second service (resource server) must validate the Jwt against the identity provider (no need for another login via Auth flow). This is the portion that’s missing, the verification with the public key.

I hope this clarifies stuff

@jameskleeh
Copy link
Contributor

Micronaut puts these tokens in the cookie which I cannot validate in the Authorization flow.

That is only the case if you have configured it to do so. That is not the default. You can enable the keys controller in the authorization service and have the other services use that

https://micronaut-projects.github.io/micronaut-security/1.2.x/guide/#keys

https://micronaut-projects.github.io/micronaut-security/1.2.x/guide/#jwks

@jameskleeh jameskleeh added closed: question The issue is a question and removed status: awaiting feedback labels Sep 23, 2019
@juliuskrah
Copy link
Author

I will look at this and revert

@juliuskrah
Copy link
Author

@jameskleeh this works. I used

micronaut:
  security:
    enabled: true
    token:
      jwt:
        enabled: true
        signatures:
          jwks:
            keycloak:
              url: 'https://<domain>:<port>/auth/realms/<realm>/protocol/openid-connect/certs'

I wasn't interested in the keys endpoint.

Question: Any suggestion on how to customize the getName() to use preferred_username instead of Subject?

Question: Also any suggestion on how to extract the roles or scopes to participate in the @Secured({"ROLE_ADMIN", "ROLE_X"}) flow

@jameskleeh
Copy link
Contributor

jameskleeh commented Sep 23, 2019 via email

@juliuskrah
Copy link
Author

Copy that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed: question The issue is a question
Projects
None yet
Development

No branches or pull requests

2 participants