nchutchind/cordova-plugin-streaming-media

Adding Authentication Header to Request

Open

#111 建立於 2017年11月29日

在 GitHub 查看
 (5 留言) (0 反應) (0 負責人)Java (392 star) (285 fork)batch import
enhancementhelp wantedpull-request-welcome

描述

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?

貢獻者指南