-
Notifications
You must be signed in to change notification settings - Fork 360
feat: OAuth 2.0 Provider (behind feature flag) #12391
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3fad9f8
Added test OAuth 2.0 Provider behind feature flag
jordanh 702c0b0
self-review
jordanh f4ff46f
fix uncorked writes, proxy route
jordanh ebbaeb2
Code review fixups
jordanh 6844d9e
string-score fixup
jordanh f43d090
used signed token to transmit trusted secret
jordanh ac7a135
refactor to simplify secret sharing
jordanh 6d43a34
mawr code review fixups; ui tweak
jordanh 2d31b21
georg code review changes
jordanh 41fe5bb
matt code review changes
jordanh bd3d734
matt code review changes
jordanh ac23c9a
refactor oauthScopes to enum
jordanh 0ba3901
2025 Dec 18 code review changes
jordanh 835532a
refactor to hasProviderAccess permissions
jordanh 29a14a4
Merge remote-tracking branch 'origin/master' into feat/oauth-provider
Dschoordsch 431adda
Cleanup
Dschoordsch a17fe2e
Merge remote-tracking branch 'origin/master' into feat/oauth-provider
Dschoordsch dcb238b
Type error
Dschoordsch 9ab4508
More types
Dschoordsch 1b1a0fe
Fixes after testing the flow
Dschoordsch c2b0c30
Test for requested scopes
Dschoordsch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import graphql from 'babel-plugin-relay/macro' | ||
| import {useEffect, useState} from 'react' | ||
| import {useMutation} from 'react-relay' | ||
| import {useHistory, useLocation} from 'react-router' | ||
| import {LoaderSize} from '../types/constEnums' | ||
| import LoadingComponent from './LoadingComponent/LoadingComponent' | ||
|
|
||
| const OAuthAuthorizePage = () => { | ||
| const history = useHistory() | ||
| const location = useLocation() | ||
| const [error, setError] = useState<string | null>(null) | ||
|
|
||
| const [commitCreateCode] = useMutation(graphql` | ||
| mutation OAuthAuthorizePageMutation($input: CreateOAuthAPICodeInput!) { | ||
| createOAuthAPICode(input: $input) { | ||
| code | ||
| redirectUri | ||
| state | ||
| } | ||
| } | ||
| `) | ||
|
|
||
| useEffect(() => { | ||
| const params = new URLSearchParams(location.search) | ||
| const clientId = params.get('client_id') | ||
| const redirectUri = params.get('redirect_uri') | ||
| const responseType = params.get('response_type') | ||
| const scope = params.get('scope') | ||
| const state = params.get('state') | ||
|
|
||
| if (!clientId || !redirectUri || responseType !== 'code') { | ||
| setError('Invalid request parameters') | ||
| return | ||
| } | ||
|
|
||
| const scopes = scope ? scope.split(' ') : [] | ||
|
|
||
| commitCreateCode({ | ||
| variables: { | ||
| input: { | ||
| clientId, | ||
| redirectUri, | ||
| scopes, | ||
| state: state || undefined | ||
| } | ||
| }, | ||
| onCompleted: (data: any) => { | ||
jordanh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const {code, redirectUri, state} = data.createOAuthAPICode | ||
| const redirectUrl = new URL(redirectUri) | ||
| redirectUrl.searchParams.set('code', code) | ||
| if (state) { | ||
| redirectUrl.searchParams.set('state', state) | ||
| } | ||
| window.location.href = redirectUrl.toString() | ||
| }, | ||
| onError: (err: any) => { | ||
| let errorMessage = err.message || 'Authorization failed' | ||
|
|
||
| if ( | ||
| errorMessage.includes('Not signed in') || | ||
jordanh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| errorMessage.includes('Not authenticated') || | ||
| errorMessage.includes('401') | ||
| ) { | ||
| const currentUrl = window.location.pathname + window.location.search | ||
| history.push(`/login?redirectTo=${encodeURIComponent(currentUrl)}`) | ||
jordanh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return | ||
| } | ||
|
|
||
| errorMessage = errorMessage.replace(/^OAuth Error:\s*/i, '').replace(/^Error:\s*/i, '') | ||
|
|
||
| setError(errorMessage) | ||
| } | ||
| }) | ||
| }, [location.search, commitCreateCode, history]) | ||
|
|
||
| if (error) { | ||
| return ( | ||
| <div className='flex h-screen w-full items-center justify-center'> | ||
| <div className='rounded-lg bg-white p-8 shadow-lg'> | ||
| <h1 className='mb-4 font-bold text-2xl text-red-600'>Authorization Error</h1> | ||
| <p className='text-slate-700'>{error}</p> | ||
| <button | ||
| onClick={() => history.push('/')} | ||
| className='mt-4 rounded bg-blue-500 px-4 py-2 text-white hover:bg-blue-600' | ||
| > | ||
| Return to Home | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| return <LoadingComponent spinnerSize={LoaderSize.WHOLE_PAGE} /> | ||
| } | ||
|
|
||
| export default OAuthAuthorizePage | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 I am very confused about this. This is a route on the server, but we're serving up something different on the client route? It seems odd that there are 2 ways to generate a code: The GraphQL way & the oauth2 spec of
/oauth/authorize. Why is the GraphQL mutation needed when we have the authorize endpoint?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I was sketching things out, I had been exploring the idea of being able to "Login with Parabol." This route would sees their session cookie and immediately redirects them back to the third-party app with an authorization code without needing the full SPA to load.
This route isn't necessary for the primary authentication path tho