Oauth 2.0 Linkedin 客户端身份验证失败

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

我正在尝试通过 Linkedin API 连接帐户,但通过以下Linkedin 官方 Oauth 教程,我实际上无法理解我的错误。

当我用访问令牌交换代码时,我在第 3 步中得到

{'error': 'invalid_client', 'error_description': 'Client authentication failed'}

我最终发布数据的确切网址是:

'https://www.linkedin.com/oauth/v2/accessToken?client_id=86XXXXXl5r7ule&redirect_uri=http%3A%2F%2F127.0.0.1%3A8000%2FLinkedin%2Fsignin-linkedin%2F&grant_type=authorization_code&code=AQRT5m_P9wt55p3CZHyHWEem81Csy4V4ubnw8CHumk2yzSm1Q6dj2CoCpcc2buj6yE26_oaayShoQO-59jezPKhXSkaWAeRAyw1u_FMJ-qELW4C5udzwDf5AV36rsDqlev52b79HCxM2GkjzNu2vb4ev7LmVVg&client_secret=55XXXXXlqRF6UvAUJ

PARAMETER = {'client_id': '86XXXXXl5r7ule', 
              'redirect_uri': 'http://127.0.0.1:8000/Linkedin/signin-linkedin/', 
              'grant_type': 'authorization_code', 
              'code':
'AQRT5m_P9wt55p3CZHyHWEem81Csy4V4ubnw8CHumk2yzSm1Q6dj2CoCpcc2buj6yE26_oaayShoQO-59jezPKhXSkaWAeRAyw1u_FMJ-qELW4C5udzwDf5AV36rsDqlev52b79HCxM2GkjzNu2vb4ev7LmVVg',
              'client_secret': '55XXXXXlqRF6UvAUJ'}

我的代码在收到后立即发送,我正在发送所有必需的参数,避免额外的参数,我实际上正在接收代码,因此我能够获得资源所有者授权。

P.S.:

Client_id
client_secret
已被检查。 如果有人知道为什么我无法作为客户端连接,谢谢。

authentication oauth-2.0 client linkedin-api
1个回答
0
投票

已经是 2024 年了,我也遇到了同样的问题。对于那些可能遇到此错误的人,这里有一个简单的修复方法。 我的代码有错误:

    const { code: linkedInLoginCode, uri: redirectUri } = req.body
try {
    if (!linkedInLoginCode) {
        return res.status(HttpStatusCode.BadRequest).json({
            status: 'error',
            message: 'Please check your details and try again',
            data: null
        })
    }


    const response = await axios.post(
        'https://www.linkedin.com/oauth/v2/accessToken',
        {
            grant_type: 'authorization_code',
            code: linkedInLoginCode,
            redirect_uri: redirectUri,
            client_id: Config.LINKEDIN_CLIENT_ID,
            client_secret: Config.LINKEDIN_CLIENT_SECRET
        },
        {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            }
        }
    )
    return res.status(HttpStatusCode.Ok).json({
        status: 'success',
        message: 'Login successful!',
        data: response.data
    })  ... more code

当我手动构建 url 时,错误已修复:

        const authUrl = `https://www.linkedin.com/oauth/v2/accessToken?grant_type=authorization_code&code=${linkedInLoginCode}&redirect_uri=${redirectUri}&client_id=${Config.LINKEDIN_CLIENT_ID}&client_secret=${Config.LINKEDIN_CLIENT_SECRET}`


    const response = await axios.post(
        authUrl,
        {},
        {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            }
        }
    )

希望能帮助任何面临这个问题的人。

© www.soinside.com 2019 - 2024. All rights reserved.