question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding Authentication Header to Request

See original GitHub issue

Trying to stream media from an API that requires the header “Authorization: Bearer <token>”.

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?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
regnetecommented, Aug 13, 2019

Would be a very usefull feature.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authorization - HTTP - MDN Web Docs - Mozilla
The HTTP Authorization request header can be used to provide credentials that authenticate a user agent with a server, allowing access to a ......
Read more >
Setting Authorization Header of HttpClient - Stack Overflow
What I've used is: client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "encrypted user/pwd"); Taking encrypted user/pwd from ...
Read more >
How do I Send a GET Request with Bearer Token ... - ReqBin
To send a GET request with a Bearer Token authorization header, you need to make an HTTP GET request and provide your Bearer...
Read more >
Make authenticated requests - Flutter documentation
Add authorization headers ​​ The http package provides a convenient way to add headers to your requests. Alternatively, use the HttpHeaders class from...
Read more >
Authorizing requests - Postman Learning Center
You can include the auth details either in the request headers or in the body / URL. Select one from the Add authorization...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found