UNPKG

passport-apple-verify-token

Version:

Sign In with Apple Token strategy for Passport, let's you validate the user token server side, usefull for mobile app SignIn with Apple authentication for example. The validation is done by using the public AppleID authentication keys.

90 lines (89 loc) 2.91 kB
/** * Module dependencies. */ import { Strategy } from 'passport-strategy'; declare type Options = { clientId?: string | string[]; appleIdKeysUrl?: string; passReqToCallback?: boolean; appleIssuer?: string; }; /** * `Strategy` constructor. * * The SignIn with Apple authentication strategy authenticates requests by verifying the * signature and fields of the token. * * Applications must supply a `verify` callback which accepts the `idToken` * coming from the user to be authenticated, and then calls the `done` callback * supplying a `parsedToken` (with all its information in visible form) and the * `appleId`. * * Options: * - `appleIdKeysUrl` // Specify the url to get Apple auth keys * * Examples: * * passport.use(new AppleTokenStrategy({ * clientID: 'apple_client_id', // Specify the CLIENT_ID of the app that accesses the backend * // Or, if multiple clients access the backend: * //[CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3] * appleIdKeysUrl?: 'https://appleid.apple.com/auth/keys', // OPTIONAL: Specify the url to get Apple auth keys * passReqToCallback?: false, // OPTIONAL: Specify if the request is passed to callback * appleIssuer?: 'https://appleid.apple.com' OPTIONAL: the Apple token issuer * }, * function(parsedToken, appleId, done) { * User.findOrCreate(..., function (err, user) { * done(err, user); * }); * } * )); * * @param {Object} options * @param {Function} verify * @api public */ export declare class AppleTokenStrategy extends Strategy { name: string; verify: (...args: any[]) => void; passReqToCallback: boolean; appleIdKeysUrl: string; clientId?: string | string[]; appleIssuer?: string; constructor(options: (() => Options) | Options, verify?: (...args: any[]) => void); /** * Authenticate request by verifying the token * * @param {Object} req * @api protected */ authenticate(req: any, options: Options): void; /** * Verify signature and token fields * To verify the identity token, your app server must: * Verify the JWS E256 signature using the server’s public key * * Verify the nonce for the authentication * * Verify that the iss field contains https://appleid.apple.com * * Verify that the aud field is the developer’s client_id * * Verify that the time is earlier than the exp value of the token * * @param {String} idToken * @api protected */ verifyAppleToken(idToken: string): Promise<any>; /** * Gets the id token value from req using name for lookup in req.body, req.query, * and req.params. * * @param {express.Request} req * @param {string} name the key to use to lookup id token in req. * @api protected */ private paramFromRequest; private getBearerToken; } export {};