dan*_*iax 4 c# identityserver4 angular
我Identity Server 4在我的Angular 5应用程序中使用。
我以这种方式配置了身份服务器:
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());
}
Run Code Online (Sandbox Code Playgroud)
这是我的 Angular 配置:
export const oAuthDevelopmentConfig: AuthConfig = {
clientId: "client",
scope: "api1",
oidc: false,
issuer: "http://localhost:5000",
requireHttps: false
}
Run Code Online (Sandbox Code Playgroud)
我这样使用配置:
...
signin(): void {
this.oAuthService
.fetchTokenUsingPasswordFlowAndLoadUserProfile(this.model.username, this.model.password)
.then(() => {
this.authenticationService.init();
...
Run Code Online (Sandbox Code Playgroud)
当我尝试访问服务器时,我收到以下错误,但我不明白问题出在哪里:
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***"
}
}
Run Code Online (Sandbox Code Playgroud)
我想念什么?
这是一个老问题,但我今天在同一个问题上做了一些头脑风暴。我发现了这个方法:AddResourceOwnerValidator。问这个问题时,这种方法可能不存在。
这是我的 AddIdentityServer 配置。
services.AddIdentityServer(opt => opt.IssuerUri = issuerUri)
.AddDeveloperSigningCredential()
.AddInMemoryApiResources(IdServer.Configuration.GetApiResources())
.AddInMemoryClients(IdServer.Configuration.GetClients())
.AddProfileService<ProfileService>()
.AddResourceOwnerValidator<ResourceOwnerPasswordValidator>()
;
Run Code Online (Sandbox Code Playgroud)
在原题的时候,答案大概是这样的,如问题IdentityServer4 register UserService and get users from database in asp.net core
//Inject the classes we just created
services.AddTransient<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
services.AddTransient<IProfileService, ProfileService>();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2328 次 |
| 最近记录: |