0

I have a mvc web application. I am able to generate a jwt token and save the token in a http cookie. Later upon each request to the web api I pass the jwt as a bearer token.

In some of the pages I have to load angular 5 app. I have created a httpInterceptor in the angular app but I am unable to get the same cookie value there so that I can attach an authorization header.

Bear
  • 662
  • 1
  • 5
  • 20
  • 1
    Please provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). This question is off topic until you provide a code example. – Bear Aug 27 '18 at 16:15
  • This problem i am facing in my professional project so cannot disclose the code – Subhash Chandra Chakraborty Aug 27 '18 at 16:42
  • I can only say that it is multi-form project and out of those forms few forms are in mvc and few are in angular 5.I need to share the jwt using cookies between mvc pages and angular – Subhash Chandra Chakraborty Aug 27 '18 at 16:43
  • 1
    Try to reproduce the issue here https://stackblitz.com/ that would help all to help you ;) – hamilton.lima Aug 27 '18 at 16:51
  • one work around would be to write the token into a hidden field and have angular pick it from there, if the angular code is embedded within an mvc view. it does expose the token if the user searches the page source, but then again the user can also just look at their cookie. – Paritosh Aug 27 '18 at 17:10
  • I understand but keeping the jwt as hidden field is less secure than cookies. – Subhash Chandra Chakraborty Aug 27 '18 at 17:21

1 Answers1

0

Not sure if i am understanding the question well but on the angular side if you are having problems setting and retrieving cookies then i would 100% check out this package.

https://www.npmjs.com/package/ngx-cookie-service

very easy to retrieve the jwt from a cookie this way in an angular app. BR

devDan
  • 5,969
  • 3
  • 21
  • 40