IdentityServer4 및 다른 클라이언트 ASP.NET 핵심 응용 프로그램을 설치했습니다. 클라이언트는 IdentityServer로 인증하고 표준 MVC 웹 API 프로젝트 인 세 번째 응용 프로그램에 대한 액세스를 요청해야합니다.IdentityServer, ASP.NET 코어 및 웹 API
내가 클라이언트 자격 증명을 달성하기위한 단계를 따라했습니다는 https://identityserver.github.io/Documentation/docsv2/overview/simplestOAuth.html
지금은 완전히 처음 무기명 토큰을 인식하고 나에게 접근하는 몇 가지 권한 부여를 제공하기 위해 웹 API를 활용하는 방법에 분실하고이 예에서 흐름 웹 API 끝점.
이
내 IdentityServer Statrup.cspublic class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentityServer()
.AddInMemoryStores()
.AddInMemoryClients(Config.GetClients())
.AddInMemoryScopes(Config.GetScopes());
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(LogLevel.Debug);
app.UseDeveloperExceptionPage();
app.UseIdentityServer();
}
}
과 Config.cs입니다
ASP.NET 코어가 IdentityServer 및 웹 API 호출public class Config
{
// scopes define the resources in your system
public static IEnumerable<Scope> GetScopes()
{
return new List<Scope>
{
new Scope
{
Name = "api1"
}
};
}
// clients want to access resources (aka scopes)
public static IEnumerable<Client> GetClients()
{
// client credentials client
return new List<Client>
{
// no human involved
new Client
{
ClientName = "Silicon-only Client",
ClientId = "silicon",
Enabled = true,
AccessTokenType = AccessTokenType.Reference,
AllowedGrantTypes = GrantTypes.ClientCredentials,
ClientSecrets = new List<Secret>
{
new Secret("F621F470-9731-4A25-80EF-67A6F7C5F4B8".Sha256())
},
AllowedScopes = new List<string>
{
"api1"
}
}
};
}}
[Route("api/testing")]
public class TestingController : Controller
{
// GET: api/values
[HttpGet]
public IActionResult Get()
{
var responce = GetClientToken();
return Json(new
{
message = CallApi(responce)
});
}
static TokenResponse GetClientToken()
{
var client = new TokenClient(
Constants.TokenEndpoint,
"silicon",
"F621F470-9731-4A25-80EF-67A6F7C5F4B8");
return client.RequestClientCredentialsAsync("api1").Result;
}
static string CallApi(TokenResponse response)
{
var client = new HttpClient
{
BaseAddress = new Uri(Constants.AspNetWebApiSampleApi),
Timeout = TimeSpan.FromSeconds(10)
};
client.SetBearerToken(response.AccessToken);
try
{
var auth = client.GetStringAsync().Result;
return auth;
}
catch (Exception ex)
{
return ex.Message;
}
}
}
그래서 수 누구나 설명하거나 공유 할 수있는 몇 가지 링크를 공유하는 웹 APi (owin 미들웨어와 함께) 통화를 처리 할 ASP.NET 코어 클라이언트에서? Owin Configuration (IAppBuilder 앱) 메서드에 어떤 설정을 적용해야합니까?
감사를 물어 주시기 알고 싶은 경우에, 마지막으로 내가 어디에서 조금 이동 붙어있는 – zdrsh