question on authinterceptor
See original GitHub issueI 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:
- Created 2 years ago
- Comments:12
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
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.