app.post("/sign_in_with_apple", async (request, response) => {
const auth = new AppleAuth(
{
// use the bundle ID as client ID for native apps, else use the service ID for web-auth flows
// https://forums.developer.apple.com/thread/118135
client_id:
request.query.useBundleId === "true"
? process.env.BUNDLE_ID
: process.env.SERVICE_ID,
team_id: process.env.TEAM_ID,
redirect_uri:
"https://flutter-sign-in-with-apple-example.glitch.me/callbacks/sign_in_with_apple", // does not matter here, as this is already the callback that verifies the token after the redirection
key_id: process.env.KEY_ID
},
process.env.KEY_CONTENTS.replace(/\|/g, "\n"),
"text"
);
console.log(request.query);
const accessToken = await auth.accessToken(request.query.code);
const idToken = jwt.decode(accessToken.id_token);
const userID = idToken.sub;
console.log(idToken);
// `userEmail` and `userName` will only be provided for the initial authorization with your app
const userEmail = idToken.email;
const userName = `${request.query.firstName} ${request.query.lastName}`;
// ??♀️ TODO: Use the values provided create a new session for the user in your system
const sessionID = `NEW SESSION ID for ${userID} / ${userEmail} / ${userName}`;
console.log(`sessionID = ${sessionID}`);
response.json({ sessionId: sessionID });
});
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}