Hi i am using angularx-social-login
of version 2.2.1
in Angular8 application. Here as google auth token expires by 1 hour, i have to call method for refresh token. I have been through many websites but not able to get solution. I have installed and declared in app module and now using in login component to get the auth token and email address, id from sign in google button click. But i am not getting how to call refresh method for expiration time near by. Please help.
HTML:
<button type="submit" class="btn btn-primary btn-block" (click)="signInWithGoogle()">Sign in with Google</button>
Ts:
public signInWithGoogle(): void {
let socialUser = this.oauthService.signIn(GoogleLoginProvider.PROVIDER_ID).then((userData) => {
if(userData.idToken){
} else {
alert('danger')
}
});
}
app.module.ts:
import { SocialLoginModule, AuthServiceConfig } from "angularx-social-login";
import { GoogleLoginProvider } from "angularx-social-login";
imports: [
SocialLoginModule
],
providers: [
{
provide: AuthServiceConfig,
useFactory: provideConfig
}],
let config = new AuthServiceConfig([
{
id: GoogleLoginProvider.PROVIDER_ID,
provider: new GoogleLoginProvider("1051927480520-u87cv859uap5e6t4r5f52mk96a8a6nhe.apps.googleusercontent.com")
},
]);
export function provideConfig() {
return config;
}
so from demo, i am able to get details of gmail account i choosed for, but token expires by an hour, i need to get refresh token before it expires. Please help
I'm not sure if this question is relevant anymore however SocialAuthService
from angularx-social-login
package actually exposes method to do this - refreshAuthToken(providerId: string): Promise<void>;
You can simply do eg:
refreshUserToken() {
this.socialAuthService.refreshAuthToken(GoogleLoginProvider.PROVIDER_ID).then(() => {
// Any post-refresh actions if needed
});
}
or:
async refreshUserToken() {
await this.socialAuthService.refreshAuthToken(GoogleLoginProvider.PROVIDER_ID);
}
and if you're already subscribed to authState
changes you will get a new SocialUser
(with new, refreshed authToken
) after refreshing. See this method implementation on Github.
Disclaimer: Looking at the implementation it woks only for Google log in.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.