Snapchat 登录工具包错误:缺少 PKCE 参数

Ric*_*rdZ 5 oauth-2.0 snapchat pkce

我正在尝试使用他们的登录工具包从我的应用程序登录到 Snapchat。

此代码(我更改了 clientId):

onSnapChat() {
    const state = `c25hcGNoYXR0ZXN0`;
    const redirectUri = `https://us-central1-library.cloudfunctions.net/redirectSnapchat`;
    const clientId = `45fad898-162e-48e0-8e4e-135adbc42716`;
    const scopeList = ['https://auth.snapchat.com/oauth2/api/user.display_name'];
    const scope = scopeList.join(' ');
    const loginQS = {
        client_id: clientId,
        redirect_uri: redirectUri,
        response_type: 'code',
        scope: scope,
        state: state
    };

    const stringifyLoginQS = qs.stringify(loginQS);
    const SNAP_ACCOUNTS_LOGIN_URL = 'https://accounts.snapchat.com/accounts/oauth2/auth';
    window.open(SNAP_ACCOUNTS_LOGIN_URL + '?' + stringifyLoginQS, '_blank');
}
Run Code Online (Sandbox Code Playgroud)

生成这个网址:https : //accounts.snapchat.com/accounts/oauth2/auth? client_id = 45fad898-162e-48e0-8e4e-135adbc42716 & redirect_uri =https% 3A%2F%2Fus-central1-library- titles%。 2FredirectSnapchat&response_type=code&scope=https%3A%2F%2Fauth.snapchat.com%2Foauth2%2Fapi%2Fuser.display_name&state=c25hcGNoYXR0ZXN0

返回此错误:{"error":"invalid_request","error_description":"缺少 PKCE 参数。"}

注意: 1. redirect_uri 与 Snapchat 列入白名单的重定向 uri 匹配 2. 我使用的是 OAUTH2 CLIENT ID 3 的开发环境 3. 重定向 uri 指向 Firebase 云函数。它永远不会被击中。

有什么建议?

谢谢你,r

小智 4

基于 Jon Hanley 的评论,对您的代码进行以下修改应该可以工作,这与 LoginQS 的相同添加(code_challenge 和 code_challenge_method)为我解决了相同的 PCKE 问题。

尝试这个修改后的代码;事实上,我确实传递了 code_challenge 的状态变量和状态键,没有任何问题:

onSnapChat() {
    const state = `c25hcGNoYXR0ZXN0`;
    const redirectUri = `https://us-central1-library.cloudfunctions.net/redirectSnapchat`;
    const clientId = `45fad898-162e-48e0-8e4e-135adbc42716`;
    const scopeList = ['https://auth.snapchat.com/oauth2/api/user.display_name'];
    const scope = scopeList.join(' ');
    const loginQS = {
        client_id: clientId,
        redirect_uri: redirectUri,
        code_challenge: state,
        code_challenge_method: "S256",
        response_type: 'code',
        scope: scope,
        state: state
    };

    const stringifyLoginQS = qs.stringify(loginQS);
    const SNAP_ACCOUNTS_LOGIN_URL = 'https://accounts.snapchat.com/accounts/oauth2/auth';
    window.open(SNAP_ACCOUNTS_LOGIN_URL + '?' + stringifyLoginQS, '_blank');
}
Run Code Online (Sandbox Code Playgroud)