custom ProfileService
This commit is contained in:
parent
4c0027549a
commit
29303d5aea
4 changed files with 16 additions and 11 deletions
|
|
@ -54,5 +54,7 @@ namespace Yavsc
|
||||||
public const string LivePath = "/live/cast";
|
public const string LivePath = "/live/cast";
|
||||||
|
|
||||||
public const string StreamingPath = "/api/stream/put";
|
public const string StreamingPath = "/api/stream/put";
|
||||||
|
|
||||||
|
public const string RoleClaimName = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,11 @@ namespace Yavsc.Services
|
||||||
|
|
||||||
foreach (var scope in context.RequestedResources.ParsedScopes)
|
foreach (var scope in context.RequestedResources.ParsedScopes)
|
||||||
{
|
{
|
||||||
claims.Add(new Claim(JwtClaimTypes.Scope, scope.ParsedName));
|
if (context.Client.AllowedScopes.Contains(scope.ParsedName))
|
||||||
claimAdds.Add(scope.ParsedName);
|
{
|
||||||
// TODO scope has a ParsedParameter
|
claims.Add(new Claim(JwtClaimTypes.Scope, scope.ParsedName));
|
||||||
|
claimAdds.Add(scope.ParsedName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (claimAdds.Contains(JwtClaimTypes.Profile))
|
if (claimAdds.Contains(JwtClaimTypes.Profile))
|
||||||
|
|
@ -54,7 +56,7 @@ namespace Yavsc.Services
|
||||||
var roles = await this._userManager.GetRolesAsync(user);
|
var roles = await this._userManager.GetRolesAsync(user);
|
||||||
if (roles.Count()>0)
|
if (roles.Count()>0)
|
||||||
{
|
{
|
||||||
claims.Add(new Claim("http://schemas.microsoft.com/ws/2008/06/identity/claims/role",String.Join(" ",roles)));
|
claims.AddRange(roles.Select(r => new Claim(Constants.RoleClaimName, r)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return claims;
|
return claims;
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,7 @@ public static class HostingExtensions
|
||||||
|
|
||||||
AddIdentityDBAndStores(builder).AddDefaultTokenProviders();;
|
AddIdentityDBAndStores(builder).AddDefaultTokenProviders();;
|
||||||
|
|
||||||
AddIdentityServer(builder);
|
AddIdentityServer(builder).AddProfileService<ProfileService>();
|
||||||
//services.AddScoped<IProfileService, ProfileService>();
|
//services.AddScoped<IProfileService, ProfileService>();
|
||||||
|
|
||||||
services.AddSession();
|
services.AddSession();
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using IdentityModel;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
|
@ -5,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
using Yavsc;
|
||||||
|
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
|
|
@ -34,12 +36,11 @@ public class Startup
|
||||||
options.GetClaimsFromUserInfoEndpoint = true;
|
options.GetClaimsFromUserInfoEndpoint = true;
|
||||||
options.SaveTokens = true;
|
options.SaveTokens = true;
|
||||||
options.ClaimActions.MapUniqueJsonKey(
|
options.ClaimActions.MapUniqueJsonKey(
|
||||||
"http://schemas.microsoft.com/ws/2008/06/identity/claims/role",
|
Constants.RoleClaimName,
|
||||||
"http://schemas.microsoft.com/ws/2008/06/identity/claims/role");
|
Constants.RoleClaimName);
|
||||||
options.ClaimActions.MapUniqueJsonKey("role",
|
options.ClaimActions.MapUniqueJsonKey(
|
||||||
"http://schemas.microsoft.com/ws/2008/06/identity/claims/role");
|
JwtClaimTypes.Scope,
|
||||||
options.ClaimActions.MapUniqueJsonKey("roles",
|
JwtClaimTypes.Scope);
|
||||||
"http://schemas.microsoft.com/ws/2008/06/identity/claims/role");
|
|
||||||
options.TokenValidationParameters = new TokenValidationParameters
|
options.TokenValidationParameters = new TokenValidationParameters
|
||||||
{
|
{
|
||||||
NameClaimType = "name",
|
NameClaimType = "name",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue