使用IdentityServer4 请求授权时出现invalid_scope的问题


如果你正在网上找IdentityServer4的学习资料进行学习,发现在请求token的时候一直报
{"error":"invalid_scope"}错误
有一个原因可能就是因为你没有加scope

IdentityServer4 4.x版本跟老版本有些区别,可能你的学习资料还是老的

 services.AddIdentityServer()
               .AddDeveloperSigningCredential()
               .AddInMemoryApiResources(Config.GetResource())
               .AddInMemoryClients(Config.GetClients())
               .AddInMemoryApiScopes(Config.ApiScopes) //这个方法是新加的
               .AddTestUsers(Config.GetTestUsers());`




 public static IEnumerable<ApiResource> GetResource()
        {
            return new List<ApiResource>() {
                new ApiResource(MemoryClient.adminFont, "font"){ /*这个一定要加
*/ Scopes = { MemoryScope.menu,MemoryScope.person }}
            };
        }

然后就能继续愉快的学习了


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM