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();
            }

    再次请求成功:

  • 相关阅读:
    数据库的优化
    Java 10
    sleep()和yield()的区别
    mvc框架实现的流程,值得收藏
    MyEclipse项目出现红色!的原因
    The requested resource is not available的解决方案-转载博文
    web.xml详解(web-app_2_3.dtd)规范顺序
    EditText小写字母自动转换成大写(注:设置之后只能显示大写字母)
    Android GridView属性意义集合(转)
    Theme.AppCompat.Light无法找到问题(转)
  • 原文地址:https://www.cnblogs.com/slsddy/p/14441653.html
Copyright © 2011-2022 走看看