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

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions adonis-typings/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
import { Exception } from '@adonisjs/core/build/standalone';
declare module "@ioc:Adonis/Addons/Jwt" {
import {
DatabaseTokenProviderConfig,
Expand Down Expand Up @@ -89,6 +91,11 @@ declare module "@ioc:Adonis/Addons/Jwt" {
* User provider
*/
provider: ProvidersList[Provider]["config"];

/**
* Default JWT uses the ctx.request.header("Authorization")
*/
getBearerToken: (ctx: HttpContextContract) => string | Exception
};

/**
Expand Down
7 changes: 7 additions & 0 deletions lib/Guards/JwtGuard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,13 @@ export class JWTGuard extends BaseGuard<"jwt"> implements JWTGuardContract<any,
* Returns the bearer token
*/
private getBearerToken(): string {
if(this.config.getBearerToken) {
try {
return this.config.getBearerToken(this.ctx);
} catch (error) {
throw new JwtAuthenticationException(error);
}
}
/**
* Ensure the "Authorization" header value exists
*/
Expand Down