我已将我的 Identity Server 项目升级到 Net Core 2,现在我无法调用 iProfileService 对象来添加自定义用户声明。它在 Net Core 1 中确实有效。
Startup.cs 配置服务函数
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
services.AddTransient<IProfileService, M25ProfileService>();
//Load certificate
var cert = new X509Certificate2(Path.Combine(_environment.ContentRootPath, "m25id-cert.pfx"), "mypassword");
services.AddIdentityServer()
.AddSigningCredential(cert)
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(connectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
})
.AddOperationalStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(connectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
//options.EnableTokenCleanup = true;
//options.TokenCleanupInterval = 30;
})
.AddProfileService<M25ProfileService>()
.AddAspNetIdentity<ApplicationUser>();
Run Code Online (Sandbox Code Playgroud)
M25ProfileService.cs
public class M25ProfileService : IProfileService
{
public M25ProfileService(UserManager<ApplicationUser> userManager)
{
_userManager …Run Code Online (Sandbox Code Playgroud) 我在Visual Studio中有3个项目.
我正在使用IdentityServer4与ASP.NET核心身份和实体框架.到目前为止,一切都很好.
现在,我想为用户添加生成API密钥的功能,以便用户可以通过他们的服务器调用我们的API服务器,只需传入API密钥即可.然后(以某种方式)将对用户进行身份验证并生成我的API用于授权的访问令牌.IdentityServer4是否支持为每个用户生成API密钥?我知道有客户机密,我已经实施但只能识别客户端.我也需要了解用户,所以我知道用户有权做什么(现在使用角色).
我想创建一个通用类型转换器,根据我转换的方向(DTO > VM 或 VM > DTO)将 Guid 转换为字符串,将字符串转换为 Guid。此外,某些属性具有可为空的 Guid,所以我想我也可以处理它。我试过以下不走运:
CreateMap<string, Guid?>().ConvertUsing(value => !string.IsNullOrEmpty(value) ? Guid.Parse(value) : (Guid?)null);
CreateMap<string, Guid>().ConvertUsing(guid => Guid.Parse(guid));
Run Code Online (Sandbox Code Playgroud)
和
CreateMap<Guid?, string>().ConvertUsing(guid => guid?.ToString("N"));
CreateMap<Guid, string>().ConvertUsing(guid => guid.ToString("N"));
Run Code Online (Sandbox Code Playgroud)
关于如何使其工作的任何建议?