arendajaelu / nestjs-passport-apple

Apple Passport Strategy for Apple Login (dedicated to Nestjs)
MIT License
16 stars 6 forks source link

Always return `Error: secretOrPrivateKey must have a value` #1

Closed kiJu2 closed 1 year ago

kiJu2 commented 1 year ago

Thank for owner(developer) of this package. πŸ˜€

I use this package but have a problem.

  stack: [
    'Error: secretOrPrivateKey must have a value\n' +
      '    at Object.module.exports [as sign] (/Users/kiju/workspace/grother/grother-core/node_modules/jsonwebtoken/sign.js:107:20)\n' +
      '    at AppleStrategy._getClientSecret (/Users/kiju/workspace/grother/grother-core/node_modules/@arendajaelu/nestjs-passport-apple/src/strategy.js:247:21)\n' +
      '    at AppleStrategy._getOAuth2Client (/Users/kiju/workspace/grother/grother-core/node_modules/@arendajaelu/nestjs-passport-apple/src/strategy.js:264:48)\n'

I think about cause keyFilePath is parameter but no import and any handling in package.

Why exist keyFilePath ?


class AppleStrategy extends passport.Strategy {
    /**
     * @param {object} options
     * @param {string} options.clientID
     * @param {string} options.teamID
     * @param {string} options.keyID
     * @param {string} options.keyFilePath // <--- Not use in this file
     * @param {string} [options.authorizationURL=https://appleid.apple.com/auth/authorize]
     * @param {string} [options.tokenURL=https://appleid.apple.com/auth/token]
     * @param {Array<string>} [options.scope]
     * @param {string} [options.sessionKey]
     * @param {boolean} [options.state]
     * @param {boolean} [options.passReqToCallback=false]
     * @param {string} [options.callbackURL]
     * @param {function} verify
     */
    constructor(options = {}, verify) {
        if (!verify) throw new TypeError('AppleStrategy requires a verify callback');
        if (!options.clientID) throw new TypeError('AppleStrategy requires a clientID option');
        if (!options.teamID) throw new TypeError('AppleStrategy requires a teamID option');
        if (!options.keyID) throw new TypeError('AppleStrategy requires a keyID option');
        if (!options.keyFilePath) throw new TypeError('AppleStrategy requires a keyFilePath option');

        super();
        this.name = 'apple';
        this._verify = verify;

        this._clientID = options.clientID;
        this._teamID = options.teamID;
        this._keyID = options.keyID;
        this._key = options.key; // <-- And ref this key. but not parameter and not read file use keyFilePath

Watch comment

     * @param {string} options.keyFilePath // <--- Not use in this file
        this._key = options.key; // <-- And ref this key. but not parameter and not read file use keyFilePath
arendajaelu commented 1 year ago

Thank you for pointing it out.

GelistirmeKF commented 1 year ago

Workaround for this issue is to assign keyFilePath variable with key value in PassportStrategy file's constructor:

@Injectable() export class AppleCustomerStrategy extends PassportStrategy(Strategy, 'apple') { constructor(config: ConfigService) { super({ clientID: config.get('APPLE_CLIENTID'), teamID: config.get('APPLE_TEAMID'), keyID: config.get('APPLE_KEYID'), //keyFilePath: config.get('APPLE_KEYFILE_PATH'), keyFilePath: -----BEGIN PRIVATE KEY----- XXXXX, .....