1
votes

I'm looking for enlightenment in regards to request headers and response headers.

Below taken from some google article

Request headers contain more information about the resource to be fetched, or about the client requesting the resource. Response headers hold additional information about the response, like its location or about the server providing it.

I'm trying to get a Bearer Token from a logged in User. The token in the newBearer is one I need. It has all the information, but my problem is the Request header has a Authorization Bearer and the response header has a Authorization: New Bearer. Which one is the correct one to take?

Can you take newBeaer token? cause when I do I get a lot of complaints with the below code.

When I just take the Authorization it works fine.

import { Injectable } from '@angular/core';
@Injectable()
export class TokenInterceptorService implements HttpInterceptor {
   intercept(req: HttpRequest<any>, next: HttpHandler):   Observable<HttpEvent<any>> {

      let token = req.headers.get('Authorization');
      let parsedToken = token.slice(7) /// which gives me my long token
      localStorgae.setItem('token', parsedToken ) /// set in storage to decode later on 
      return next.handle(req);
   }
}

Should I be taking the token from the response or request headers?
1
you have localStorgae instead localStoragesonEtLumiere
"I get complaints" is virtually meaningless for debugging purposes ... don't you mean errors and what specifically are those errors?charlietfl

1 Answers

0
votes

JWT works this way

You send a login request to server. Server sends a JSON response with the jwt token. Client get the jwt token and set the headers for the next request that require authorization.

Then you set a header with authorization bearer, send it to server, then server check for authorization, and response with a new jwt token for the next request.

That is simple, but there is a lack of information about the client side.