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.

question on authinterceptor

See original GitHub issue

I had a question regarding sending the Token as part of the header when communicating with the backend. The documentation [here] (https://github.com/damienbod/angular-auth-oidc-client/blob/main/docs/using-access-tokens.md#http-interceptor) states that one only needs to include the Authinterceptor provider and define the secureRoutes in the config. Just doing this did not automatically add the token to the request header. I just used a standard piece of code like this

@Injectable()
export class AuthInterceptorService implements HttpInterceptor {

  constructor(private oidcSecurityService: OidcSecurityService) {
  }

  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    const token = this.oidcSecurityService.getToken();
    const modifiedRequest = req.clone({
      headers: req.headers.set('Authorization', 'Bearer ' + token)
    });
    return next.handle(modifiedRequest);
  }
}

Only then did it work. But then naturally I am not doing something right. Cause now the Authinterceptor from your package is not being used. Maybe this is a noob question. Sorry, please help.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
rtamsatyamcommented, Jun 11, 2021

I have updated the project with the source files from https://github.com/damienbod/angular-auth-oidc-client/tree/main/projects/sample-code-flow-refresh-tokens

The call to backend code is under src/app/home/user.service.ts

0reactions
FabianGosebrinkcommented, Jun 14, 2021

Like said: CORS is a server issue. If you use the /api/... route before and the backend AND frontend are running on the same origin, you do not have CORS problems.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: No provider for AuthInterceptor - angular - Stack Overflow
To resolve the problem at hand, change useExisting to useClass , if AuthInterceptor is a class, otherwise change it to useValue or ...
Read more >
Authentication Interceptor for Angular does not appear to work
To begin with, I apologise for any ignorance I show in this post I am very much a beginner to using Okta and...
Read more >
pubsub emulator authinterceptor question #1381 - GitHub
I get the following when subscribing to a topics subscription locally: ... [pubsub] Nov 09, 2016 1:46:17 PM com.google.cloud.iam.testing.v1.shared.authorization ...
Read more >
Watch out what you expose with Angular Interceptors
export class AuthInterceptor implements HttpInterceptor { ... From the top Stack Overflow question and the corresponding answer: question.ts
Read more >
Angular — an interceptor interview question with a tricky aspect
The common answer and a good way to go, is to use an interceptor in the app or core module and add the...
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