nchutchind/cordova-plugin-streaming-media
View on GitHubAdding Authentication Header to Request
Open
#111 opened on Nov 29, 2017
enhancementhelp wantedpull-request-welcome
Description
Trying to stream media from an API that requires the header "Authorization: Bearer ".
I've used the following to inject the header:
@Injectable()
export class ApiAuthInterceptor implements HttpInterceptor {
constructor( @Inject(forwardRef(() => SessionProvider)) private session: SessionProvider) { }
intercept(req: HttpRequest<any>, next: HttpHandler) {
let auth: any = {};
if (this.session.auth) auth = this.session.auth;
const newReq = req.clone({ headers: req.headers.set('Authorization', 'Bearer ' + auth.access_token) });
return next.handle(newReq);
}
};
@NgModule({
providers: [
ApiProvider,
{ provide: HTTP_INTERCEPTORS, useClass: ApiAuthInterceptor, multi: true }
]
})
This works great for images, and video will load and play, but the file appears to download in its entirety and play. Also the video time is listed at --:-- and the seek control slider is disabled.
If I disable all authentication on the API and streamed the same file it worked normally, buffering, seek, etc.
Is there a proper way to add the "Authentication" header to the stream request?