새해 복 많이 받으세요는 ... IdentityServer4 IdentityServer3.AccessTokenValidation 모든 사람에게
가 나는 IdentityServer4을 구성, 나는 성공 ASP.net 코어 웹 API를 호출 할 수 있습니다. asp.net 프레임 워크 4.5.2 웹 api, .NET Framework 웹 API에서 { "응답 상태 코드가 성공 (401 (Unauthorized)."} 오류가 발생했습니다. 나는 너의 도움과 의견을 묻고 싶다.IS4를 사용하여 항목을 검색하고 IdentityServer3.AccessTokenValidation 호환성에 대한 항목을 발견했습니다. 그리고 답장에 따르면, 나는 서명 인증서를로드하고 AddTemporarySigninCredential 대신 AddSigningCredential을 호출했습니다. x509certificate는 로컬에서 만든 인증서입니다. IdentityServer3.AccessTokenValidation 버전을 v2.13.0으로 업데이트했습니다.
여전히 오류가 발생했습니다. 도움을 주시면 감사하겠습니다.
감사합니다.
IdentityServer 4면 : Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services
.AddIdentityServer()
//.AddTemporarySigningCredential()
.AddSigningCredential(x509Certificate)
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients())
.AddAspNetIdentity<ApplicationUser>();
}
Config.cs
public static IEnumerable<ApiResource> GetApiResources()
{
return new List<ApiResource>
{
new ApiResource("AuthorizationWebApi","Authorization Web API .NET Core"),
new ApiResource("AuthorizationWebApiNetFramework","Authorization Web API NET Framework"),
new ApiResource("api1", "Empty Test Api")
};
}
public static IEnumerable<Client> GetClients()
{
return new List<Client> {
new Client {
ClientId = "silicon",
ClientName = "console app",
AllowedGrantTypes = GrantTypes.ClientCredentials,
ClientSecrets = { new Secret("abcdef".Sha256())},
AllowedScopes = new List<string>{
"AuthorizationWebApiNetFramework"
}
},
new Client
{
ClientId = "MYUX",
ClientName = "MYUX MVC Client",
AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
RequireConsent = false,
ClientSecrets= {new Secret("abcdef".Sha256()) },
RedirectUris = { "http://localhost:5002/signin-oidc" },
PostLogoutRedirectUris = {"http://localhost:5002"},
AllowedScopes = {
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"custom.profile",
"AuthorizationWebApi",
"AuthorizationWebApiNetFramework"
},
AllowOfflineAccess = true
}
};
}
.NET 프레임 워크 API 측면
public void Configuration(IAppBuilder app)
{
//ConfigureAuth(app);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "http://www.abcdefgh.com:5000",
ValidationMode = ValidationMode.ValidationEndpoint,
RequiredScopes = new[] { "AuthorizationWebApiNETFramework" }
});
//configure web api
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
//require authentication for all controllers
config.Filters.Add(new AuthorizeAttribute());
app.UseWebApi(config);
}
호출 측 :
,987,198,861또는 콘솔 응용 프로그램에 의해3210 ...
try
{
// discover endpoints from metadata
var disco = await DiscoveryClient.GetAsync("http://www.abcdefgh.com:5000");
var tokenClient = new TokenClient(disco.TokenEndpoint, "silicon", "abcdef");
var tokenResponse = await tokenClient.RequestClientCredentialsAsync("AuthorizationWebApiNetFramework");
if (tokenResponse.IsError)
{
Console.WriteLine(tokenResponse.Error);
return;
}
Console.WriteLine(tokenResponse.Json);
var client = new HttpClient();
client.SetBearerToken(tokenResponse.AccessToken);
var response = await client.GetAsync("http://localhost:13243/values");
if (!response.IsSuccessStatusCode)
{
Console.WriteLine(response.StatusCode);
}
else
{
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(JArray.Parse(content));
}
}
catch (Exception)
{
throw;
}
편집 : 나는 줄 ValidationMode = ValidationMode.ValidationEndpoint에서 주석 : API를 측면 4.5.2에. IS3 설명서를 따라이 줄을 추가했습니다. 모두에게 감사드립니다.
내가 샘플로 시작하는 제안 그들이 작동하는지 확인 것입니다. 그런 다음 샘플에서 사용자 지정 프로젝트의 차이점을 비교하기 시작합니다. –
401 오류가 발생했을 때 idsrv4 로그에서 말하는 내용은 무엇입니까? –
감사합니다 얘들 아 @ BrockAllen 내가 오픈 아이디로 ASP.Net Core MVC를 인증 할 수 있다고 말했고, ASP.Net Core WebApi를 ASP.Net Core IS4로 클라이언트 자격 증명으로 인증합니다. 하지만 4.5.2 ApiResource에 문제가 있습니다. Jonas Axelsson 토큰이 성공적으로 생성되는 것을 볼 수 있지만 WebApi의 GetAsync를 호출 할 때 아무 일도 일어나지 않는다는 것을 기억합니다. 나는 오늘 그것을 점검 할 것이다 :). 안부 – ozgurozkanakdemirci