zoukankan      html  css  js  c++  java
  • IdentityServer4最新版 出现invalid_scope

    原贴解决方法地址:https://cyimt.net/Article/Details/66

    首先请求地址:http://localhost:5000/connect/token

    出现错误:

    {
        "error": "invalid_request"
    }
    

      请求图片:

     发现请求需要选择    application/x-www-form-urlencoded  而不是form-data

    选择后,开始提示

     后经查找上面链接的帖子解决

    config类代码修改,需要新加代码

    namespace IdentityServiceCenter
    {
    
        public class Config
        {
            public static IEnumerable<ApiResource> GetResources() {
                return new List<ApiResource> { 
                    new ApiResource("api", "My Api") 
                };
            }
    
            public static IEnumerable<Client> GetClients()
            {
                return new List<Client> {
                    new Client() {
                        ClientId = "client",
    
                        AllowedGrantTypes = GrantTypes.ClientCredentials,
                        ClientSecrets={
                            new Secret("secret".Sha256())
                        },
                        AllowedScopes={"api"}
    
                    }
                };
            }
    
    //上面是原来的代码
    
    //下面是需要新加上方法,否则访问提示invalid_scope
            public static IEnumerable<ApiScope> ApiScopes =>
                new ApiScope[] { new ApiScope("api") };
    
            public static IEnumerable<IdentityResource> GetIdentityResources()
            {
                return new List<IdentityResource>
                {
                    new IdentityResources.OpenId()
                };
            }
        }
    }

    Startup类中修改:

    ConfigureServices方法需要修改
    Configure方法中还是只需要开始的app.UseIdentityServer()就可以
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddIdentityServer()
                  .AddInMemoryApiResources(Config.GetResources())
                  .AddInMemoryClients(Config.GetClients())
    
                  //这个ApiScopes需要新加上,否则访问提示invalid_scope
                  .AddInMemoryApiScopes(Config.ApiScopes)
    
                  .AddDeveloperSigningCredential();
    
    
                services.AddControllers();
            }

    再次请求成功:

  • 相关阅读:
    Android开发实例关键点讲解系列之一:Eclipse中建立Android工程
    类欧几里得小记
    【清华集训2017模拟12.09】塔
    【51nod1792】Jabby's segment tree
    【51nod1220】约数之和
    【51nod 2026】Gcd and Lcm
    【JZOJ5180】【NOI2017模拟6.29】呵呵
    2017noip总结
    2017.11.7总结
    Codeforces Round #395 Div.1 C pacifist【JZOJ5449】Pacifist
  • 原文地址:https://www.cnblogs.com/slsddy/p/14441653.html
Copyright © 2011-2022 走看看