在过去的几个月中,我在使用OAuth登录后一直使用此网址来检索用户的名称和信息。
https://www.googleapis.com/oauth2/v1/userinfo?alt=json
这给了我以下格式的JSON:
{
"id": "12345",
"email": "name@gmail.com",
"verified_email": true,
"name": "First Last",
"given_name": "First",
"family_name": "Last",
"link": "https://plus.google.com/12345",
"picture": "https://lh3.googleusercontent.com/123photo.jpg",
"locale": "en"
}
今天早晨,当我的应用程序到达此端点时,它以以下格式获取了JSON:
{
"id": "12345",
"email": "name@gmail.com",
"verified_email": true,
"picture": "https://lh3.googleusercontent.com/123/photo.jpg"
}
我尚未在开发人员控制台中对配置进行任何更改。有谁知道造成这个问题的原因是什么?
答案 0 :(得分:0)
我认为您应该使用不同的URL-来自OpenID Connect的URL,它是用于身份验证的OAuth2扩展,并且its RFC中指定了class GoogleLogin extends Component{
constructor(props) {
super(props)
}
componentDidMount(){
(function() {
var e = document.createElement("script");
e.type = "text/javascript";
e.async = true;
e.src = "https://apis.google.com/js/client:platform.js?onload=gPOnLoad";
var t = document.getElementsByTagName("script")[0];
t.parentNode.insertBefore(e, t)
})();
}
//Triggering login for google
googleLogin = () => {
let response = null;
window.gapi.auth.signIn({
callback: function(authResponse) {
this.googleSignInCallback( authResponse )
}.bind( this ),
clientid: config.google, //Google client Id
cookiepolicy: "single_host_origin",
requestvisibleactions: "http://schema.org/AddAction",
scope: "https://www.googleapis.com/auth/plus.login email"
});
}
googleSignInCallback = (e) => {
console.log( e )
if (e["status"]["signed_in"]) {
window.gapi.client.load("plus", "v1", function() {
if (e["access_token"]) {
this.getUserGoogleProfile( e["access_token"] )
} else if (e["error"]) {
console.log('Import error', 'Error occured while importing data')
}
}.bind(this));
} else {
console.log('Oops... Error occured while importing data')
}
}
getUserGoogleProfile = accesstoken => {
var e = window.gapi.client.plus.people.get({
userId: "me"
});
e.execute(function(e) {
if (e.error) {
console.log(e.message);
console.log('Import error - Error occured while importing data')
return
} else if (e.id) {
//Profile data
alert("Successfull login from google : "+ e.displayName )
console.log( e );
return;
}
}.bind(this));
}
render(){
return(
<img src={google} title="google login" alt="google" onClick={ () => this.googleLogin() }/>
)
}
}
export default GoogleLogin;
端点。
userinfo
正确的过程是从OpenID Discovery文档(Google doc)中获取此URL
https://openidconnect.googleapis.com/v1/userinfo
及其https://accounts.google.com/.well-known/openid-configuration
属性。
您一直在使用的端点的行为更改可能与Google+被关闭有关。但这只是我的猜测。