Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular AWS cognito刷新标记问题在具有角度的星云中_Angular_Amazon Web Services_Nebular - Fatal编程技术网

Angular AWS cognito刷新标记问题在具有角度的星云中

Angular AWS cognito刷新标记问题在具有角度的星云中,angular,amazon-web-services,nebular,Angular,Amazon Web Services,Nebular,我的JWT令牌刷新有问题,如果令牌在未登录的情况下过期,我需要刷新令牌, 我在NbAuthService中看到一个名为refreshToken的方法。 我不明白如何使用它,我在拦截器中添加了代码。这是我的密码 在这段代码中,它不是订阅refreshToken @Injectable() export class AuthJWTInterceptor implements HttpInterceptor { constructor(private injector: Injector, pri

我的JWT令牌刷新有问题,如果令牌在未登录的情况下过期,我需要刷新令牌, 我在NbAuthService中看到一个名为refreshToken的方法。 我不明白如何使用它,我在拦截器中添加了代码。这是我的密码 在这段代码中,它不是订阅refreshToken

@Injectable()
export class AuthJWTInterceptor implements HttpInterceptor {
  constructor(private injector: Injector, private router: Router) {}

  intercept(
    req: HttpRequest<any>,
    next: HttpHandler,
  ): Observable<HttpEvent<any>> {
    return this.authService.getToken().switchMap((token: NbAuthJWTToken) => {
      if (!token.isValid()) {
         this.authService.refreshToken('email').subscribe((newToken: any) => {
          console.log((newToken));
        });
        this.router.navigate(['auth']);
      }
      if (token) {
        const JWT = `${token.getValue()}`;
        req = req.clone({
          setHeaders: {
            Authorization: JWT,
          },
        });
      }
      return next.handle(req);
    });
  }

  protected get authService(): NbAuthService {
    return this.injector.get(NbAuthService);
  }
}

那么,我在这里犯了什么错误,请帮助我解决这个问题。

您找到解决方案了吗?您找到解决方案了吗?
NbOAuth2AuthStrategy.setup({
            name: 'email',
            clientId: environment.cognitoClientId,
            clientSecret: '',
            clientAuthMethod: NbOAuth2ClientAuthMethod.NONE,
            redirect: {
              success: '',
              failure: '',
            },
            defaultErrors: ['Something went wrong, please try again.'],
            defaultMessages: ['You have been successfully authenticated.'],
            authorize: {
              endpoint: environment.cognitoUrl + '/oauth2/authorize',
              redirectUri: environment.siteUrl + '/auth/callback',
              responseType: NbOAuth2ResponseType.TOKEN,
            },
            token: {
              endpoint: environment.cognitoUrl + '/oauth2/token',
              grantType: NbOAuth2GrantType.AUTHORIZATION_CODE,
              requireValidToken: false,
              class: NbAuthCognitoToken,
            },
            refresh: {
              endpoint: environment.cognitoUrl + '/oauth2/token',
              grantType: NbOAuth2GrantType.REFRESH_TOKEN,
             },
          }),
        ],
      }).providers,