-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add boilerplate for OAuth2 recipe * feat!: add initial impl for OAuth2 (#833) * feat: add initial impl of OAuth2 recipe * build: add missing bundle conf * fix: wrong recipe id * feat: clean up todos * feat: make use of getLoginChallengeInfo * fix: self-review fixes * refactor: rename OAuth2 to OAuth2Provider * feat: show logo for oauth clients * fix: Rename oauth2 to oauth2provider * test: Add e2e test for OAuth2 (#843) * test: Add e2e test for OAuth2 * fix: PR changes * feat: add tryLinkingWithSessionUser, forceFreshAuth and small test fixes * test: add explanation comment to oauth2 tests --------- Co-authored-by: Mihaly Lengyel <[email protected]> * feat: add a route we can use to force refreshes * test: extend/stabilize tests * feat: Add functions and prebuiltUI for oauth2 logout (#850) * feat: Add functions and prebuiltUI for oauth2 logout * Update lib/ts/recipe/oauth2provider/components/themes/themeBase.tsx Co-authored-by: Mihály Lengyel <[email protected]> * fix: PR changes * fix: PR changes --------- Co-authored-by: Mihály Lengyel <[email protected]> * Add OAuth2 example apps (#854) * feat: Add st-oauth2-authorization-server example * feat: Add with-oauth2-without-supertokens * feat: Add with-oauth2-with-supertokens example * feat: keep the tenantId queryparam during redirections * feat: update to match node changes * test: stability fixes * test: update dep version and fix tests * fix: ignore appname in the oauth flow if it is empty * fix: fix typo * feat: handle not initialized OAuth2Provider recipe more gracefully * feat: ignore loginChallenge queryparam on auth page if we couldn't load it * feat: show an error if the getLoginChallengeInfo errors out * feat: update prebuiltui types and add test into with-typescript * test: add more debugging options for ci * fix: shouldTryLinkingWithSessionUser * chore: update versions * ci: do not forward browser logs into the console on CI * test: improve request logging in tests * test: update test expectations to match new node logic * chore: update web-js dep version in lock --------- Co-authored-by: Mihaly Lengyel <[email protected]> * refactor: self-review fixes * refactor: self-review fixes * docs: remove oauth2 examples until the restructuring is done * chore: expand changelog * chore: set web-js version to new version branch * chore: update size limits --------- Co-authored-by: Ankit Tiwari <[email protected]>
- Loading branch information
Showing
207 changed files
with
5,435 additions
and
843 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,91 @@ | ||
import { AuthProvider, useAuth } from "react-oidc-context"; | ||
import { getApiDomain, getWebsiteDomain } from "./config"; | ||
|
||
// NOTE: For convenience, the same page/component handles both login initiation and callback. | ||
// Separate pages for login and callback are not required. | ||
|
||
const scopes = window.localStorage.getItem("oauth2-scopes") ?? "profile openid offline_access email"; | ||
const extraConfig = JSON.parse(window.localStorage.getItem("oauth2-extra-config") ?? "{}"); | ||
const extraSignInParams = JSON.parse(window.localStorage.getItem("oauth2-extra-sign-in-params") ?? "{}"); | ||
const extraSignOutParams = JSON.parse(window.localStorage.getItem("oauth2-extra-sign-out-params") ?? "{}"); | ||
|
||
const oidcConfig = { | ||
client_id: window.localStorage.getItem("oauth2-client-id"), | ||
authority: `${getApiDomain()}/auth`, | ||
response_type: "code", | ||
redirect_uri: `${getWebsiteDomain()}/oauth/callback`, | ||
scope: scopes ? scopes : "profile openid offline_access email", | ||
...extraConfig, | ||
onSigninCallback: async (user) => { | ||
// Clears the response code and other params from the callback url | ||
window.history.replaceState({}, document.title, window.location.pathname); | ||
}, | ||
}; | ||
|
||
function AuthPage() { | ||
const { signinRedirect, signinSilent, signoutSilent, signoutRedirect, user, error } = useAuth(); | ||
|
||
return ( | ||
<div> | ||
<h1 style={{ textAlign: "center" }}>OAuth2 Login Test</h1> | ||
<div style={{ display: "flex", flexDirection: "column", alignItems: "center" }}> | ||
{error && <p id="oauth2-error-message">Error: {error.message}</p>} | ||
{user && ( | ||
<> | ||
<pre id="oauth2-token-data">{JSON.stringify(user.profile, null, 2)}</pre> | ||
<button id="oauth2-logout-button" onClick={() => signoutSilent(extraSignOutParams)}> | ||
Logout | ||
</button> | ||
<button id="oauth2-logout-button-redirect" onClick={() => signoutRedirect(extraSignOutParams)}> | ||
Logout (Redirect) | ||
</button> | ||
</> | ||
)} | ||
<button id="oauth2-login-button" onClick={() => signinRedirect(extraSignInParams)}> | ||
Login With SuperTokens | ||
</button> | ||
<button id="oauth2-login-button-silent" onClick={() => signinSilent(extraSignInParams)}> | ||
Login With SuperTokens (silent) | ||
</button> | ||
<button | ||
id="oauth2-login-button-prompt-login" | ||
onClick={() => | ||
signinRedirect({ | ||
prompt: "login", | ||
...extraSignInParams, | ||
}) | ||
}> | ||
Login With SuperTokens (prompt=login) | ||
</button> | ||
<button | ||
id="oauth2-login-button-max-age-3" | ||
onClick={() => | ||
signinRedirect({ | ||
max_age: 3, | ||
...extraSignInParams, | ||
}) | ||
}> | ||
Login With SuperTokens (max_age=3) | ||
</button> | ||
<button | ||
id="oauth2-login-button-prompt-none" | ||
onClick={() => | ||
signinRedirect({ | ||
prompt: "none", | ||
...extraSignInParams, | ||
}) | ||
}> | ||
Login With SuperTokens (prompt=none) | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default function OAuth2Page() { | ||
return ( | ||
<AuthProvider {...oidcConfig}> | ||
<AuthPage /> | ||
</AuthProvider> | ||
); | ||
} |
This file contains 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,13 @@ | ||
import { getQueryParams } from "./testContext"; | ||
|
||
export function getApiDomain() { | ||
const apiPort = process.env.REACT_APP_API_PORT || 8082; | ||
const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; | ||
return apiUrl; | ||
} | ||
|
||
export function getWebsiteDomain() { | ||
const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3031; | ||
const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; | ||
return getQueryParams("websiteDomain") ?? websiteUrl; | ||
} |
This file contains 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"_comment": "contains a list of frontend-backend interface versions that this package supports", | ||
"versions": ["2.0", "3.0"] | ||
"versions": ["4.0"] | ||
} |
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.