【发布时间】:2017-12-30 17:44:09
【问题描述】:
我在我的Angular 5 应用程序中使用Identity Server 4。
我是这样配置身份服务器的:
public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
new Client
{
ClientId = "client",
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
AllowAccessTokensViaBrowser = true,
RequireClientSecret = false,
AllowedScopes = {
"api1"
},
AllowedCorsOrigins = new List<string>
{
"http://localhost:4200"
}
}
};
}
public void ConfigureServices(IServiceCollection services)
{
var cors = new DefaultCorsPolicyService(_loggerFactory.CreateLogger<DefaultCorsPolicyService>())
{
AllowedOrigins = { "http://localhost:4200" }
};
services.AddSingleton<ICorsPolicyService>(cors);
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients());
}
这是我的 Angular 配置:
export const oAuthDevelopmentConfig: AuthConfig = {
clientId: "client",
scope: "api1",
oidc: false,
issuer: "http://localhost:5000",
requireHttps: false
}
我是这样使用配置的:
...
signin(): void {
this.oAuthService
.fetchTokenUsingPasswordFlowAndLoadUserProfile(this.model.username, this.model.password)
.then(() => {
this.authenticationService.init();
...
当我尝试访问服务器时,我收到以下错误,但我不明白问题出在哪里:
info: IdentityServer4.Hosting.IdentityServerMiddleware[0]
Invoking IdentityServer endpoint: IdentityServer4.Endpoints.TokenEndpoint for /connect/token
info: IdentityServer4.Validation.NotSupportedResourceOwnerPasswordValidator[0]
Resource owner password credential type not supported. Configure an IResourceOwnerPasswordValidator.
fail: IdentityServer4.Validation.TokenRequestValidator[0]
Resource owner password credential grant type not supported
fail: IdentityServer4.Validation.TokenRequestValidator[0]
{
"ClientId": "client",
"GrantType": "password",
"Scopes": "api1",
"UserName": "admin@gmail.com",
"Raw": {
"grant_type": "password",
"client_id": "client",
"scope": "api1",
"username": "admin@gmail.com",
"password": "***REDACTED***"
}
}
我想念什么?
【问题讨论】:
-
您是如何实际配置 IdSrv 的? (在启动中)
-
您是否提供了自定义 IResourceOwnerPasswordValidator?没有那个身份服务器就不知道如何实际验证密码是否正确。
-
我更新了我的帖子
-
AFAIK,您需要添加测试用户、身份或自定义用户存储。目前,您尚未为用户配置任何内容
-
Like@Evk 建议,添加一个 IResourceOwnerPasswordValidator。它甚至在错误消息“配置 IResourceOwnerPasswordValidator”中字面上都说
标签: c# angular identityserver4