授权好使,能够获取令牌,带上令牌去访问写好的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";
});
给的资料不全的话,欢迎提问