Home > Enterprise >  Identity Server 4 with ASP.NET Core MVC to authenticate then call Angular SPA
Identity Server 4 with ASP.NET Core MVC to authenticate then call Angular SPA

Time:05-27

I am using an ASP.NET Core MVC application with Identity Server 4 (Duende) and an Angular client.

A user logs in via an ASP.NET Core MVC Login controller, after successful authentication is redirected to another controller that returns a view that has the Angular start up files, namely main.js and the related js files that then launches the Angular app.

Is there a way to set a cookie with the auth token so that the Angular app has access to it? Is a session or cache the way to do this? I need access to the token to pass it to a SignalR hub for data needs.

In most cases it would be the Angular app that directly calls the Identity server API end point using an OIDC client library to authenticate and then can use a getAccessToken method from the OIDC client library to make further authorized API calls.

CodePudding user response:

I think you could read the document and try to set as the document:

https://identityserver4.readthedocs.io/en/latest/quickstarts/3_aspnetcore_and_apis.html#modifying-the-mvc-client

If you want to store the token in cookie ,you could try as below in controller:

var accessToken =  await HttpContext.GetTokenAsync("access_token");
Response.Cookies.Append("access_token", accessToken);
  • Related