ngx-admin icon indicating copy to clipboard operation
ngx-admin copied to clipboard

Refresh Token with Google Oauth2 Strategy

Open KarlGNassar opened this issue 2 years ago • 6 comments

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,
        },
      }),
    ],
})

KarlGNassar avatar Jun 13 '22 18:06 KarlGNassar

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.

nitinmukesh avatar Aug 09 '22 05:08 nitinmukesh

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 avatar Aug 09 '22 20:08 KarlGNassar

@KarlGNassar If you can upload your code somewhere I can try to see how I can help

nitinmukesh avatar Aug 15 '22 11:08 nitinmukesh

@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

KarlGNassar avatar Aug 15 '22 12:08 KarlGNassar

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.

nitinmukesh avatar Aug 15 '22 13:08 nitinmukesh

It seems like refresh token IS implemented in Nebular.

https://github.com/akveo/nebular/blob/master/src/framework/auth/strategies/oauth2/oauth2-strategy.ts

Prefix1802 avatar Jul 02 '23 09:07 Prefix1802