Я делаю патч для API, который использует Identity Server для аутентификации. Когда я запускаю его на Postman, патч работает отлично
http://localhost:90909/api/products/3434
Headers = {
Authorization: Bearer <token>
Content-Type: application/json-patch+json
}
Body:
[
{
"op" : "replace",
"path" : "/DESCRIPTION",
"value" : "bruhhh"
}
]
Но когда я выполняю патч на своих Reactjs с помощью axios, он возвращает Unauthorized:
static update(data){
let config = {
data : [],
headers: {
'Authorization' : 'Bearer ' + data.access_token,
'Content-Type' : 'application/json-patch+json'
}
}
config.data.push(
{
"op" : "replace",
"path" : "/DESCRIPTION",
"value" : "you da best"
}
)
return axios.patch(root + '/api/products/' + data.product.id, config);
}
У меня есть настройка Cors для приема запросов с этого порта:
services.AddCors(options =>
{
options.AddPolicy("JSClient", builder =>
builder.WithOrigins("http://localhost:9999")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
});
Так что я не уверен, что еще мне не хватает.
EDIT Исправлен заголовок для почтальона.
Ошибка, которую я вижу в журналах Identity Server
[msg=Log Error];[msg=Exception while initializing Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers.ClientIpHeaderTelemetryInitializer, exception message - System.TypeInitializationException: The type initializer for 'Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.Tracing.AspNetCoreEventSource' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.PlatformAbstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
at Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.Tracing.AspNetCoreEventSource..ctor()
at Microsoft.ApplicationInsights.AspNetCore.Extensibility.Implementation.Tracing.AspNetCoreEventSource..cctor()
--- End of inner exception stack trace ---
at Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers.ClientIpHeaderTelemetryInitializer.OnInitializeTelemetry(HttpContext platformContext, RequestTelemetry requestTelemetry, ITelemetry telemetry)
at Microsoft.ApplicationInsights.TelemetryClient.Initialize(ITelemetry telemetry)]
Вот еще один вывод журнала из serilog
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 OPTIONS http://localhost:90909/api/products/3434
info: Microsoft.AspNetCore.Cors.Infrastructure.CorsService[4]
Policy execution successful.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 15.8032ms 204
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 PATCH http://localhost:90909/api/products/3434 application/json;charset=UTF-8 805
info: Microsoft.AspNetCore.Cors.Infrastructure.CorsService[4]
Policy execution successful.
info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2]
Authorization failed for user: (null).
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[3]
Authorization failed for the request at filter 'Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter'.
info: Microsoft.AspNetCore.Mvc.ChallengeResult[1]
Executing ChallengeResult with authentication schemes ().
info: Microsoft.AspNetCore.Builder.IdentityServerAuthenticationHandler[12]
AuthenticationScheme: Bearer was challenged.
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action InventoryApi.Controllers.ProductsController.Update (InventoryApi) in 46.6963ms
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 127.3384ms 401
Bearer
не отличается в обоих случаях? - person shyammakwana.me   schedule 11.11.2017Authorization:Bearer {{token}}
, если вы используете обычную аутентификацию (как в коде реакции) - person shyammakwana.me   schedule 11.11.2017