zoukankan      html  css  js  c++  java
  • 基于IdentityServer4的声明的授权

    ## 概述

    基于Asp.net Core 1.1 ,使用IdentityServer4认证与授权。

    ## 参考资料

    [微软教程](https://docs.microsoft.com/zh-cn/aspnet/core/security/authorization/claims#security-authorization-claims-based)

    ## 客户端的设置

    ### 配置与IdentityServerSystem连接

    //配置与IdentityServerSystem连接
    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
    AuthenticationScheme = "Cookies"
    });
    JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();


    ////For MVC Implicit Flow
    app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
    {
    AuthenticationScheme = "oidc",
    SignInScheme = "Cookies",
    Authority = "http://localhost:5000",
    ClientId = "testClientID",
    RequireHttpsMetadata = false,
    Scope = { "testclientidentity" },
    GetClaimsFromUserInfoEndpoint = true,

    SaveTokens = true
    });

    ### 在Controller的Action中加入权限

    using Microsoft.AspNetCore.Authorization;
    public class TestsController : Controller
     [Authorize(Policy = "EditInfo")]
      public IActionResult Edit(){
      }
    }

    ## IdentityServer4服务器端设置

    ### 创建ClientID

    ClientID为testClientID,

    ### 创建IdentityScope

    创建名为testclientidentity的IdentityScope

    在其中加入一些UserClaim,比如"EditInfo"

    ## 测试

    1. 利用用户名为"a"的用户登陆程序,在进入Tests/Edit时,会提示拒绝访问的错误界面

    2. 给用户"a"加入名为"EditInfo"的UserClaim,再次进入Tests/Edit时,会正确显示界面

  • 相关阅读:
    Eclipse下Tomcat插件的安装
    支付宝接口资料解读
    文件转换器服务推荐
    接吻的学问
    Web小工具推荐
    两个优秀的免费字体资源
    每年考证时间
    Visual Studio 2008 简体中文版和MSDN下载
    生活小经验
    UIScrollView and lazy loading
  • 原文地址:https://www.cnblogs.com/hahaxi/p/7820509.html
Copyright © 2011-2022 走看看