使用护照登录苹果-苹果库不在 nestjs 中返回 id_token

问题描述 投票:0回答:0

我正在使用 NestJS 使用“passport-apple”库设置 Apple Login。第一次登录返回一个包含“状态”、“代码”和“用户”但没有 id_token 的数据对象。

后续登录返回仅包含“state”和“code”的数据对象。

据我所知,Apple 不会在后续登录中返回用户对象,但“code”和“state”对于用户而言并不是唯一的,因为“state”和“code”返回的值在任何登录请求中都是不同的。现在每次用户向 Apple 发出登录请求时,我都无法识别用户。

以下是我的策略配置:

import { Inject, Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import { Strategy } from 'passport-apple';

import { readFileSync } from 'fs';

@Injectable()
export class AppleStrategy extends PassportStrategy(Strategy, 'apple') {
  constructor(configService: ConfigService) {
    super({
      clientID: configService.get<string>('APPLE_CLIENT_ID'),
      teamID: configService.get<string>('APPLE_TEAM_ID'),
      keyID: configService.get<string>('APPLE_KEY_ID'),
      key: readFileSync(
        __dirname + '/../../../apple_secret/apple_secret_key.p8',
      ),
      callbackURL: configService.get<string>('APPLE_CALLBACK_URL'),
      passReqToCallback: false,
      response_type: 'code id_token',
      scope: ['name', 'email'],
    });
  }

}

我的第一个登录响应正文:

{
"state": ".......",
"code": "..............................................",
"user": "{"name":{"firstName":"First_Name","lastName":"Last_Name"},"email":"Email"}"
}

我的后续回复正文:

{
"state": ".......",
"code": ".............................................."
}

nestjs passport.js apple-login
© www.soinside.com 2019 - 2024. All rights reserved.