webledger-auth-plugin 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +9 -0
- package/README.md +14 -0
- package/build/adonis-typings/AuthService.d.ts +26 -0
- package/build/adonis-typings/AuthService.js +0 -0
- package/build/adonis-typings/index.d.ts +1 -0
- package/build/adonis-typings/index.js +1 -0
- package/build/instructions.js +17 -0
- package/build/instructions.md +8 -0
- package/build/providers/AuthServiceProvider.d.ts +8 -0
- package/build/providers/AuthServiceProvider.js +19 -0
- package/build/src/AuthService.d.ts +16 -0
- package/build/src/AuthService.js +81 -0
- package/build/templates/config/AuthService.txt +12 -0
- package/package.json +138 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2022 Chimezie Enyinnaya, contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare module '@ioc:AuthService' {
|
|
2
|
+
export interface AuthServiceI {
|
|
3
|
+
login(email: string, password: string): any;
|
|
4
|
+
signup(params: any): any;
|
|
5
|
+
getUser(uuid: string): any;
|
|
6
|
+
updateUser(uuid: string, params: any): any;
|
|
7
|
+
forgotPassword(email: string): any;
|
|
8
|
+
resendEmailVerification(email: string): any;
|
|
9
|
+
verifyPin(uuid: string, user_pin: string): any;
|
|
10
|
+
forgotPin(uuid: string, password: string, user_pin: string): any;
|
|
11
|
+
}
|
|
12
|
+
const authService: AuthServiceI;
|
|
13
|
+
export default authService;
|
|
14
|
+
export interface AuthServiceConfig {
|
|
15
|
+
host: string;
|
|
16
|
+
env: string;
|
|
17
|
+
type: string;
|
|
18
|
+
iss: string;
|
|
19
|
+
secret: string;
|
|
20
|
+
expiry?: string;
|
|
21
|
+
timeout?: number;
|
|
22
|
+
paths?: {
|
|
23
|
+
[x: string]: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference path="AuthService.d.ts" />
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference path="./AuthService.ts" />
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const path_1 = require("path");
|
|
4
|
+
function getStub(...relativePaths) {
|
|
5
|
+
return (0, path_1.join)(__dirname, 'templates', ...relativePaths);
|
|
6
|
+
}
|
|
7
|
+
function makeConfigFile(projectRoot, sink) {
|
|
8
|
+
const appProviderPath = (0, path_1.join)('config', 'authService.ts');
|
|
9
|
+
const template = new sink.files.MustacheFile(projectRoot, appProviderPath, getStub('config/AuthService.txt'));
|
|
10
|
+
template.overwrite = true;
|
|
11
|
+
template.commit();
|
|
12
|
+
sink.logger.action('create').succeeded(appProviderPath);
|
|
13
|
+
}
|
|
14
|
+
async function instructions(projectRoot, _, sink) {
|
|
15
|
+
makeConfigFile(projectRoot, sink);
|
|
16
|
+
}
|
|
17
|
+
exports.default = instructions;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Congratulations! You have configured `AuthService` package successfully. Make sure to add the following values inside `env.ts` file:
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
AUTH_HOST: Env.schema.string({ format: 'host' }),
|
|
5
|
+
AUTH_ENV: Env.schema.string(),
|
|
6
|
+
AUTH_PRODUCT_TYPE: Env.schema.string(),
|
|
7
|
+
AUTH_JWT_TOKEN: Env.schema.string(),
|
|
8
|
+
```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="@adonisjs/application/build/adonis-typings" />
|
|
2
|
+
import { ApplicationContract } from '@ioc:Adonis/Core/Application';
|
|
3
|
+
export default class AuthServiceProvider {
|
|
4
|
+
protected app: ApplicationContract;
|
|
5
|
+
static needsApplication: boolean;
|
|
6
|
+
constructor(app: ApplicationContract);
|
|
7
|
+
register(): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const AuthService_1 = __importDefault(require("../src/AuthService"));
|
|
7
|
+
class AuthServiceProvider {
|
|
8
|
+
constructor(app) {
|
|
9
|
+
this.app = app;
|
|
10
|
+
}
|
|
11
|
+
register() {
|
|
12
|
+
this.app.container.singleton('AuthService', () => {
|
|
13
|
+
const config = this.app.container.use('Adonis/Core/Config');
|
|
14
|
+
return new AuthService_1.default(config.get('authService'));
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = AuthServiceProvider;
|
|
19
|
+
AuthServiceProvider.needsApplication = true;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AuthServiceConfig, AuthServiceI } from '@ioc:AuthService';
|
|
2
|
+
export default class AuthService implements AuthServiceI {
|
|
3
|
+
private config;
|
|
4
|
+
private client;
|
|
5
|
+
private paths;
|
|
6
|
+
constructor(config: AuthServiceConfig);
|
|
7
|
+
private setAuthToken;
|
|
8
|
+
login(email: string, password: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
9
|
+
signup(params: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
10
|
+
getUser(uuid: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
11
|
+
updateUser(uuid: string, params: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
12
|
+
forgotPassword(email: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
13
|
+
resendEmailVerification(email: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
14
|
+
verifyPin(uuid: string, user_pin: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
15
|
+
forgotPin(uuid: string, password: string, user_pin: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
const jsonwebtoken_1 = require("jsonwebtoken");
|
|
8
|
+
class AuthService {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
this.paths = {
|
|
12
|
+
login: '/api/login',
|
|
13
|
+
signup: '/api/signup',
|
|
14
|
+
get_user: '/api/users',
|
|
15
|
+
update_user: '/api/users',
|
|
16
|
+
forgot_password: '/api/forgot_password',
|
|
17
|
+
resend_email_verification: '/api/resend_verify_email',
|
|
18
|
+
verify_pin: '/api/users',
|
|
19
|
+
forgot_pin: '/api/users',
|
|
20
|
+
};
|
|
21
|
+
this.client = axios_1.default.create({ baseURL: config.host });
|
|
22
|
+
this.client.defaults.timeout = config.timeout || 30000; // default is 30seconds
|
|
23
|
+
const headers = {
|
|
24
|
+
'Content-Type': 'application/json',
|
|
25
|
+
'x-auth-env': config.env,
|
|
26
|
+
'x-product-type': config.type,
|
|
27
|
+
};
|
|
28
|
+
for (const key in headers) {
|
|
29
|
+
this.client.defaults.headers.common[key] = headers[key];
|
|
30
|
+
}
|
|
31
|
+
this.paths = { ...this.paths, ...config.paths };
|
|
32
|
+
}
|
|
33
|
+
setAuthToken(sub) {
|
|
34
|
+
const payload = { env: this.config.env, type: this.config.type, iss: this.config.iss, sub };
|
|
35
|
+
const jwtAuthToken = (0, jsonwebtoken_1.sign)(payload, this.config.secret, {
|
|
36
|
+
expiresIn: this.config.expiry || '1m',
|
|
37
|
+
});
|
|
38
|
+
this.client.defaults.headers.common['Authorization'] = `Bearer ${jwtAuthToken}`;
|
|
39
|
+
}
|
|
40
|
+
login(email, password) {
|
|
41
|
+
const subject = 'login';
|
|
42
|
+
this.setAuthToken(subject);
|
|
43
|
+
return this.client.post(this.paths[subject], { email, password });
|
|
44
|
+
}
|
|
45
|
+
signup(params) {
|
|
46
|
+
const subject = 'signup';
|
|
47
|
+
this.setAuthToken(subject);
|
|
48
|
+
return this.client.post(this.paths[subject], params);
|
|
49
|
+
}
|
|
50
|
+
getUser(uuid) {
|
|
51
|
+
const subject = 'get_user';
|
|
52
|
+
this.setAuthToken(subject);
|
|
53
|
+
return this.client.get(`${this.paths[subject]}/${uuid}`);
|
|
54
|
+
}
|
|
55
|
+
updateUser(uuid, params) {
|
|
56
|
+
const subject = 'update_user';
|
|
57
|
+
this.setAuthToken(subject);
|
|
58
|
+
return this.client.put(`${this.paths[subject]}/${uuid}`, params);
|
|
59
|
+
}
|
|
60
|
+
forgotPassword(email) {
|
|
61
|
+
const subject = 'forgot_password';
|
|
62
|
+
this.setAuthToken(subject);
|
|
63
|
+
return this.client.post(this.paths[subject], { email });
|
|
64
|
+
}
|
|
65
|
+
resendEmailVerification(email) {
|
|
66
|
+
const subject = 'resend_email_verification';
|
|
67
|
+
this.setAuthToken(subject);
|
|
68
|
+
return this.client.post(this.paths[subject], { email });
|
|
69
|
+
}
|
|
70
|
+
verifyPin(uuid, user_pin) {
|
|
71
|
+
const subject = 'verify_pin';
|
|
72
|
+
this.setAuthToken(subject);
|
|
73
|
+
return this.client.post(`${this.paths[subject]}/${uuid}/verify_pin`, { user_pin });
|
|
74
|
+
}
|
|
75
|
+
forgotPin(uuid, password, user_pin) {
|
|
76
|
+
const subject = 'forgot_pin';
|
|
77
|
+
this.setAuthToken(subject);
|
|
78
|
+
return this.client.post(`${this.paths[subject]}/${uuid}/forgot_pin`, { password, user_pin });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.default = AuthService;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AuthServiceConfig } from '@ioc:AuthService'
|
|
2
|
+
import Env from '@ioc:Adonis/Core/Env'
|
|
3
|
+
|
|
4
|
+
const authServiceConfig: AuthServiceConfig = {
|
|
5
|
+
host: Env.get('AUTH_HOST'),
|
|
6
|
+
env: Env.get('AUTH_ENV'),
|
|
7
|
+
type: Env.get('AUTH_PRODUCT_TYPE'),
|
|
8
|
+
iss: Env.get('BASE_URL'),
|
|
9
|
+
secret: Env.get('AUTH_JWT_TOKEN'),
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default authServiceConfig
|
package/package.json
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "webledger-auth-plugin",
|
|
3
|
+
"version": "1.0.8",
|
|
4
|
+
"description": "webledger auth service AdonisJS 5 login plugin",
|
|
5
|
+
"main": "build/providers/AuthServiceProvider.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"mrm": "mrm --preset=@adonisjs/mrm-preset",
|
|
8
|
+
"pretest": "npm run lint",
|
|
9
|
+
"clean": "del-cli build",
|
|
10
|
+
"copyfiles": "copyfiles \"templates/**/*.txt\" \"instructions.md\" build",
|
|
11
|
+
"compile": "npm run lint && npm run clean && tsc && npm run copyfiles",
|
|
12
|
+
"build": "npm run compile",
|
|
13
|
+
"prepublishOnly": "npm run build",
|
|
14
|
+
"lint": "eslint . --ext=.ts",
|
|
15
|
+
"format": "prettier --write .",
|
|
16
|
+
"commit": "git-cz",
|
|
17
|
+
"release": "np --message=\"chore(release): %s\"",
|
|
18
|
+
"version": "npm run build",
|
|
19
|
+
"sync-labels": "github-label-sync --labels ./node_modules/@adonisjs/mrm-preset/gh-labels.json divamtech/webledger-auth-plugin"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/divamtech/webledger-auth-plugin.git"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/divamtech/webledger-auth-plugin#readme",
|
|
26
|
+
"keywords": [
|
|
27
|
+
"adonisjs",
|
|
28
|
+
"adonis"
|
|
29
|
+
],
|
|
30
|
+
"author": "Gaurav D. Sharma",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/divamtech/webledger-auth-plugin/issues"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@adonisjs/core": "^5.7.6",
|
|
37
|
+
"@adonisjs/mrm-preset": "^5.0.3",
|
|
38
|
+
"@adonisjs/require-ts": "^2.0.12",
|
|
39
|
+
"@adonisjs/sink": "^5.4.0",
|
|
40
|
+
"@types/node": "^18.0.3",
|
|
41
|
+
"commitizen": "^4.2.4",
|
|
42
|
+
"copyfiles": "^2.4.1",
|
|
43
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
44
|
+
"del-cli": "^4.0.1",
|
|
45
|
+
"eslint": "^8.19.0",
|
|
46
|
+
"eslint-config-prettier": "^8.5.0",
|
|
47
|
+
"eslint-plugin-adonis": "^2.1.0",
|
|
48
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
49
|
+
"github-label-sync": "^2.2.0",
|
|
50
|
+
"husky": "^8.0.1",
|
|
51
|
+
"mrm": "^4.0.0",
|
|
52
|
+
"np": "^7.6.2",
|
|
53
|
+
"prettier": "^2.7.1",
|
|
54
|
+
"typescript": "^4.7.4"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"@adonisjs/core": "^5.7.6"
|
|
58
|
+
},
|
|
59
|
+
"mrmConfig": {
|
|
60
|
+
"core": false,
|
|
61
|
+
"license": "MIT",
|
|
62
|
+
"services": [],
|
|
63
|
+
"minNodeVersion": "16.13.1",
|
|
64
|
+
"probotApps": []
|
|
65
|
+
},
|
|
66
|
+
"types": "build/adonis-typings/index.d.ts",
|
|
67
|
+
"files": [
|
|
68
|
+
"build/adonis-typings",
|
|
69
|
+
"build/src",
|
|
70
|
+
"build/providers",
|
|
71
|
+
"build/templates",
|
|
72
|
+
"build/instructions.js",
|
|
73
|
+
"build/instructions.md"
|
|
74
|
+
],
|
|
75
|
+
"eslintConfig": {
|
|
76
|
+
"extends": [
|
|
77
|
+
"plugin:adonis/typescriptPackage",
|
|
78
|
+
"prettier"
|
|
79
|
+
],
|
|
80
|
+
"plugins": [
|
|
81
|
+
"prettier"
|
|
82
|
+
],
|
|
83
|
+
"rules": {
|
|
84
|
+
"prettier/prettier": [
|
|
85
|
+
"error",
|
|
86
|
+
{
|
|
87
|
+
"endOfLine": "auto"
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"eslintIgnore": [
|
|
93
|
+
"build"
|
|
94
|
+
],
|
|
95
|
+
"prettier": {
|
|
96
|
+
"trailingComma": "es5",
|
|
97
|
+
"semi": false,
|
|
98
|
+
"singleQuote": true,
|
|
99
|
+
"useTabs": false,
|
|
100
|
+
"quoteProps": "consistent",
|
|
101
|
+
"bracketSpacing": true,
|
|
102
|
+
"arrowParens": "always",
|
|
103
|
+
"printWidth": 100
|
|
104
|
+
},
|
|
105
|
+
"config": {
|
|
106
|
+
"commitizen": {
|
|
107
|
+
"path": "cz-conventional-changelog"
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
"np": {
|
|
111
|
+
"contents": ".",
|
|
112
|
+
"anyBranch": false
|
|
113
|
+
},
|
|
114
|
+
"publishConfig": {
|
|
115
|
+
"access": "public"
|
|
116
|
+
},
|
|
117
|
+
"adonisjs": {
|
|
118
|
+
"instructions": "./build/instructions.js",
|
|
119
|
+
"instructionsMd": "./build/instructions.md",
|
|
120
|
+
"providers": [
|
|
121
|
+
"webledger-auth-plugin"
|
|
122
|
+
],
|
|
123
|
+
"types": "webledger-auth-plugin",
|
|
124
|
+
"templates": {
|
|
125
|
+
"basePath": "./build/templates",
|
|
126
|
+
"config": [
|
|
127
|
+
{
|
|
128
|
+
"src": "config/AuthService.txt",
|
|
129
|
+
"dest": "authService"
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
"dependencies": {
|
|
135
|
+
"axios": "^1.7.5",
|
|
136
|
+
"jsonwebtoken": "^9.0.2"
|
|
137
|
+
}
|
|
138
|
+
}
|