Javascript Google身份验证请求URL中断(客户端身份验证)
我有一小段javascript代码,它一直在角度应用程序中工作:Javascript Google身份验证请求URL中断(客户端身份验证),javascript,client-side,google-authentication,Javascript,Client Side,Google Authentication,我有一小段javascript代码,它一直在角度应用程序中工作: async googleSignIn(redirectUrl, userId) { let clientID=encodeURIComponent('redacted'); let redirectURI=encodeURIComponent(redirectUrl); let scope=encodeURIComponent('https://www.googleapis.com/auth/calen
async googleSignIn(redirectUrl, userId) {
let clientID=encodeURIComponent('redacted');
let redirectURI=encodeURIComponent(redirectUrl);
let scope=encodeURIComponent('https://www.googleapis.com/auth/calendar')+"+"+encodeURIComponent('https://www.googleapis.com/auth/calendar.events')
let url =
`https://accounts.google.com/o/oauth2/v2/auth?response_type=code&
client_id=${clientID}&
redirect_uri=${redirectURI}&
access_type=offline&
prompt=consent&
scope=${scope}&
state=${userId}`;
window.open(url,"_self");
}
没有任何更改,但现在它不再工作,取而代之的是,我得到一个400错误,其中缺少一个参数。每次加载链接时,哪一个缺少更改(clientId、scope、redirectURI——它总是说缺少其中一个,即使它们存在)
通过使用调试器并检查变量,我验证了一切都在那里。我甚至复制了变量的内容,将其粘贴到一个新的选项卡中,并且成功了。我真的被难住了,有人能帮我看看我做错了什么吗
将在编写字符串时呈现字符串,包括换行符
,空格
,。。。这些新词就是问题所在。
删除额外字符将解决此问题:
let url = `https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=${clientID}&redirect_uri=${redirectURI}&access_type=offline&prompt=consent&scope=${scope}&state=${userId}`;
将在编写字符串时呈现字符串,包括换行符
,空格
,。。。这些新词就是问题所在。
删除额外字符将解决此问题:
let url = `https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=${clientID}&redirect_uri=${redirectURI}&access_type=offline&prompt=consent&scope=${scope}&state=${userId}`;