0

this is the login api result- header in postman

this is angular code to retrieve token in console

  return this.http.post(this.loginUrl, bodystr, this._requestOption)
        .subscribe(response => {
          if(response.headers.has("authorization"))
          {
              let token = response.headers.get("authorization");

              console.log(token);
          }
          console.log("cookie: " + response.headers.get("Access-Control-Expose-Headers: authorization"));
          console.log(response.headers.get("Authorization"));
            console.log(response);
            return response;
        }, err => {
            throw err;
        });
  }

and i am unable to access the token from the header.

Quentin
  • 45
  • 1
  • 5

2 Answers2

0

Check here for one of my solutions on how to implement token authorization. Maybe that will help you.

Joe Belladonna
  • 1,349
  • 14
  • 20
0
    [EnableCors(origins: "*", headers: "*", methods: "*", exposedHeaders: "Authorization")]
    public HttpResponseMessage Post([FromBody]User user)
    {
        string AuthenticationTokken = Common.GetToken(user.UserName,user.Password);

        var response = Request.CreateResponse(HttpStatusCode.OK);

        response.Headers.Add("Authorization", "Basic "+ AuthenticationTokken);

        return response;
    }
Quentin
  • 45
  • 1
  • 5