React Google OAuth 2.0:某些请求的范围无效

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

我正在尝试使用 Google OAuth 2.0 登录我的网络应用程序。我要求以下范围:

当我尝试授权我的应用程序时,收到以下错误消息:

某些请求的范围无效。 {无效=[https://www.googleapis.com/auth/userinfo.email,https://www.go... 我还在 Google Cloud Console 中启用了范围。但是,我仍然收到此错误消息。

const scope = [
  'https://www.googleapis.com/auth/userinfo.email',
  'https://www.googleapis.com/auth/userinfo.profile'
].join(' ');

const params = {
    response_type: 'code',
    client_id: googleClientId,
    redirect_uri: `${apiBaseURL}/${redirectUri}`,
    prompt:'select_account',
    access_type:'offline',
    scope
};

const urlParams = new URLSearchParams(params).toString();
window.location = `${googleAuthUrl}?${urlParams}`;
};
reactjs authentication google-cloud-platform google-oauth jsx
1个回答
0
投票

范围不应该是数组,它应该看起来像

 "scope": "https:\/\/www.googleapis.com\/auth\/userinfo.profile openid https:\/\/www.googleapis.com\/auth\/userinfo.email",

范围定义为字符串除以空格字符

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