This repository has been archived by the owner on Jul 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 741a3b5
Showing
18 changed files
with
15,099 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# http://editorconfig.org | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.json] | ||
insert_final_newline = ignore | ||
|
||
[**.min.js] | ||
indent_style = ignore | ||
insert_final_newline = ignore | ||
|
||
[MakeFile] | ||
indent_style = space | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": [ | ||
"plugin:adonis/typescriptPackage", | ||
"prettier" | ||
], | ||
"rules": { | ||
"max-len": "off", | ||
"@typescript-eslint/indent": ["error", 4, { | ||
"SwitchCase": 1, | ||
"flatTernaryExpressions": false, | ||
"ignoredNodes": ["TSTypeParameterInstantiation"] | ||
}], | ||
"@typescript-eslint/space-before-function-paren": ["error", "never"], | ||
"@typescript-eslint/semi": "off", | ||
"@typescript-eslint/quotes": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
build | ||
docs | ||
*.md | ||
config.json | ||
.eslintrc.json | ||
package.json | ||
*.html | ||
*.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
declare module "@ioc:Adonis/Addons/Jwt" { | ||
import { | ||
DatabaseTokenProviderConfig, | ||
RedisTokenProviderConfig, | ||
ProvidersList, | ||
TokenProviderContract, | ||
ProviderTokenContract, | ||
GetProviderRealUser, | ||
GuardsList, | ||
GuardContract, | ||
} from "@ioc:Adonis/Addons/Auth"; | ||
import { DateTime } from "luxon"; | ||
|
||
/** | ||
* Login options | ||
*/ | ||
export type JWTLoginOptions = { | ||
name?: string; | ||
expiresIn?: number | string; | ||
[key: string]: any; | ||
}; | ||
|
||
export type DatabaseJWTTokenProviderConfig = DatabaseTokenProviderConfig & { | ||
refreshTokenKey: string; | ||
}; | ||
export type RedisJWTTokenProviderConfig = RedisTokenProviderConfig & { | ||
refreshTokenKey: string; | ||
}; | ||
|
||
/** | ||
* Shape of JWT guard config. | ||
*/ | ||
export type JWTGuardConfig<Provider extends keyof ProvidersList> = { | ||
/** | ||
* Driver name is always constant | ||
*/ | ||
driver: "jwt"; | ||
|
||
/** | ||
* Issuer name to sign the token | ||
*/ | ||
issuer?: string; | ||
|
||
/** | ||
* Audience to sign the token | ||
*/ | ||
audience?: string; | ||
|
||
/** | ||
* Public key to sign the token | ||
*/ | ||
publicKey: string; | ||
|
||
/** | ||
* Private key to sign the token | ||
*/ | ||
privateKey: string; | ||
|
||
/** | ||
* Provider for managing tokens | ||
*/ | ||
tokenProvider: | ||
| DatabaseJWTTokenProviderConfig | ||
| RedisJWTTokenProviderConfig; | ||
|
||
/** | ||
* User provider | ||
*/ | ||
provider: ProvidersList[Provider]["config"]; | ||
}; | ||
|
||
/** | ||
* JWT token is generated during the login call by the JWTGuard. | ||
*/ | ||
export interface JWTTokenContract<User extends any> { | ||
/** | ||
* Always a bearer token | ||
*/ | ||
type: "bearer"; | ||
|
||
/** | ||
* The user for which the token was generated | ||
*/ | ||
user: User; | ||
|
||
/** | ||
* Date/time when the token will be expired | ||
*/ | ||
expiresAt?: DateTime; | ||
|
||
/** | ||
* Time in seconds until the token is valid | ||
*/ | ||
expiresIn?: number; | ||
|
||
/** | ||
* Any meta-data attached with the token | ||
*/ | ||
meta: any; | ||
|
||
/** | ||
* Token name | ||
*/ | ||
name: string; | ||
|
||
/** | ||
* Token public value | ||
*/ | ||
accessToken: string; | ||
|
||
/** | ||
* Token public value | ||
*/ | ||
refreshToken: string; | ||
|
||
/** | ||
* Token hash (persisted to the db as well) | ||
*/ | ||
tokenHash: string; | ||
|
||
/** | ||
* Serialize token | ||
*/ | ||
toJSON(): { | ||
type: "bearer"; | ||
token: string; | ||
refreshToken: string; | ||
expires_at?: string; | ||
expires_in?: number; | ||
}; | ||
} | ||
|
||
export interface JwtTokenProviderContract extends TokenProviderContract { | ||
/** | ||
* Delete token using the lookup id or the token value | ||
*/ | ||
destroyWithHash(token: string, type: string): Promise<void>; | ||
} | ||
|
||
/** | ||
* Shape of the JWT guard | ||
*/ | ||
export interface JWTGuardContract< | ||
Provider extends keyof ProvidersList, | ||
Name extends keyof GuardsList | ||
> extends GuardContract<Provider, Name> { | ||
token?: ProviderTokenContract; | ||
tokenProvider: JwtTokenProviderContract; | ||
|
||
/** | ||
* Attempt to verify user credentials and perform login | ||
*/ | ||
attempt( | ||
uid: string, | ||
password: string, | ||
options?: JWTLoginOptions | ||
): Promise<JWTTokenContract<GetProviderRealUser<Provider>>>; | ||
|
||
/** | ||
* Login a user without any verification | ||
*/ | ||
login( | ||
user: GetProviderRealUser<Provider>, | ||
options?: JWTLoginOptions | ||
): Promise<JWTTokenContract<GetProviderRealUser<Provider>>>; | ||
|
||
/** | ||
* Generate token for a user without any verification | ||
*/ | ||
generate( | ||
user: GetProviderRealUser<Provider>, | ||
options?: JWTLoginOptions | ||
): Promise<JWTTokenContract<GetProviderRealUser<Provider>>>; | ||
|
||
/** | ||
* Alias for logout | ||
*/ | ||
revoke(): Promise<void>; | ||
|
||
/** | ||
* Login a user using their id | ||
*/ | ||
loginViaId( | ||
id: string | number, | ||
options?: JWTLoginOptions | ||
): Promise<JWTTokenContract<GetProviderRealUser<Provider>>>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"core": false, | ||
"license": "MIT", | ||
"services": [ | ||
"github-actions" | ||
], | ||
"minNodeVersion": "14.17.0", | ||
"probotApps": [ | ||
"stale" | ||
], | ||
"runGhActionsOnWindows": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import JwtProvider from './providers/JwtProvider' | ||
export default JwtProvider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require("@adonisjs/require-ts/build/register"); | ||
|
||
const { configure } = require("japa"); | ||
|
||
configure({ | ||
files: ["test/**/*.spec.ts"], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict' | ||
|
||
import { Exception } from '@adonisjs/core/build/standalone' | ||
|
||
export default class JwtAuthenticationException extends Exception { | ||
|
||
} |
Oops, something went wrong.