maxgalbu / adonis5-jwt

JWT Authentication service for Adonisjs v5
MIT License
86 stars 15 forks source link

feat (guard): add possibility to get access token from cookie #8

Closed chramos closed 2 years ago

chramos commented 2 years ago

I'm using this library in a personal project and I need to get access token from cookies and it is not possible so far. This change allow us to provide the access token to the guard class from auth.config file

e.g:

//config/auth.ts
 basic: {
 },
jwt: {
  ...{ALL_JWT_CONFIG}
  getBearerToken: (ctx) => {
      const token = ctx.request.cookie('authorization')
      if (token) {
        return token
      }
      return ''
   },
}

if nothing was provided in the auth.config file, the default getBearerToken will be executed

maxgalbu commented 2 years ago

Apart from the comments, this looks good to me! Please review the commits and I'll merge it

claudesortwell commented 2 years ago

Any chance we can re open this? I'm happy to make any changes you need.

I've implemented this but using patch-package.

maxgalbu commented 2 years ago

Actually, it was merged as you can see just above your comment (in https://github.com/maxgalbu/adonis5-jwt/commit/548ea8940054fa356049809554b0e128683a7c24). I just didn't release any version, I was working on the MongoDb adapter. I'll release a new version with this fix

maxgalbu commented 2 years ago

There you go: https://github.com/maxgalbu/adonis5-jwt/releases/tag/v1.1.7

claudesortwell commented 2 years ago

Sorry about that seemed to have missed that, and thanks for updating the version.