我知道我可以使用在响应中收到的访问令牌来验证用户身份。但我希望它更安全所以我想要我们在 oAuth 2.0 中获得的代码。有没有办法在后台获取代码以一键登录对用户进行身份验证?
我们从服务器获得的授权码响应在 url 中是这样的:
https://oauth2.example.com/auth?code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7
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);
});
}