Skip to content

Add OAuth2AuthorizationRequestResolver #4911

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

Closed
andersonkyle opened this issue Dec 13, 2017 · 11 comments
Closed

Add OAuth2AuthorizationRequestResolver #4911

andersonkyle opened this issue Dec 13, 2017 · 11 comments
Assignees
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: enhancement A general enhancement
Milestone

Comments

@andersonkyle
Copy link
Contributor

Summary

When using a 3rd party OAuth provider such as Auth0 or Okta it would be very useful to allow developers to hook into the Authorization Request URI build process in order to add custom query parameters. This is because the providers mentioned above have added additional parameters on top of the specification to allow for more functionality.

Examples


Auth0

audience: The unique identifier of the target API you want to access.

This parameter impacts the format of the access token


Okta

idp: The Identity provider used to do the authentication.

This parameter instructs Okta to either use itself as the Identity Provider or to use another identity provider connected to the Okta Authorization Server.


A simple hook into the building of the URI should provide sufficient flexibility for these custom parameters and any others that are introduced in the future.

@jgrandja
Copy link
Contributor

@andersonkyle Makes sense. We'll aim to add this for 5.1

@jgrandja
Copy link
Contributor

@andersonkyle I'm finally circling back to address this requirement.

The simplest solution to allow for custom authorization request parameters would be to allow the user to provide the request parameters via the ClientRegistration configuration.

For example, if you would like to provide the audience and idp in the Authorization Request, you would configure it as follows:

spring:
  security:
    oauth2:
      client:
        registration:
          okta:
            client-id: client-id
            client-secret: secret
	    ...
	    ...
        provider:
          okta:
            authorization-uri: https://tenant1.okta.com/oauth2/v2/auth?audience=resource1&idp=https://provider2.com
	   ...
	   ...

We would ensure that any request parameters supplied in the authorization-uri are preserved when building the Authorization Request.

Would this strategy meet your requirement?

@andersonkyle
Copy link
Contributor Author

andersonkyle commented Jun 20, 2018

Yeah, that should do the trick. Thanks!

The same flexibility is needed for the token request:

{
	"grant_type":"http://auth0.com/oauth/grant-type/password-realm",
	"username": "[email protected]",
	"password": "password",
	"realm": "UserDatabase5",
	"audience": "https://api.example.com",
	"scope": "openid email profile",
	"client_id": "1234",
	"client_secret": "5678"
}

^ the above example POST /oauth/token body for a Resource Owner Password Credentials grant includes 2 additional parameters: audience, realm as well as a custom value for grant_type.

This may be worthy of a separate ticket but thought I'd mention it while you're looking at this.

Both of these improvements will make working with 3rd party providers (who love to add functionality on top of the spec) much easier!

@jgrandja
Copy link
Contributor

@andersonkyle Yes, please add a new ticket for the custom token request parameters. I'll keep this in mind.

@andersonkyle
Copy link
Contributor Author

@jgrandja Thought about the proposal a little more and while it works for simple use cases, it doesn't allow the values to be dynamic.

Here's an example:

A Client has access to multiple identity providers (Active Directory, Google and Okta's Universal Directory). The additional idp parameter allows a Client to switch between them dynamically. If we bake it into the properties file it essentially becomes static.

Perhaps a callback mechanism would work a little better?

@jgrandja
Copy link
Contributor

@andersonkyle Ok. I'll ensure a hook is provided that will allow for dynamic parameters.

@thiagotgo90
Copy link

Hi,

Maybe I shouldn't be using Security OAauth to do this (as the API say that they use a "variant of OAuth2") but:

I'm trying to use the Pocket API and they request just requires the "consumer_key" and "redirect_url" to get the token.

As pointed out by @andersonkyle would be good to customize the URI and add parameters, but also remove unnecessary. When I'm creating a ClientRegistration the builder forces me to set some parameters that are not mandatory to this specific API.

If I did not provide enough information, please just let me know.
Tks

@jgrandja
Copy link
Contributor

@andersonkyle This feature has been merged. Take a look at the following tests for usage:

public void doFilterWhenAuthorizationRequestAndAdditionalParametersProvidedThenAuthorizationRequestIncludesAdditionalParameters() throws Exception {

public void doFilterWhenAuthorizationRequestAndCustomAuthorizationRequestUriSetThenCustomAuthorizationRequestUriUsed() throws Exception {

Also, I'm planning on merging #5521 shortly as this is required in order to configure a custom OAuth2AuthorizationRequestResolver.

Please let me know how this goes and if it suits your requirements.

@andersonkyle
Copy link
Contributor Author

@jgrandja This looks great. This additional flexibility makes it simple to satisfy any OAuth provider's specific requirements. 👍

@jgrandja
Copy link
Contributor

Yeah I'm pretty happy how it turned out. The OAuth2AuthorizationRequestResolver is simple yet provides the flexibility to fulfill various use cases.

@rwinch rwinch changed the title Support Custom Query Parameters within OAuth2AuthorizationRequestUriBuilder Add OAuth2AuthorizationRequestResolver Jul 30, 2018
rwinch added a commit that referenced this issue Aug 17, 2018
…ing)

Previously there was a tangle between
DefaultOAuth2AuthorizationRequestResolver and
OAuth2AuthorizationRequestRedirectFilter with
AUTHORIZATION_REQUIRED_EXCEPTION_ATTR_NAME

This commit adds a new method that can be used for resolving the
OAuth2AuthorizationRequest when the client registration id is known.

Issue: gh-4911
@rwinch
Copy link
Member

rwinch commented Aug 17, 2018

@jgrandja @andersonkyle I put some polish on this code to remove a tangle. See 938dbbf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants