Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 548ea89

Browse files
committed
feat (guard): add possibility to get access token from cookie (closes #8)
1 parent 4b5d8d6 commit 548ea89

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

adonis-typings/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
2+
13
declare module "@ioc:Adonis/Addons/Jwt" {
24
import {
35
DatabaseTokenProviderConfig,
@@ -89,6 +91,11 @@ declare module "@ioc:Adonis/Addons/Jwt" {
8991
* User provider
9092
*/
9193
provider: ProvidersList[Provider]["config"];
94+
95+
/**
96+
* Default JWT uses the ctx.request.header("Authorization")
97+
*/
98+
getBearerToken?: (ctx: HttpContextContract) => string
9299
};
93100

94101
/**

lib/Guards/JwtGuard.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,14 @@ export class JWTGuard extends BaseGuard<"jwt"> implements JWTGuardContract<any,
464464
* Returns the bearer token
465465
*/
466466
private getBearerToken(): string {
467+
if (this.config.getBearerToken) {
468+
try {
469+
return this.config.getBearerToken(this.ctx);
470+
} catch (error) {
471+
throw new JwtAuthenticationException(error.message);
472+
}
473+
}
474+
467475
/**
468476
* Ensure the "Authorization" header value exists
469477
*/

0 commit comments

Comments
 (0)