首页 新闻 会员 周边

IdentityServer4 客户端授权验证401

0
悬赏园豆:50 [已关闭问题] 关闭于 2021-06-29 14:47

授权好使,能够获取令牌,带上令牌去访问写好的webapi就一直提示401

IdentityServer4 配置

public static IEnumerable<ApiResource> GetApis()
        {
            return new List<ApiResource>
            {
                new ApiResource("api1", "My API"){ 
                    Scopes = { "api1" }
                }
            };
        }

        public static IEnumerable<Client> GetClients()
        {
            return new List<Client>
            {
                new Client
                {
                    ClientId = "client",
                    AllowedGrantTypes = GrantTypes.ClientCredentials,
                    ClientSecrets =
                    {
                        new Secret("secret".Sha256())
                    },
                    AllowedScopes = { "api1" }
                }
            };
        }

        public static IEnumerable<ApiScope> GetScopes()
        {
            return new List<ApiScope>
            {
                new ApiScope("api1", "My API")
            };
        }

startup 授权

services.AddIdentityServer()
                .AddDeveloperSigningCredential()
                .AddInMemoryApiResources(Ids4Config.GetApis())
                .AddInMemoryClients(Ids4Config.GetClients())
                .AddInMemoryApiScopes(Ids4Config.GetScopes());

startup 验证

services.AddAuthentication("Bearer")
                .AddJwtBearer("Bearer", options =>
                {
                    options.Authority = "http://localhost:5000";
                    options.RequireHttpsMetadata = false;

                    options.Audience = "api1";
                });
问题补充:

给的资料不全的话,欢迎提问

ufo233-的主页 ufo233- | 初学一级 | 园豆:92
提问于:2021-06-29 09:58
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册