passport-apple throwing Invalid client id or web redirect url

176 Views Asked by At

am trying to implement a sign in using passport-apple, eventhough the steps and variables has been set, I keep getting enter image description here

I have checked the apple developer console setup, domain is correct, redirect URL is correct and from code side ...

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;
}

I can't figure out the issue

1

There are 1 best solutions below

0
On

the issue was using the app identifier as clientId, it appears that, service id should be used for clientId