ngx-admin
ngx-admin copied to clipboard
Refresh Token with Google Oauth2 Strategy
Issue type
I'm submitting a ... (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] question about the decisions made in the repository
Issue description
Current behavior:
Returning accessToken
and storing it in localStorage
Expected behavior:
Return both accessToken
and refreshToken
so that token.getRefreshToken()
doesn't return null
I did not see a single piece of code in the repo that includes refresh token with google-oauth2 login. Is that not a feature yet?
Related code:
NbOAuth2AuthStrategy.setup({
name: "google",
clientId: environment.googleClientId,
clientSecret: environment.googleClientSecret,
authorize: {
endpoint: "https://accounts.google.com/o/oauth2/v2/auth",
responseType: NbOAuth2ResponseType.TOKEN,
scope: "profile email",
redirectUri: environment.googleRedirectUri,
},
redirect: {
success: "/",
},
token: {
endpoint: "token",
grantType: NbOAuth2GrantType.AUTHORIZATION_CODE,
class: NbAuthOAuth2Token,
requireValidToken: true,
},
refresh: {
endpoint: "token",
grantType: NbOAuth2GrantType.REFRESH_TOKEN,
},
}),
],
})
Please check here https://akveo.github.io/nebular/docs/auth/nbauthservice#nbauthservice
refreshToken() | parameters: strategyName: string, data: anyreturns:Observable<NbAuthResult>Sends a refresh token request Stores received token in the token storageExample: refreshToken('email', {token: token})
I am struggling with implementing basic authentication so can't help.
Please check here https://akveo.github.io/nebular/docs/auth/nbauthservice#nbauthservice
refreshToken() | parameters: strategyName: string, data: anyreturns:Observable<NbAuthResult>Sends a refresh token request Stores received token in the token storageExample: refreshToken('email', {token: token})
I am struggling with implementing basic authentication so can't help.
this.authService.authenticate("google")
.pipe(takeUntil(this.destroy$))
.subscribe((authResult: NbAuthResult) => {
this.authService.refreshToken('google', {token: authResult.getToken() as NbAuthOAuth2Token}).subscribe(
...
This returns TypeError: token.getRefreshToken is not a function
Am I doing something wrong!?
@KarlGNassar If you can upload your code somewhere I can try to see how I can help
@KarlGNassar If you can upload your code somewhere I can try to see how I can help
The code in the issue above is all the code needed to make the auth work, but the refresh token is the only thing that is not working. Do you have any sample code that uses Google OAuth2 and refresh tokens? Would really appreciate it
I don't have it that's why I want to debug.. You don't need to upload whole code just working code so I can debug. Don't have time to implement everything from scratch.
It seems like refresh token IS implemented in Nebular.
https://github.com/akveo/nebular/blob/master/src/framework/auth/strategies/oauth2/oauth2-strategy.ts