Identity Server를 처음 사용했습니다. 나는 전에 그것을 구성하지 않았다. 하지만 내가 작업중인 프로젝트에 필요합니다.Identity Server 4 - invaid_client 오류 받기
API는 Angular JS Client, iOS App 및 Android App을 제공합니다. 우리는 인증과 인증을 구현해야합니다.
참고 : 동일한 웹 API 프로젝트에서 Identity Server와 내 API를 구성하려고합니다.
나는 다음과 같은 문서 및 구성 신원 서버 따랐다: https://stackoverflow.com/a/35306021/1910735
:ConfigureServices()
services.AddTransient<IProfileService, CustomProfileService>();
services.AddTransient<IResourceOwnerPasswordValidator, CustomResourceOwnerPasswordValidator>();
services.AddIdentityServer()
.AddTemporarySigningCredential()
// add the resources that need to be secured
.AddInMemoryApiResources(IdentityServerConfig.Resources.GetApiResources())
// add the clients that will be access the ApiResources
.AddInMemoryClients(IdentityServerConfig.Clients.GetClients());
CustomProfileService
및 CustomResourceOwnerPasswordValidator
이 대답과 같은에서 startup.cs에서
을,
있음 Configure()
(10)는 GetClients()
public static IEnumerable<Client> GetClients()
{
var clients = new List<Client>();
var websiteGrants = new List<string> { GrantType.ResourceOwnerPassword };
var secret = new Secret("secret".Sha256());
var websiteClient = new Client()
{
// we will be using Angular JS to access the API - so naming it js
ClientId = "js",
// just a human friendly name
ClientName = "JavaScript Client",
// set to GrantType.ResourceOwnerPassword - because using Username/Password to login
AllowedGrantTypes = websiteGrants,
// secret for authentication
//TODO: Change the secret
ClientSecrets = { secret },
// we need to access the fhApi from Angular JS front-end
// fhApi is defined in Resources file as an API Resource
AllowedScopes = { "obApi" }
};
clients.Add(websiteClient);
return clients;
}
이며, 여기에 내가 사용하고자하기 때문에 지금 GetApiResources()
public static IEnumerable<ApiResource> GetApiResources()
{
// e.g. if we want to protect an API called api1 - then we will add it here
// these values are hard coded for now - but we can get from DB, config file etc.
return new List<ApiResource>
{
new ApiResource("obApi", "Order2Bite API")
};
}
입니다 난 그냥에서 액세스 토큰을 얻으려면 그것을 각도 JS, iOS 및 Android Identity Server를 누른 다음 인증 및 권한 부여에 대한 액세스 토큰을 사용하십시오. 이것에 대한
은 내가 JS 클라이언트에서 /connect/token
에 액세스하려고하지만 나는 invalid_client
오류를 얻고있다.
var user = { client_id: "js", grant_type: 'password', username: "testuser", password: "testpasswrd", scope: 'obApi' };
var urlEncodedUrl = {
'Content-Type': 'application/x-www-form-urlencoded',
};
this.$http({
method: 'POST', url: "http://localhost:44337/connect/token",
headers: urlEncodedUrl,
data: user,
})
.then(data => {
console.log(data)
},
data => {
console.log(data)
});
I는 서버 측에서 얻을 오류 '찾을 수 없음 클라이언트 식별자'입니다 :
1 - 왜이 오류가 무엇입니까를?
2 - JS, Android 및 iOS에서 프로그래밍 방식으로 Token을 얻으려면 /connect/token
을 사용해야합니다.이 문제를 해결하려면 어떻게해야합니까? 나는 올바른 길을 가고 있는가?
사용자를 어디에서 구성합니까? grant_type = password 및 username/password로 로그인하고 있습니다. 그것은 사용자가 존재하지 않는 것 같아요, –
요청이 CustomResourceOwnerPasswordValidator에 도달하지 않습니다 - 그래서 신원 서버가 암호 유효성 검사기에 도달하기 전에 invalid_client 오류를 던지고 있음을 의미합니다. @RuardvanElburg –