diff --git a/client/src/app/auth.interceptor.ts b/client/src/app/auth.interceptor.ts index d26e98d..2aa8775 100644 --- a/client/src/app/auth.interceptor.ts +++ b/client/src/app/auth.interceptor.ts @@ -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> { 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); diff --git a/server/RdtClient.Service/Middleware/AuthorizeMiddleware.cs b/server/RdtClient.Service/Middleware/AuthorizeMiddleware.cs new file mode 100644 index 0000000..f4409af --- /dev/null +++ b/server/RdtClient.Service/Middleware/AuthorizeMiddleware.cs @@ -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; + } + + /// + /// Return a 403 instead of a 401, it's quirk that QBittorrent has. + /// + /// + /// + public async Task Invoke(HttpContext context) + { + await _next(context); + + if (context.Response.StatusCode == (Int32) HttpStatusCode.Unauthorized) + { + context.Response.StatusCode = (Int32) HttpStatusCode.Forbidden; + } + } + } +} \ No newline at end of file diff --git a/server/RdtClient.Web/Startup.cs b/server/RdtClient.Web/Startup.cs index 3f42152..b40e6a1 100644 --- a/server/RdtClient.Web/Startup.cs +++ b/server/RdtClient.Web/Startup.cs @@ -94,6 +94,8 @@ namespace RdtClient.Web app.ConfigureExceptionHandler(); + app.UseMiddleware(); + app.Use(async (context, next) => { await next.Invoke();