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

Commit

Permalink
import
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgalbu committed Oct 11, 2021
0 parents commit 741a3b5
Show file tree
Hide file tree
Showing 18 changed files with 15,099 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
17 changes: 17 additions & 0 deletions .eslintrc.json
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"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
8 changes: 8 additions & 0 deletions .prettierignore
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
188 changes: 188 additions & 0 deletions adonis-typings/index.ts
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>>>;
}
}
12 changes: 12 additions & 0 deletions config.json
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
}
2 changes: 2 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import JwtProvider from './providers/JwtProvider'
export default JwtProvider
7 changes: 7 additions & 0 deletions japaFile.js
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"],
});
7 changes: 7 additions & 0 deletions lib/Exceptions/JwtAuthenticationException.ts
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 {

}
Loading

0 comments on commit 741a3b5

Please sign in to comment.