Skip to content
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

UnauthorizedHandler never called #31

Closed
mstimvol opened this issue Aug 9, 2023 · 2 comments
Closed

UnauthorizedHandler never called #31

mstimvol opened this issue Aug 9, 2023 · 2 comments

Comments

@mstimvol
Copy link

mstimvol commented Aug 9, 2023

At first... Thank you very much for this great plugin! It works perfectly - except one thing... my unauthorizedHandler is never called. Here's my registration:

  fastify.register(require('fastify-keycloak-adapter'), {
    appOrigin: env('APP_URL'),
    keycloakSubdomain: env('KEYCLOAK_SUBDOMAIN'),
    clientId: env('KEYCLOAK_CLIENT_ID'),
    clientSecret: env('KEYCLOAK_CLIENT_SECRET'),
    callback: '/login',
    autoRefreshToken: true,
    scope: ['openid', 'profile', 'email'],
    unauthorizedHandler: (req, resp) => {
      console.log('hello world!')
      resp.status(401).send('Invalid request')
    },
    userPayloadMapper: (payload) => ({
      name: payload.name,
      email: payload.email,
      given_name: payload.given_name,
      family_name: payload.family_name,
      preferred_username: payload.preferred_username
    })
  })

In my fastify logs I see only the following:

  {"level":20,"time":1691607443896,"pid":10120,"hostname":"PC-09","msg":"Keycloak Options valid successfully. Keycloak options: <removed ;-)>"}
  {"level":30,"time":1691607444242,"pid":10120,"hostname":"PC-09","msg":"Keycloak registered successfully!"}
  {"level":30,"time":1691607444342,"pid":10120,"hostname":"PC-09","msg":"Server listening at http://[::1]:8888"}
  {"level":30,"time":1691607444343,"pid":10120,"hostname":"PC-09","msg":"Server listening at http://127.0.0.1:8888"}
  Webserver is listening on http://[::1]:8888
  {"level":20,"time":1691607465215,"pid":10120,"hostname":"PC-09","reqId":"req-1","msg":"Keycloak adapter: grant not found in session"}

And then I'm getting redirected to Keycloak. Any idea what I'm doing wrong here?

@yubinTW
Copy link
Owner

yubinTW commented Aug 16, 2023

yes, I have fixed this issue in 2.1.0
when user set unauthorizedHandler, he has to handle all of the unauthorized situations.

@mstimvol
Copy link
Author

Thank you very much, @yubinTW! I updated my application and now it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants