I have Asp.Net MVC Core application and inside it is the React JavaScript application.
I would like to share the access token between MVC part and React JavaScript part.
I've used for generating access token the IdentityServer4
with Implicit Flow.
I've used the UseOpenIdConnectAuthentication
middleware which store the token inside cookie probable but this cookie is not readable from JavaScript.
How can I pass the access token from MVC to the JavaScript? I want to use in JavaScript this token for calling and API from React.
Finally I want to store the token in cookie for MVC (it's okay) and for React part in the localStorage - but I don't know how send the token from MVC to the React.
From React, you could call your MVC server and return the token to React:
public class SomeController : Controller
{
[Authorize]
public async Task<String> GetAccessToken()
{
var accessToken = await HttpContext.Authentication.GetTokenAsync("access_token");
return accessToken;
}
}