Abp配置文件设置IdentityServer客户端

Abp配置文件设置IdentityServer客户端在没有购买商业版,又没实现IdentityServer配置管理页功能时,我们又得配置客户端时。设想通过appsettings.json,临时添加配置,然后执行.DbMigrator迁移数据。这时原

大家好,又见面了,我是你们的朋友全栈君。

在没有购买商业版,又没实现IdentityServer配置管理页功能时,我们又得配置客户端时。
设想通过appsettings.json,临时添加配置,然后执行.DbMigrator迁移数据。
这时原版代码需要以下改动:

修改.Domain项目中IdentityServerDataSeedContributor类的CreateClientsAsync方法。

private async Task CreateClientsAsync()
{
    var commonScopes = new[]
    {
        "email",
        "openid",
        "profile",
        "role",
        "phone",
        "address"
    };

    var configurationSection = _configuration.GetSection("IdentityServer:Clients");

    foreach (var section in configurationSection.GetChildren())
    {
        var clientId = section["ClientId"];
        var secret = (section["ClientSecret"] ?? "123456").Sha256();
        var rootUrl = section["RootUrl"].EnsureEndsWith('/');
        var grantTypes = (section["GrantTypes"] ?? "client_credentials").Split();
        var redirectUri = section["RedirectUri"] ?? $"{rootUrl}signin-oidc";
        var postLogoutRedirectUri = section["PostLogoutRedirectUri"] ?? $"{rootUrl}signout-callback-oidc";
        var frontChannelLogoutUri = section["FrontChannelLogoutUri"] ?? rootUrl;
        var requireClientSecret = (section["RequireClientSecret"] ?? "False").To<bool>();
        var requirePkce = (section["RequirePkce"] ?? "False").To<bool>();
        var corsOrigins = new[] { rootUrl.RemovePostFix("/") };

        await CreateClientAsync(
            name: clientId,
            scopes: commonScopes,
            grantTypes: grantTypes,
            secret: secret,
            redirectUri: redirectUri,
            postLogoutRedirectUri: postLogoutRedirectUri,
            frontChannelLogoutUri: frontChannelLogoutUri,
            requireClientSecret,
            requirePkce,
            corsOrigins: corsOrigins
        );
    }
}

修改.DbMigrator项目中appsettings.json为:

{
    "ConnectionStrings": {
        "Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=IdentityServer;Trusted_Connection=True;"
    },
    "IdentityServer": {
        "Clients": {
            "TestClient.Mvc": {
                "ClientId": "TestClient.Mvc",
                "ClientSecret": "TestClient.Mvc",
                "RootUrl": "https://localhost:53279",
                "GrantTypes": "authorization_code",
                "RequirePkce": true
            },
            "MyProject_Web": {
                "ClientId": "MyProject_Web",
                "ClientSecret": "1q2w3e*",
                "RootUrl": "https://localhost:44393",
                "GrantTypes": "hybrid",
                "FrontChannelLogoutUri": "https://localhost:44393/Account/FrontChannelLogou"
            },
            "MyProject_App": {
                "ClientId": "MyProject_App",
                "ClientSecret": "1q2w3e*",
                "RootUrl": "http://localhost:4200",
                "GrantTypes": "password client_credentials authorization_code"
            },
            "MyProject_Blazor": {
                "ClientId": "MyProject_Blazor",
                "RootUrl": "https://localhost:44307",
                "GrantTypes": "authorization_code",
                "RedirectUri": "https://localhost:44307/authentication/login-callback",
                "PostLogoutRedirectUri": "https://localhost:44307/authentication/logout-callback"
            },
            "MyProject_Swagger": {
                "ClientId": "MyProject_Swagger",
                "ClientSecret": "1q2w3e*",
                "RootUrl": "https://localhost:44399",
                "GrantTypes": "authorization_code",
                "redirectUri": "https://localhost:44399/swagger/oauth2-redirect.html"
            }
        }
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/155575.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • offsetof 例子「建议收藏」

    offsetof 例子「建议收藏」
    /*offsetofexample*/
    #include”stdafx.h”
    #include
    #include
    /************************************************************************/
    /*MacroOBJECT_HEAD_ADDRESS:calculatethestruct’saddress

    2022年8月22日
    7
  • 游标和动态SQL

    游标和动态SQL游标类别:静态游标(指在编译的时候,游标就与一个select语句进行了静态绑定的游标,这种游标只能作用于一个查询语句)和动态游标(就是希望我们的查询语句在运行的时候才跟游标绑定,为了使用动态游标,必须声明游标变量)。动态游标分两种,分别是强类型和弱类型。强类型的动态游标只能支持查询结果与他类型匹配的这种查询语句,弱类型的动态游标可以支持任何的查询语句。静态游标分为两种,隐式游标和显

    2022年6月23日
    29
  • linux rhel7下安装python

    1.查看是否已经安装PythonCentos7默认安装了python2.7.5因为一些命令要用它比如yum它使用的是python2.7.5。使用python-V命令查看一下是否安装Pytho

    2021年12月29日
    59
  • Django(30)Django常用的模板标签

    Django(30)Django常用的模板标签常用的模板标签if标签if标签相当于Python中的if语句,有elif和else相对应,但是所有的标签都需要用标签符号({%%})进行包裹。if标签中可以使用==、!=、<、<=、&

    2022年8月7日
    7
  • JavaScript字符串截取

    JavaScript字符串截取一、常用方法说明1.substr2.substring3.slice二、举例说明1.substr2.substring3.slice

    2022年6月13日
    28
  • Apache Thrift的简单使用

    Apache Thrift的简单使用

    2021年11月14日
    47

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号