小编Son*_*ika的帖子

我们如何创建非对称安全密钥?

我们如何在 C# 中创建 AsymmetrySecurityKey。实际上,我们正在使用 AsymetricSecurityKey 创建签名凭据,这是我们的代码:

// Define const Key this should be private secret key  stored in some safe place
string key = "401b09eab3c013d4ca54922bb802bec8fd5318192b0a75f201d8b3727429090fb337591abd3e44453b954555b7a0812e1081c39b740293f765eae731f5a65ed1";

// Create Security key  using private key above:
// not that latest version of JWT using Microsoft namespace instead of System
var securityKey = new AsymmetricSecurityKey(Encoding.UTF8.GetBytes(key));

// Also note that securityKey length should be >256b
// so you have to make sure that your private key has a proper length
//
var credentials = new …
Run Code Online (Sandbox Code Playgroud)

c#

5
推荐指数
1
解决办法
1万
查看次数

IClientStore 的自定义实现

我们使用 EntityFramework Core 和 Identity Server4 来存储配置数据。我们是否需要自定义实现 IClientStore(即 FindClientByIdAsync)接口来从数据库中获取客户端?

 public class CustomClientStore : IClientStore
{
    const string connectionString = @"Data Source=(LocalDb)\MSSQLLocalDB;database=IdentityServer4.Quickstart.EntityFramework-2.0.0;trusted_connection=yes;";
    public Task<Client> FindClientByIdAsync(string clientId)
    {
        var options = new DbContextOptionsBuilder<ConfigurationDbContext>();

        options.UseSqlServer(connectionString);

        var _context = new ConfigurationDbContext(options.Options, new ConfigurationStoreOptions());

        var result = _context.Clients.Where(x => x.ClientId == clientId).FirstOrDefault();

        return Task.FromResult(result.ToModel());
    }
}
Run Code Online (Sandbox Code Playgroud)

identityserver4

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

标签 统计

c# ×1

identityserver4 ×1