akveo / ngx-admin

Customizable admin dashboard template based on Angular 10+
https://akveo.github.io/ngx-admin/
MIT License
25.27k stars 7.96k forks source link

Refresh Token with Google Oauth2 Strategy #5944

Open KarlGNassar opened 2 years ago

KarlGNassar commented 2 years ago

Issue type

I'm submitting a ... (check one with "x")

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,
        },
      }),
    ],
})
nitinmukesh commented 2 years ago

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.

KarlGNassar commented 2 years ago

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!?

nitinmukesh commented 2 years ago

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

KarlGNassar commented 2 years ago

@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

nitinmukesh commented 2 years ago

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.

Prefix1802 commented 1 year ago

It seems like refresh token IS implemented in Nebular.

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