小编206*_*mph的帖子

IdentityServer4 Net Core 2 不调用自定义 iProfileService

我已将我的 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)

profile identityserver4 asp.net-core-2.0

6
推荐指数
3
解决办法
6646
查看次数

IdentityServer4 API密钥支持

我在Visual Studio中有3个项目.

  1. Identity Server
  2. API站点
  3. 角2前端

我正在使用IdentityServer4与ASP.NET核心身份和实体框架.到目前为止,一切都很好.

现在,我想为用户添加生成API密钥的功能,以便用户可以通过他们的服务器调用我们的API服务器,只需传入API密钥即可.然后(以某种方式)将对用户进行身份验证并生成我的API用于授权的访问令牌.IdentityServer4是否支持为每个用户生成API密钥?我知道有客户机密,我已经实施但只能识别客户端.我也需要了解用户,所以我知道用户有权做什么(现在使用角色).

api-key asp.net-core identityserver4

3
推荐指数
1
解决办法
3972
查看次数

Automapper 字符串到 Guid 不起作用

我想创建一个通用类型转换器,根据我转换的方向(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)

关于如何使其工作的任何建议?

c# guid automapper .net-core

1
推荐指数
2
解决办法
4939
查看次数