Javascript 如何在Google一键登录中使用OAuth 2.0流?
我知道我可以使用我在响应中收到的访问令牌来验证用户。 但是我希望它更安全,所以我希望我们在OAuth2.0中得到的代码。 有没有办法在后台获取代码,以便在一次点击登录时对用户进行身份验证 我们从服务器获得的授权码响应在url中如下所示:Javascript 如何在Google一键登录中使用OAuth 2.0流?,javascript,reactjs,google-api,google-signin,google-api-javascript-client,Javascript,Reactjs,Google Api,Google Signin,Google Api Javascript Client,我知道我可以使用我在响应中收到的访问令牌来验证用户。 但是我希望它更安全,所以我希望我们在OAuth2.0中得到的代码。 有没有办法在后台获取代码,以便在一次点击登录时对用户进行身份验证 我们从服务器获得的授权码响应在url中如下所示: https://oauth2.example.com/auth?code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7 你找到路了吗?我发现了这一点,也尝试了github方法,但没有成功。我想我找到了路。不使用code只使用我们从点击中获得的凭证
https://oauth2.example.com/auth?code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7
你找到路了吗?我发现了这一点,也尝试了github方法,但没有成功。我想我找到了路。不使用
code
只使用我们从点击中获得的凭证,我检查它,当我完成时,如果它对您有帮助,我将发布它
componentDidMount() {
this.registerNewUser();
}
retrievePromise() {
window.googleyolo.retrieve({
supportedAuthMethods: [
'https://accounts.google.com',
],
supportedIdTokenProviders: [
{
uri: 'https://accounts.google.com',
// Replace with your client Id
clientId: 'XXX...XXX.apps.googleusercontent.com',
},
],
});
}
// eslint-disable-next-line class-methods-use-this
registerNewUser() {
window.googleyolo.hint({
supportedAuthMethods: [
'https://accounts.google.com',
],
supportedIdTokenProviders: [{
uri: 'https://accounts.google.com',
// Replace with your client Id
clientId: 'XXX...XXX.apps.googleusercontent.com',
}],
context: 'signUp',
}).then((credential) => {
console.log(credential);
this.props.doGoogleLogin('login');
this.props.decideWhichSocialLogin(this.props.location);
/* hit backend api and API TOKEN here */
/* Also save basic details that we get here */
}, (error) => {
console.log('Error occurred: ', error.type);
});
}