0
votes

I have a .net core API and JWT token authentication code is added in the application. My problem is how can I generate the bearer token from any application so that I can authenticate the request. I am not able to generate the bearer token.

I have tried lots of options like from Postman GetNewAccessToken. Its asks for Single sign-on but after sign-in open the Microsoft office website in a new window. How can I get bearer token from Postman?

Is there is any way for getting the bearer token from C# application using users's credentials or using single sign on?

enter image description here

enter image description here

I need a bearer token just to authenticate my request.

2

2 Answers

1
votes

Open up your F12 developer tools in your browser, look up an authenticated request and have a look at the Authentication header. It has a current version of a Bearer token.

For instance:

  • Go to the Graph Explorer preview
  • Sign in to Graph Explorer (top left)
  • Open up F12 developer tools
  • Run the Me query
  • See the request to /me in the Network tab
  • Inspect the request headers and find the Authorization header

Authorization header from Graph Explorer - Preview

1
votes

If you want to retrieve the token programmatically, you should check out Microsoft Authentication Library (MSAL): https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-overview and more specifically MSAL.NET