-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: partial support for Signin with Apple (mostly)
* This is almost working but I can't get apple to return the email claim in the idtoken. * Also requires a special build of @architect/functions to set ARC_SESSION_SAME_SITE=None to support apple's form_post scenario (which requires a lax SameSite cookie)
- Loading branch information
1 parent
0f29b29
commit 3f60f47
Showing
17 changed files
with
317 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from "react" | ||
import SignInWithProvider from "./SignInWithProvider" | ||
|
||
// TODO: Style https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_js/displaying_sign_in_with_apple_buttons | ||
const SignInWithApple = (): JSX.Element => { | ||
return <SignInWithProvider provider="APPLE" label="Apple" /> | ||
} | ||
|
||
export default SignInWithApple |
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,8 @@ | ||
import React from "react" | ||
import SignInWithProvider from "./SignInWithProvider" | ||
|
||
const SignInWithGoogle = (): JSX.Element => { | ||
return <SignInWithProvider provider="GOOGLE" label="Google" /> | ||
} | ||
|
||
export default SignInWithGoogle |
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,20 @@ | ||
import React from "react" | ||
|
||
const SignInWithProvider = (props: { | ||
provider: string, | ||
label: string | ||
}): JSX.Element => { | ||
return ( | ||
<button | ||
type="button" | ||
className="btn btn-outline-primary d-block btn-signin m-1" | ||
onClick={() => { | ||
window.location.href = process.env.PUBLIC_URL + `/auth/login/${props.provider}` | ||
}} | ||
> | ||
{`Sign in with ${props.label}`} | ||
</button> | ||
) | ||
} | ||
|
||
export default SignInWithProvider |
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,20 @@ | ||
import * as arc from "@architect/functions" | ||
import { HttpRequest, HttpResponse } from "@architect/functions" | ||
|
||
const handlerImp = async function handlerImp( | ||
req: HttpRequest | ||
): Promise<HttpResponse> { | ||
return { | ||
headers: { | ||
"content-type": "application/json", | ||
}, | ||
statusCode: 200, | ||
body: JSON.stringify({ | ||
message: | ||
"This is a useful debugging tool just to see what a request payload looks like.", | ||
request: req, | ||
}), | ||
} | ||
} | ||
|
||
export const handler = arc.http.async(handlerImp) |
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 * as arc from "@architect/functions" | ||
import oAuthRedirectHandlerFactory from "@architect/shared/architect/oauth/handlers/redirect" | ||
import tokenRepositoryFactory from "@architect/shared/architect/oauth/repository/TokenRepository" | ||
import userRepositoryFactory from "@architect/shared/architect/oauth/repository/UserRepository" | ||
import { fetchJson } from "@architect/shared/fetch" | ||
|
||
const impl = oAuthRedirectHandlerFactory( | ||
fetchJson, | ||
userRepositoryFactory(), | ||
tokenRepositoryFactory() | ||
) | ||
|
||
export const handler = arc.http.async(impl) |
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,37 @@ | ||
import * as jwt from "node-webtokens" | ||
|
||
/** | ||
* Generates a client secret for Sign in with Apple's OIDC Flow as described at https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens | ||
* @param appleTeamID The 10-character Team ID associated with your Apple developer account. | ||
* @param appleClientID The client ID value associated with your Sign in with Apple service ID. | ||
* @param appleKeyID They Key ID for the apple private key. Get it from the Apple Developer console at https://developer.apple.com/account/resources/authkeys/list selecting your key and then find the 10-digit identifier under "Key ID". | ||
* @param applePrivateKey The private key contents you received from Apple (note this is the value of the key, inside of the file you downloaded from Apple). | ||
*/ | ||
export function appleSecret( | ||
appleTeamID: string, | ||
appleClientID: string, | ||
appleKeyID: string, | ||
applePrivateKey: string | ||
): string { | ||
if (!applePrivateKey) throw new Error("applePrivateKey must be specified") | ||
if (!appleKeyID) throw new Error("appleKeyID must be specified") | ||
|
||
const kid = appleKeyID | ||
const keyStore: Record<string, string> = {} | ||
keyStore[kid] = applePrivateKey | ||
|
||
const payload = { | ||
iss: appleTeamID, | ||
exp: fromMinutes(2), | ||
aud: "https://appleid.apple.com", | ||
sub: appleClientID, | ||
} | ||
const secret = jwt.generate("ES256", payload, keyStore, kid) | ||
return secret | ||
} | ||
|
||
function fromMinutes(minutes: number): number { | ||
const MS_PER_SECOND = 1000 | ||
const SECONDS_PER_MIN = 60 | ||
return minutes * SECONDS_PER_MIN + Date.now() / MS_PER_SECOND | ||
} |
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
Oops, something went wrong.