feature: Implement support for authorization_code
OAuth flow
#269
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.
In this PR I implement support for
authorization_code
OAuth flow. See https://www.oauth.com/oauth2-servers/access-tokens/authorization-code-request/ and https://www.oauth.com/oauth2-servers/server-side-apps/authorization-code/ for details.New functionality:
AuthorizationCodeClient
. Very similar toClientCredentialsClient
, but it implementsauthorization_code
flow. Similarly toClientCredentialsClient
it acceptsclientID
, but instead ofclientSecret
it acceptsauthorizationCode
, which is something that you need to obtain in a flow that's handled byAuthorizationCodeHandler
.AuthorizationCodeHandler
. This one implements the callback handler that should receive the redirect from the browser with the authorization code once user finishes their login.AuthorizationCodeLoginFlowManager
. A helper service that orchestrates the fullauthorization_code
flow across bothAuthorizationCodeClient
andAuthorizationCodeHandler
.I think that some users may want to implement a custom login flow manager, so I think it's useful to provide individual building blocks for these, while still providing a sane default implementation.
Rough steps that are orchestrated by
AuthorizationCodeLoginFlowManager
:AuthorizationCodeHandler
starts a web server on https://localhost:8401/ (un-privileged port, so doesn't require root)AuthorizationCodeHandler
opens https://oauth.example.com/oauth2/authorize (plus some parameters there) in the browserAuthorizationCodeClient
exchanges the authorization code for an access token from OAuth Server