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)
上一篇 2022年7月3日 下午6:00
下一篇 2022年7月3日 下午6:00


相关推荐

  • RandomAccessFile 详解

    RandomAccessFile 详解RandomAccess 是用来访问那些保存数据记录的文件的 你就可以用 seek 方法来访问记录 并进行读写了 这些记录的大小不必相同 但是其大小和位置必须是可知的 但是该类仅限于操作文件 RandomAccess 不属于 InputStream 和 OutputStream 类系的 实际上 除了实现 DataInput 和 DataOutput 接口之外 Da

    2026年3月18日
    2
  • OPNET14.5+WIN10+VS2010安装教程(附安装包)

    OPNET14.5+WIN10+VS2010安装教程(附安装包)引言在做毕设调研的时候 在给项目调研的时候 在写网络仿真论文的时候 发现使用 OPNET 软件来做网络仿真的可行性比较高 大部分论文中也都有提及这款软件 之后的毕设也将使用这款软件 网上也有比较多的教程 在这里我提供的是 OPNET14 5 WIN10 VS2010 的安装教程 这种情况提供的教程比较少 但是还是有参考这个情况下环境变量配置的例子 可以点击这里 接下来 我就一边安装一边做个教程 尽可

    2026年3月26日
    3
  • jenkins 邮件_un38.3测试报告

    jenkins 邮件_un38.3测试报告前言前面已经实现在jenkins上展示html的测试报告,接下来只差最后一步,把报告发给你的领导,展示你的劳动成果了。安装EmailExtensionPlugin插件jenkins首页-

    2022年7月29日
    6
  • 堆排序实现及应用

    堆排序实现及应用

    2022年2月6日
    47
  • jenkinsfile docker_docker从0创建镜像

    jenkinsfile docker_docker从0创建镜像前言之前我们用docker手动安装了jenkins环境,在jenkins中又安装了python3环境和各种安装包,如果我们想要在其他3台机器上安装,又是重复操作,重复劳动,那会显得很low,这里可以

    2022年7月31日
    9
  • linux下gdb调试方法与技巧整理「建议收藏」

    linux下gdb调试方法与技巧整理「建议收藏」目录一、gdb简介二、gdb使用流程1、启动gdb2、查看源码3、运行程序4、设置断点5、单步执行6、查看变量7、退出gdb三、gdb基本使用命令1、运行命令2、设置断点3、查看源码4、打印表达式5、查看运行信息6、分割窗口7、cgdb强大工具四、总结一、gdb简介GDB是一个由GNU开源组织发布的、UNIX/LINUX操作系统下的、基于命令行的、功能强大的程序调试工具。对于一名Linux下…

    2022年5月25日
    74

发表回复

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

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