[7.0] Allow first party clients to skip the authorization prompt #1022
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds a new method
Client::skipsAuthorization()
. If the method returns true the client is allowed to skip the authorization prompt.Rationale
It's considered best practice to use the Authorization code grant for first party mobile apps and SPAs but Passport currently requires you to show an authorization prompt to the user ("{client} is requesting permission...") with this grant type.
It doesn't really make sense to show the authorization prompt for first party clients. If Google asked you to grant permission to Google every time you logged in to gmail it would be pretty confusing.
Allowing first party clients to skip the authorization prompt is supported by the majority of OAuth servers: Auth0, Otka, Doorkeeper, Django OAuth Toolkit, IdentityServer, Keycloak, Ory Hydra, and others. It's also explicitly allowed by the OAuth specification.
It's difficult to add this feature yourself. You have to override the Authorization controller which requires copying ~30 lines of code. You then need to register the route override in the
AuthServiceProvider
after thePassport::routes()
call and make sure to add the same middleware.There is some more background info in #1010.
Usage
To use this feature you need to extend the
Client
and override theskipsAuthorization
method. You also need to tell Passport to use your extended model in theAuthServiceProvider
.How you implement
skipsAuthorization
is up to you. For example, you may add afirst_party
boolean column to the database and check the value. Alternatively you might want to check the redirect URL and allow any client for a given domain.Backwards Compatibility
This feature is opt-in and does not do anything unless you override the
skipsAuthorization
method to return true.