Fixed an authentication quirk where theqBittorrent API returns a 403 instead of a 401 when its unauthorized.
This commit is contained in:
parent
5d73ae140e
commit
7c6458bbb0
3 changed files with 42 additions and 8 deletions
|
|
@ -1,14 +1,14 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
HttpEvent,
|
||||
HttpInterceptor,
|
||||
HttpHandler,
|
||||
HttpRequest,
|
||||
HttpErrorResponse,
|
||||
HttpEvent,
|
||||
HttpHandler,
|
||||
HttpInterceptor,
|
||||
HttpRequest,
|
||||
} from '@angular/common/http';
|
||||
import { throwError, Observable } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
|
||||
@Injectable()
|
||||
export class AuthInterceptor implements HttpInterceptor {
|
||||
|
|
@ -20,7 +20,7 @@ export class AuthInterceptor implements HttpInterceptor {
|
|||
): Observable<HttpEvent<any>> {
|
||||
return next.handle(req).pipe(
|
||||
catchError((error: HttpErrorResponse) => {
|
||||
if (error && error.status === 401) {
|
||||
if (error && (error.status === 401 || error.status === 403)) {
|
||||
this.router.navigate(['/login']);
|
||||
}
|
||||
return throwError(error);
|
||||
|
|
|
|||
32
server/RdtClient.Service/Middleware/AuthorizeMiddleware.cs
Normal file
32
server/RdtClient.Service/Middleware/AuthorizeMiddleware.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace RdtClient.Service.Middleware
|
||||
{
|
||||
public class AuthorizeMiddleware
|
||||
{
|
||||
readonly RequestDelegate _next;
|
||||
|
||||
public AuthorizeMiddleware(RequestDelegate next)
|
||||
{
|
||||
_next = next;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a 403 instead of a 401, it's quirk that QBittorrent has.
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
await _next(context);
|
||||
|
||||
if (context.Response.StatusCode == (Int32) HttpStatusCode.Unauthorized)
|
||||
{
|
||||
context.Response.StatusCode = (Int32) HttpStatusCode.Forbidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -94,6 +94,8 @@ namespace RdtClient.Web
|
|||
|
||||
app.ConfigureExceptionHandler();
|
||||
|
||||
app.UseMiddleware<AuthorizeMiddleware>();
|
||||
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
await next.Invoke();
|
||||
|
|
|
|||
Loading…
Reference in a new issue