I build an Angular 4 site that send authentication details (username/password) to IdentityServer4 and successfully receive a token back (grant type = resource owner password).
Now I want to redirect user to another (different) ASP Core MVC site from my Angular 4 site. Somehow I can not find a way to set up 'headers' in redirection to pass token as a Authorization: Bearer xxx.
I set up cookie in Angular site and then just window.location.href = 'www.example.com/another_site
On MVC site I configure in Startup.cs:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
...
...
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationScheme = "Cookies_Authentication",
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = "http://my_identityserver4_address:49950",
RequireHttpsMetadata = false,
AuthenticationScheme = "Cookies_Authentication",
ApiName = "Protected_Api.get",
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
}
but I'm still receiving 401 Unauthorized response from MVC site. What I'm doing wrong ?
May be IdentityServer looking for special cookie name ? I'm setting it in Angular as:
cookieService.setItem('access_token', 'eyJhbGciOiJSUzI1NiIsImtpZCI6ImFlOWEyMzNhZDczOTUwNWI4YjJkZGE0NTNiMDE........)