Skip to content

Commit

Permalink
feat: add a route we can use to force refreshes
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Aug 18, 2024
1 parent 55ace9c commit b63bd81
Show file tree
Hide file tree
Showing 66 changed files with 4,764 additions and 3,566 deletions.
7 changes: 4 additions & 3 deletions examples/for-tests/src/AppWithReactDomRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { EmailPasswordPreBuiltUI } from "supertokens-auth-react/recipe/emailpass
import { PasswordlessPreBuiltUI } from "supertokens-auth-react/recipe/passwordless/prebuiltui";
import { EmailVerificationPreBuiltUI } from "supertokens-auth-react/recipe/emailverification/prebuiltui";
import { ThirdPartyPreBuiltUI, SignInAndUpCallback } from "supertokens-auth-react/recipe/thirdparty/prebuiltui";
import { OAuth2ProviderPreBuiltUI } from "supertokens-auth-react/recipe/oauth2provider/prebuiltui";
import { AccessDeniedScreen } from "supertokens-auth-react/recipe/session/prebuiltui";
import { MultiFactorAuthPreBuiltUI } from "supertokens-auth-react/recipe/multifactorauth/prebuiltui";
import { TOTPPreBuiltUI } from "supertokens-auth-react/recipe/totp/prebuiltui";
Expand All @@ -31,7 +32,7 @@ function AppWithReactDomRouter(props) {
const emailVerificationMode = window.localStorage.getItem("mode") || "OFF";
const websiteBasePath = window.localStorage.getItem("websiteBasePath") || undefined;

let recipePreBuiltUIList = [TOTPPreBuiltUI];
let recipePreBuiltUIList = [TOTPPreBuiltUI, OAuth2ProviderPreBuiltUI];
if (enabledRecipes.some((r) => r.startsWith("thirdparty"))) {
recipePreBuiltUIList.push(ThirdPartyPreBuiltUI);
}
Expand Down Expand Up @@ -174,8 +175,8 @@ function AppWithReactDomRouter(props) {
/>
)}

<Route path="/oauth2/login" element={<OAuth2Page />} />
<Route path="/oauth2/callback" element={<OAuth2Page />} />
<Route path="/oauth/login" element={<OAuth2Page />} />
<Route path="/oauth/callback" element={<OAuth2Page />} />
</Routes>
</BaseComponent>
</Router>
Expand Down
66 changes: 51 additions & 15 deletions examples/for-tests/src/OAuth2Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,76 @@ 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()}/oauth2/callback`,
scope: "profile openid offline_access email",
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, signoutSilent, user, error } = useAuth();
const { signinRedirect, signinSilent, signoutSilent, user, error } = useAuth();

return (
<div>
<h1 style={{ textAlign: "center" }}>OAuth2 Login Test</h1>
<div>
{user ? (
<div style={{ display: "flex", flexDirection: "column", alignItems: "center" }}>
<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()}>
<button id="oauth2-logout-button" onClick={() => signoutSilent(extraSignOutParams)}>
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>
</>
)}
<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>
);
Expand Down
4 changes: 2 additions & 2 deletions lib/build/arrowLeftIcon.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/build/authCompWrapper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/build/authRecipe-shared.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions lib/build/authRecipe-shared2.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/build/emailLargeIcon.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/build/emailpassword-shared.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b63bd81

Please sign in to comment.