Support ASP.NET Core 2.0
Can't upgrade to 2.0. Please help me: https://github.com/IdentityServer/IdentityServer4/issues/1625.
Thanks @thangchung. I had initially thought the asp.net identity roles magically appeared in token claims. Now after seeing your example and the one here and here - it now makes sense.
Would be great to see the IdentityServer 4 documentation describe with examples adding various claims (including roles) via IProfileService - maybe here (and maybe a quickstart addition here).
Here is how I implemented the IProfileService to move the roles to claims (modifying @damienbod code from the link above):
` public async Task GetProfileDataAsync(ProfileDataRequestContext context) {
var sub = context.Subject.GetSubjectId();
var user = await _userManager.FindByIdAsync(sub);
var role = await _userManager.GetRolesAsync(user);
var principal = await _claimsFactory.CreateAsync(user);
var claims = principal.Claims.ToList();
claims = claims.Where(claim => context.RequestedClaimTypes.Contains(claim.Type)).ToList();
claims.Add(new Claim(JwtClaimTypes.GivenName, user.UserName));
if (role.Contains("admin"))
{
claims.Add(new Claim(JwtClaimTypes.Role, "admin"));
}
else if (role.Contains("editor")) {
claims.Add(new Claim(JwtClaimTypes.Role, "editor"));
}
else
{
claims.Add(new Claim(JwtClaimTypes.Role, "user"));
}
claims.Add(new Claim(IdentityServerConstants.StandardScopes.Email, user.Email));
context.IssuedClaims = claims;
}
`
Hi I am new to this forum. I am also having similar issue. I have my auth server developed using Identityserver3 framework. i am using local signing cert and ssl enabled. The auth server is working fine and i get the response to https://localhost:44300/identity/.well-known/openid-configuration.
Recently, i started developing asp.net core 2.0 webapi and i had to use the existing auth server as mentioend above.
I tried the following in core api startup.cs.
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication("Bearer")
.AddIdentityServerAuthentication(options =>
{
options.Authority= "https://localhost:44300";
options.ApiName = "web_api";
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
// Enable CORS
app.UseCors(builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
app.UseAuthentication();
app.UseMvc();
}
I used postman to get a token and use the token to access my api and getting error saying:
<h1>An unhandled exception occurred while processing the request.</h1>
<div class="titleerror">JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.</div>
<p class="location">Newtonsoft.Json.JsonTextReader.ParseValue()</p>
<div class="titleerror">InvalidOperationException: IDX10803: Unable to obtain configuration from: 'https://localhost:44300/.well-known/openid-configuration'.</div>
<p class="location">Microsoft.IdentityModel.Protocols.ConfigurationManager+<GetConfigurationAsync>d__24.MoveNext()</p>
As mentioned above, i am completely new to Identityserver.
Appreciate if anyone could help with this?
Thanks
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.