Skip to content
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

feat: add auth0connection param #981

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions account-kit/signer/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
const {
authProviderId,
isCustomProvider,
auth0Connection,
scope: providedScope,
claims: providedClaims,
mode,
Expand Down Expand Up @@ -547,6 +548,9 @@ export class AlchemySignerWebClient extends BaseSignerClient<ExportWalletParams>
if (claims) {
params.claims = claims;
}
if (auth0Connection) {
params.connection = auth0Connection;
}
authUrl.search = new URLSearchParams(params).toString();
return authUrl.toString();
};
Expand Down
10 changes: 4 additions & 6 deletions account-kit/signer/src/oauth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { sha256 } from "viem";
import type { KnownAuthProvider } from "./signer";

/**
* Turnkey requires the nonce in the id token to be in this format.
Expand All @@ -15,14 +16,11 @@ export type ScopeAndClaims = {
claims?: string;
};

const DEFAULT_SCOPE_AND_CLAIMS: Record<string, ScopeAndClaims> = {
const DEFAULT_SCOPE_AND_CLAIMS: Record<KnownAuthProvider, ScopeAndClaims> = {
google: { scope: "openid email" },
apple: { scope: "openid email" },
facebook: { scope: "openid email" },
twitch: {
scope: "openid user:read:email",
claims: JSON.stringify({ id_token: { email: null } }),
},
auth0: { scope: "openid email" },
};

/**
Expand All @@ -32,7 +30,7 @@ const DEFAULT_SCOPE_AND_CLAIMS: Record<string, ScopeAndClaims> = {
* @returns {ScopeAndClaims | undefined} default scope and claims
*/
export function getDefaultScopeAndClaims(
knownAuthProviderId: string
knownAuthProviderId: KnownAuthProvider
): ScopeAndClaims | undefined {
return DEFAULT_SCOPE_AND_CLAIMS[knownAuthProviderId];
}
28 changes: 23 additions & 5 deletions account-kit/signer/src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,37 @@ export type AuthParams =
}
| ({
type: "oauth";
authProviderId: string;
isCustomProvider?: boolean;
scope?: string;
claims?: string;
} & RedirectConfig)
} & OauthProviderConfig &
OauthRedirectConfig)
| { type: "oauthReturn"; bundle: string; orgId: string };

export type OauthMode = "redirect" | "popup";
export type OauthProviderConfig =
| {
authProviderId: "auth0";
isCustomProvider?: false;
dphilipson marked this conversation as resolved.
Show resolved Hide resolved
auth0Connection?: string;
}
| {
authProviderId: KnownAuthProvider;
isCustomProvider?: false;
auth0Connection?: never;
}
| {
authProviderId: string;
dphilipson marked this conversation as resolved.
Show resolved Hide resolved
isCustomProvider: true;
auth0Connection?: never;
};

export type RedirectConfig =
export type OauthRedirectConfig =
| { mode: "redirect"; redirectUrl: string }
| { mode: "popup"; redirectUrl?: never };

export type KnownAuthProvider = "google" | "apple" | "facebook" | "auth0";

export type OauthMode = "redirect" | "popup";

export const AlchemySignerParamsSchema = z
.object({
client: z
Expand Down
Loading