Skip to content

Understanding of DefaultOAuthInterceptor #497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Hummelbeine opened this issue Jan 18, 2019 · 5 comments
Closed

Understanding of DefaultOAuthInterceptor #497

Hummelbeine opened this issue Jan 18, 2019 · 5 comments
Labels
more-info-needed Please provide a minimal example (e.g. at stackblitz.com) which demonstrates the issue

Comments

@Hummelbeine
Copy link

Hi there,

this is more a question than an issue.

I have an application split into an angular frontend and a spring-boot rest backend and try to integrate a keycloak oauth2/oidc authentication. I had the following plan:

  • just secure the rest endpoints
  • enforce a login only when the rest endpoints require one

So I thought an interceptor is a good place to init a login. I'm using the DefaultOAuthInterceptor which detects a 401/403 as I expected but then it does a redirect to http://localhost:4200/login.

And I cannot find the place where this behaviour is implemented nor how I can substitute it by starting the initial login flow.

Any hints are welcome. :-)

Thanks,
Stephan

@jeroenheijmans
Copy link
Collaborator

Please check out #414 which might already answer your question.

@Hummelbeine
Copy link
Author

Hi Jeroen,

thank's for your fast reply. I already brought a HttpInterceptor in place and it works when receiving a HTTP 200 or 404.

When receiving a HTTP 401, I can see my interceptor logging when receiving the request.

public intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
  console.log('intercepting request...');
  console.log(request);

  return next.handle(request).do(
    (event: HttpEvent<any>) => {
      if (event instanceof HttpResponse) {
        console.log('receiving response...');
        console.log(event);
      }
    },
    (error: any) => {
      if (error instanceof HttpErrorResponse) {
        console.log('receiving error response...');
        console.error(error);
      }
    }
  );
}

But the logging when receiving the response does not take place.

Instead there is that redirect to http://localhost:4200/login which happens even when I totally remove the usage of angular-oauth2-oidc.

Maybe it is a HttpClient related behaviour?

Thanks,
Stephan

@jeroenheijmans
Copy link
Collaborator

Hmm, if you get such specific unexpected behavior no longer related to angular-oauth2-oidc, I suggest further trimming down the code into a minimal repro (e.g. a StackBlitz example), and possibly asking a question on Stack Overflow about the behavior. Good luck!

@jeroenheijmans
Copy link
Collaborator

Hoping you resolved the issue in the mean time? Thinking we might close this issue, unless you still have an open issue? (In which case we'd need steps to reproduce the problem, otherwise it's not really possible to help...)

@jeroenheijmans jeroenheijmans added the more-info-needed Please provide a minimal example (e.g. at stackblitz.com) which demonstrates the issue label Aug 4, 2019
@jeroenheijmans
Copy link
Collaborator

Going to tidy up and close the issue. Let us know if the problem persists, and if so please try to provide a minimal repro (here, to reopen things, or in a fresh issue). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more-info-needed Please provide a minimal example (e.g. at stackblitz.com) which demonstrates the issue
Projects
None yet
Development

No branches or pull requests

2 participants