如何在 Parse Server 中处理苹果回调

How to handle the apple callback in Parse Server

我的 Sign in with apple 工作到我用 apple 登录的程度,并且 apple 使用 Post 请求重定向到我的服务器。

我设置了以下 express post 处理程序:

app.post('/apple-callback', async function (req, res) {
    let data = req.body.id_token
    let buff = Buffer.from(data.split('.')[1], 'base64')
    let text = buff.toString('utf8')
    let json = JSON.parse(text)
    try {
        let currentUser = await Parse.User.logInWith('apple', {
            'authData':{
                'id': json.sub,
                'token': data
            } 
        })

        console.info(currentUser)
    } catch (error) {
        console.error(error)
    }

    res.json({
        'fissa': req.body,
        'state': req.body.state,
        'code': req.body.code,
        'idToken': req.body.id_token,
        json,
        sub: json.sub
    })
})

但我收到以下错误:

Feb 25, 2020, 15:56:39 +01:00- ERROR
Uncaught internal server error. { JsonWebTokenError: invalid signature
    at /opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:133:19
    at getSecret (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:90:14)
    at Object.module.exports [as verify] (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:94:10)
    at verifyIdToken (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/index.js:43:25)
    at process._tickCallback (internal/process/next_tick.js:68:7) name: 'JsonWebTokenError', message: 'invalid signature' } JsonWebTokenError: invalid signature
    at /opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:133:19
    at getSecret (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:90:14)
    at Object.module.exports [as verify] (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:94:10)
    at verifyIdToken (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/index.js:43:25)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Feb 25, 2020, 15:56:39 +01:00- ERROR
JsonWebTokenError: invalid signatureJsonWebTokenError: invalid signature
    at /opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:133:19
    at getSecret (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:90:14)
    at Object.module.exports [as verify] (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:94:10)
    at verifyIdToken (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/index.js:43:25)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Feb 25, 2020, 15:56:39 +01:00- ERROR
Uncaught internal server error. { JsonWebTokenError: invalid signature
    at /opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:133:19
    at getSecret (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:90:14)
    at Object.module.exports [as verify] (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:94:10)
    at verifyIdToken (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/index.js:43:25)
    at process._tickCallback (internal/process/next_tick.js:68:7) name: 'JsonWebTokenError', message: 'invalid signature' } JsonWebTokenError: invalid signature
    at /opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:133:19
    at getSecret (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:90:14)
    at Object.module.exports [as verify] (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:94:10)
    at verifyIdToken (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/index.js:43:25)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Feb 25, 2020, 15:56:39 +01:00- ERROR
JsonWebTokenError: invalid signatureJsonWebTokenError: invalid signature
    at /opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:133:19
    at getSecret (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:90:14)
    at Object.module.exports [as verify] (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:94:10)
    at verifyIdToken (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/index.js:43:25)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Feb 25, 2020, 15:56:39 +01:00- ERROR
Uncaught internal server error. { JsonWebTokenError: invalid signature
    at /opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:133:19
    at getSecret (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:90:14)
    at Object.module.exports [as verify] (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:94:10)
    at verifyIdToken (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/index.js:43:25)
    at process._tickCallback (internal/process/next_tick.js:68:7) name: 'JsonWebTokenError', message: 'invalid signature' } JsonWebTokenError: invalid signature
    at /opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:133:19
    at getSecret (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:90:14)
    at Object.module.exports [as verify] (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:94:10)
    at verifyIdToken (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/index.js:43:25)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Feb 25, 2020, 15:56:39 +01:00- ERROR
JsonWebTokenError: invalid signatureJsonWebTokenError: invalid signature
    at /opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:133:19
    at getSecret (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:90:14)
    at Object.module.exports [as verify] (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:94:10)
    at verifyIdToken (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/index.js:43:25)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Feb 25, 2020, 15:56:39 +01:00- ERROR
Uncaught internal server error. { JsonWebTokenError: invalid signature
    at /opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:133:19
    at getSecret (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:90:14)
    at Object.module.exports [as verify] (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:94:10)
    at verifyIdToken (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/index.js:43:25)
    at process._tickCallback (internal/process/next_tick.js:68:7) name: 'JsonWebTokenError', message: 'invalid signature' } JsonWebTokenError: invalid signature
    at /opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:133:19
    at getSecret (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:90:14)
    at Object.module.exports [as verify] (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:94:10)
    at verifyIdToken (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/index.js:43:25)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Feb 25, 2020, 15:56:39 +01:00- ERROR
JsonWebTokenError: invalid signatureJsonWebTokenError: invalid signature
    at /opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:133:19
    at getSecret (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:90:14)
    at Object.module.exports [as verify] (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/node_modules/jsonwebtoken/verify.js:94:10)
    at verifyIdToken (/opt/app-root/src/node_modules/sashido-parse-server-apple-auth-adapter/index.js:43:25)
    at process._tickCallback (internal/process/next_tick.js:68:7)

有什么建议吗?

这是我在 parse docs 和一些试验和错误方面取得的进展。

但我不知道如何修复错误并获得有效的解析用户。

原来解析服务器有一个错误,苹果开始托管多个 public 密钥(因此密钥并不总是与签名的 jwt 匹配),这是不支持的身份验证适配器。到目前为止,该修复程序已合并到 master 中,并将与下一个版本一起发布,届时我在问题中使用的代码可以正常工作。

仅供参考:https://github.com/parse-community/parse-server/issues/6496