vendredi 25 mai 2018

Angular Authorization with Token not working

I have an issue with my code, where browser returns Error message for Authorization.

ERROR MESSAGE: Error message text

And here is my HttpInterceptor, which should take care of Authorization with Token for each request

AUTH INTERCEPTOR:

@Injectable()
export class AuthInterceptor implements HttpInterceptor {

  constructor(private store: Store<fromApp.AppState>) {}

  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

   return this.store.select('bucket')
      .switchMap( () => {
          const copiedReq = req.clone({
            setHeaders: {
              Authorization: `Bearer some-valid-token-here`,
            }});
          console.log('Intercepted ' + copiedReq.headers.get('Authorization'));
          return next.handle(copiedReq);
        });
  }

}

Now obviously one would consider Token being invalid, which I validated with the API owner that it is indeed valid, so I have no clue why it is not working. You may notice my console.log in Interceptor and it is indeed logging this event on each request, but it seems to fail to authorize it.

I have to admit that I am a bit new to Angular, so I might have made a mistake somewhere - if you need additional code, please let me know.




Aucun commentaire:

Enregistrer un commentaire