我尝试使用passport-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;
}
字符串
我想不通
1条答案
按热度按时间wljmcqd81#
问题是将应用程序标识符用作
clientId
,似乎应该将服务ID用于clientId