Google 授权用户加密属性
Google Auth User Cryptic Properties
我在 Web 项目上使用 google 身份验证,我试图理解 属性 名称。屏幕截图显示了 google 返回的 user
对象。我可以这样访问 id_token
:
this.user.Zb.id_token
为什么Zb
?一年前是这样的:
this.user.wc.id_token
请注意,当时是 wc
,现在我的 UI 代码中断了。我错过了什么?为什么使用这些 属性 名称?我该怎么做才能访问 id_token
而不管它的父 属性 名称?
这是 UI 代码:
async authenticate(): Promise<gapi.auth2.GoogleUser> {
// Initialize gapi if not done yet
if (!this.gapiSetup) {
await this.initGoogleAuth();
}
// Resolve or reject signin Promise
return new Promise(async () => {
await this.authInstance.signIn().then(
user => {
this.user = user;
console.log('this.user: ', this.user);
this.cookieService.set('jwt', this.user.Zb.id_token, 365); // expires in one year (365 days)
// this.cookieService.set('jwt', this.user.wc.id_token, 365); // expires in one year (365 days)
this.owlerApiService.getHooterUsingIdTokenFromProvider()
.subscribe((data: any) => {
this.userDto = data;
},
error => {
console.log('error: ', error);
});
},
error => this.error = error);
});
}
async initGoogleAuth(): Promise<void> {
// Create a new Promise where the resolve function is the callback passed to gapi.load
const pload = new Promise((resolve) => {
gapi.load('auth2', resolve);
});
// When the first promise resolves, it means we have gapi loaded and that we can call gapi.init
return pload.then(async () => {
// ClientId safe to put here? Looks like it:
//
await gapi.auth2
.init({ client_id: 'xxx.apps.googleusercontent.com' })
.then(auth => {
this.gapiSetup = true;
this.authInstance = auth;
});
});
}
我认为您没有按预期形式使用 SDK;我不清楚你是如何确定这是为经过身份验证的用户访问 id_token
值的正确方法,因为官方文档中没有任何地方提到它。
signIn()
returns an instance of GoogleUser
, on which you can call getAuthResponse()
. The returned gapi.auth2.AuthResponse
object 包括 id_token
:
await this.authInstance.signIn().then(
user => {
this.user = user;
console.log('this.user: ', this.user);
this.cookieService.set('jwt', this.user.getAuthResponse().id_token, 365); // expires in one year (365 days)
// …
我在 Web 项目上使用 google 身份验证,我试图理解 属性 名称。屏幕截图显示了 google 返回的 user
对象。我可以这样访问 id_token
:
this.user.Zb.id_token
为什么Zb
?一年前是这样的:
this.user.wc.id_token
请注意,当时是 wc
,现在我的 UI 代码中断了。我错过了什么?为什么使用这些 属性 名称?我该怎么做才能访问 id_token
而不管它的父 属性 名称?
这是 UI 代码:
async authenticate(): Promise<gapi.auth2.GoogleUser> {
// Initialize gapi if not done yet
if (!this.gapiSetup) {
await this.initGoogleAuth();
}
// Resolve or reject signin Promise
return new Promise(async () => {
await this.authInstance.signIn().then(
user => {
this.user = user;
console.log('this.user: ', this.user);
this.cookieService.set('jwt', this.user.Zb.id_token, 365); // expires in one year (365 days)
// this.cookieService.set('jwt', this.user.wc.id_token, 365); // expires in one year (365 days)
this.owlerApiService.getHooterUsingIdTokenFromProvider()
.subscribe((data: any) => {
this.userDto = data;
},
error => {
console.log('error: ', error);
});
},
error => this.error = error);
});
}
async initGoogleAuth(): Promise<void> {
// Create a new Promise where the resolve function is the callback passed to gapi.load
const pload = new Promise((resolve) => {
gapi.load('auth2', resolve);
});
// When the first promise resolves, it means we have gapi loaded and that we can call gapi.init
return pload.then(async () => {
// ClientId safe to put here? Looks like it:
//
await gapi.auth2
.init({ client_id: 'xxx.apps.googleusercontent.com' })
.then(auth => {
this.gapiSetup = true;
this.authInstance = auth;
});
});
}
我认为您没有按预期形式使用 SDK;我不清楚你是如何确定这是为经过身份验证的用户访问 id_token
值的正确方法,因为官方文档中没有任何地方提到它。
signIn()
returns an instance of GoogleUser
, on which you can call getAuthResponse()
. The returned gapi.auth2.AuthResponse
object 包括 id_token
:
await this.authInstance.signIn().then(
user => {
this.user = user;
console.log('this.user: ', this.user);
this.cookieService.set('jwt', this.user.getAuthResponse().id_token, 365); // expires in one year (365 days)
// …