Implementing authorization on the video player

This commit is contained in:
Zoe Roux 2020-04-01 02:57:26 +02:00
parent 39dc1460e9
commit 76fbdce3be
2 changed files with 17 additions and 3 deletions

View File

@ -130,7 +130,7 @@ export class AppModule
client_id: 'kyoo.webapp',
response_type: "code",
trigger_authorization_result_event: true,
scope: "openid profile kyoo.read offline_access",
scope: "openid profile offline_access kyoo.read kyoo.play",
silent_renew: false,
silent_renew_url: "/silent",
use_refresh_token: false,

View File

@ -1,4 +1,4 @@
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import {Component, Inject, Injector, OnInit, ViewEncapsulation} from '@angular/core';
import { MatSnackBar } from "@angular/material/snack-bar";
import { DomSanitizer, Title } from "@angular/platform-browser";
import { ActivatedRoute, Event, NavigationCancel, NavigationEnd, NavigationStart, Router } from "@angular/router";
@ -6,6 +6,7 @@ import { Track, WatchItem } from "../../models/watch-item";
import { Location } from "@angular/common";
import * as Hls from "hls.js"
import { getPlaybackMethod, method, getWhatIsSupported, SupportList } from "../../videoSupport/playbackMethodDetector";
import {OidcSecurityService} from "angular-auth-oidc-client";
declare var SubtitleManager: any;
@ -52,7 +53,10 @@ export class PlayerComponent implements OnInit
private progress: HTMLElement;
private buffered: HTMLElement;
constructor(private route: ActivatedRoute, private sanitizer: DomSanitizer, private snackBar: MatSnackBar, private title: Title, private router: Router, private location: Location) { }
private oidcSecurity: OidcSecurityService;
constructor(private route: ActivatedRoute, private sanitizer: DomSanitizer, private snackBar: MatSnackBar, private title: Title, private router: Router, private location: Location, private injector: Injector) { }
ngOnInit()
{
@ -399,6 +403,16 @@ export class PlayerComponent implements OnInit
selectPlayMethod(playMethod: method)
{
this.playMethod = playMethod;
if (this.oidcSecurity === undefined)
this.oidcSecurity = this.injector.get(OidcSecurityService);
this.hlsPlayer.config.xhrSetup = (xhr, url) =>
{
const token = this.oidcSecurity.getToken();
if (token)
xhr.setRequestHeader("Authorization", "Bearer " + token);
};
if (this.playMethod == method.direct)
{
this.player.src = "/video/" + this.item.link;