You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用passport-apple实现登录时提示Invalid client id or web redirect url

使用passport-apple实现Apple登录持续报错,排查配置后仍无法定位问题

我正在用passport-apple库实现Apple登录功能,已经完成了Apple开发者控制台的域名、重定向URL配置,代码层面也按文档做了设置(如下代码),但始终收到错误提示(见截图)。我反复核对了开发者后台的各项配置和代码里的变量对应关系,还是找不到问题出在哪。

const fs = require('fs');
const _ = require("lodash");
const AppleStrategy = require('passport-apple');
const authorizationService = require('../service/authorization.service');
const path = require('path');


//adding some comment for change
const keyFilePath = 'ff.p8';

module.exports = function (passport) {

    const express = require('express')
        , router = express.Router()
        , config = require('./config')
        , userService = require('../service/user.service')
        , jwt = require('jsonwebtoken');


    const appleConf = {
        clientID: config.apple_client_id,
        teamID: config.apple_team_id,
        keyID: config.apple_key_id,
        privateKeyLocation: path.join(__dirname, keyFilePath),
        callbackURL: config.apple_callback_url,
        passReqToCallback: true
    }

    router.use(express.json());
    router.use(express.urlencoded({ extended: true }));

    // Passport session setup.
    passport.serializeUser(function (user, done) {
        done(null, user);
    });

    passport.deserializeUser(function (obj, done) {
        // console.log('deserializing', obj)
        done(null, obj);
    });



    // Set up the Apple strategy
    passport.use(
        new AppleStrategy(
            appleConf
            ,
            (accessToken, refreshToken, profile, done) => {
                console.log("profile data is", profile)
                // You can use the `profile` object to access user information.
                // Here, we are just passing the profile to the `done` function.
                done(null, profile);
            }
        )
    );



    router.get('/apple', passport.authenticate('apple'));


    router.post('/apple/callback',
        passport.authenticate('apple', {

        }),
        function (req, res) {
            let user = req.session.passport.user
            let userJson = JSON.stringify(user)
            const accessToken = jwt.sign({ user: userJson }, config.secret);
            res.cookie('token', accessToken, { maxAge: 1 * 3600 * 1000 });

            if (user.status == 'profile_not_complete') {
                res.redirect(`http://${config.host}:${config.port}/complete-profile`);

                return;
            }

            if (user.status == 'active') {
                res.redirect(`http://${config.host}:${config.port}`);
            }

        });



    return router;
}

内容的提问来源于stack exchange,提问作者Exorcismus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 11:56:20