Hi, I am trying to authenticate .net core web service via anuglar 7 application. I have tried passing
application/json
but for some reason the request isn't received by the service.
public async Task Invoke(HttpContext context)
{
string authHeader = context.Request.Headers["Authorization"];
if (!string.IsNullOrEmpty(authHeader))
{
var secretKey = Startup.AppSettings.Secret;
var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(secretKey));
List<SymmetricSecurityKey> keys = new List<SymmetricSecurityKey>();
keys.Add(signingKey);
try
{
ValidateAndDecode(authHeader, keys);
await _next.Invoke(context);
}
catch (Exception ex)
{
context.Response.StatusCode = 401;
await context.Response.WriteAsync(ex.Message);
}
}
}
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const authReq = request.clone({
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
});
console.log('Intercepted HTTP call', authReq);
return next.handle(authReq);
}
request is received when I send headers as
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
but change it to
'Content-Type': 'application/json'
and service stops getting request from client
What I have tried:
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const authReq = request.clone({
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
});
console.log('Intercepted HTTP call', authReq);
return next.handle(authReq);
}
Added headers but didn't work