From d3a860fa8ffccade9e3b17022482e11c9a18303e Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 9 May 2021 02:38:38 +0200 Subject: [PATCH] Fixing authentication guard --- src/app/auth/auth.module.ts | 2 +- src/app/auth/auth.service.ts | 3 ++- src/app/auth/misc/authenticated-guard.service.ts | 2 +- src/app/auth/misc/authorizer-interceptor.service.ts | 3 +++ static/more.svg | 1 + 5 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 static/more.svg diff --git a/src/app/auth/auth.module.ts b/src/app/auth/auth.module.ts index 51c7fcc6..9a1135ca 100644 --- a/src/app/auth/auth.module.ts +++ b/src/app/auth/auth.module.ts @@ -34,7 +34,7 @@ export function loadConfig(oidcConfigService: OidcConfigService): () => Promise< clientId: "kyoo.webapp", responseType: "code", triggerAuthorizationResultEvent: false, - scope: "openid profile offline_access", + scope: "openid profile offline_access kyoo.read kyoo.write kyoo.play kyoo.admin", silentRenew: true, silentRenewUrl: "/silent.html", useRefreshToken: true, diff --git a/src/app/auth/auth.service.ts b/src/app/auth/auth.service.ts index 15642a41..0e2ae99e 100644 --- a/src/app/auth/auth.service.ts +++ b/src/app/auth/auth.service.ts @@ -18,11 +18,12 @@ export class AuthService { if (x == null) return; + console.log(x); this.account = { email: x.email, username: x.username, picture: x.picture, - permissions: x.permissions.split(",") + permissions: x.permissions?.split(",") ?? [] }; }); } diff --git a/src/app/auth/misc/authenticated-guard.service.ts b/src/app/auth/misc/authenticated-guard.service.ts index f216cae5..0d70a67f 100644 --- a/src/app/auth/misc/authenticated-guard.service.ts +++ b/src/app/auth/misc/authenticated-guard.service.ts @@ -7,7 +7,7 @@ import { AuthService } from "../auth.service"; export class AuthGuard { public static guards: any[] = []; - public static defaultPermissions: string[]; + public static defaultPermissions: string[] = undefined; public static permissionsObservable: Observable; static forPermissions(...permissions: string[]): any diff --git a/src/app/auth/misc/authorizer-interceptor.service.ts b/src/app/auth/misc/authorizer-interceptor.service.ts index 3960beec..4cd63a92 100644 --- a/src/app/auth/misc/authorizer-interceptor.service.ts +++ b/src/app/auth/misc/authorizer-interceptor.service.ts @@ -18,9 +18,12 @@ export class AuthorizerInterceptor implements HttpInterceptor intercept(request: HttpRequest, next: HttpHandler): Observable> { + if (request.url.startsWith("http")) + return next.handle(request); if (this.oidcSecurity === undefined) this.oidcSecurity = this.injector.get(OidcSecurityService); const token: string = this.oidcSecurity.getToken(); + console.log(request.url, token); if (token) request = request.clone({setHeaders: {Authorization: "Bearer " + token}}); return next.handle(request); diff --git a/static/more.svg b/static/more.svg new file mode 100644 index 00000000..65a683fa --- /dev/null +++ b/static/more.svg @@ -0,0 +1 @@ + \ No newline at end of file