-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Showing
42 changed files
with
569 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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 oidcConfig = { | ||
client_id: window.localStorage.getItem("oauth2-client-id"), | ||
authority: `${getApiDomain()}/auth`, | ||
response_type: "code", | ||
redirect_uri: `${getWebsiteDomain()}/oauth2/callback`, | ||
scope: "profile openid offline_access email", | ||
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, signoutSilent, user, error } = useAuth(); | ||
|
||
return ( | ||
<div> | ||
<h1 style={{ textAlign: "center" }}>OAuth2 Login Test</h1> | ||
<div> | ||
{user ? ( | ||
<div style={{ display: "flex", flexDirection: "column", alignItems: "center" }}> | ||
<pre id="oauth2-token-data">{JSON.stringify(user.profile, null, 2)}</pre> | ||
<button id="oauth2-logout-button" onClick={() => signoutSilent()}> | ||
Logout | ||
</button> | ||
</div> | ||
) : ( | ||
<div style={{ display: "flex", flexDirection: "column", alignItems: "center" }}> | ||
{error && <p id="oauth2-error-message">Error: {error.message}</p>} | ||
<button id="oauth2-login-button" onClick={() => signinRedirect()}> | ||
Login With SuperTokens | ||
</button> | ||
</div> | ||
)} | ||
</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; | ||
} |
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.