に承認のために働く私は、Identity ServerのIDを開くに新しいですし、APIを構築、 、私のサーバーは、クライアントへのアクセストークンを与えます私は、Identity Server 3およびAPIとクライアントを設定しているのはなぜ[ルート]はアイデンティティサーバ3
public void Configuration (IAppBuilder app)
{
var options = new IdentityServerOptions
{
Factory = new IdentityServerServiceFactory()
.UseInMemoryClients(Clients.Get())
.UseInMemoryScopes(Scopes.Get())
.UseInMemoryUsers(Users.Get()),
RequireSsl = false
};
app.UseIdentityServer(options);
}
と私のAPIは私が
を使用するときに、なぜ私の質問があるpublic void Configuration(IAppBuilder app)
{
//accept access token from indentityserver and require a scope of api1
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "http://localhost:62172/",
ValidationMode = ValidationMode.ValidationEndpoint,
RequiredScopes = new[] { "api1" }
});
//config web api
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
// require authentication for all controllers
config.Filters.Add(new AuthorizeAttribute());
app.UseWebApi(config);
}
を起動しているサーバーでのAPI スタートアップを呼び出すときに、それは使用することができています
[Route("api/Search")]
それは[オーソライズ]
[Route("api/Search")]
public async Task<IHttpActionResult> Companies(SearchRequest searchRequest)
{
}
仕事上の理由ブローコードのように使用してのように動作します。これはつまり、私の方法で私のコントローラで
[Authorize]
public async Task<IHttpActionResult> Companies(SearchRequest searchRequest)
{}
詳細情報
を私は電話をしており、私はユーザーが許可を得ようとしています
public async Task<IHttpActionResult> Companies(SearchRequest searchRequest)
{
var caller = User as ClaimsPrincipal;
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
HttpResponseMessage response = new HttpResponseMessage();
Framework.BusinessLogicFactory factory = new Framework.BusinessLogicFactory();
BusinessLogic.Search search = factory.CreateSearch();
}
しかし、私は、コントローラの[承認]または[ルート(「API/Sreach」)]属性を持っていない場合は、APIへの呼び出しは戻って結果を取得し、 、これは私が私のAPI
をテストしています方法ですstring APiURL = "http://localhost:59791/api/Search";
var responses = GetClientToken();
var clinet = new HttpClient();
var value = new Dictionary<string, string>()
{
{ "CompanyNumber", " " },
{ "CompanyName", "test" },
{ "Address1", " " },
{ "Address2", " " },
{ "Address3", " " },
{ "PostCode", " " },
{ "CountryCode", " " },
};
var content = new FormUrlEncodedContent(value);
var response = await clinet.PostAsync(APiURL, content);
var t = response.StatusCode;
私の質問にマークが付いている理由を教えてください。 –