@gapi/auth 1.8.151 → 1.8.153

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.
Files changed (2) hide show
  1. package/README.md +87 -92
  2. package/package.json +3 -2
package/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # @Gapi authentication Module
2
2
 
3
- ##### For questions/issues you can write ticket [here](http://gitlab.youvolio.com/Stradivario/gapi-auth/issues)
3
+ ##### For questions/issues you can write ticket [here](https://github.com/Stradivario/gapi/issues)
4
+
4
5
  ##### This module is intended to be used with [rxdi](https://github.com/rxdi/core) or [gapi](https://github.com/Stradivario/gapi)
5
6
 
6
7
  ## Installation and basic examples:
8
+
7
9
  ##### To install this Gapi module, run:
8
10
 
9
11
  ```bash
@@ -13,22 +15,23 @@ $ npm install @gapi/auth --save
13
15
  ## Consuming @gapi/auth
14
16
 
15
17
  ##### Import inside AppModule or CoreModule
18
+
16
19
  ```typescript
17
- import { Module } from "@rxdi/core";
18
- import { AuthModule } from "@gapi/auth";
20
+ import { Module } from '@rxdi/core';
21
+ import { AuthModule } from '@gapi/auth';
19
22
 
20
23
  @Module({
21
- imports: [
22
- AuthModule.forRoot({
23
- algorithm: 'HS256',
24
- cert: 'dadada',
25
- cyper: {
26
- algorithm: 'dada',
27
- iv: '',
28
- privateKey: 'dadada'
29
- }
30
- }),
31
- ]
24
+ imports: [
25
+ AuthModule.forRoot({
26
+ algorithm: 'HS256',
27
+ cert: 'dadada',
28
+ cyper: {
29
+ algorithm: 'dada',
30
+ iv: '',
31
+ privateKey: 'dadada',
32
+ },
33
+ }),
34
+ ],
32
35
  })
33
36
  export class CoreModule {}
34
37
  ```
@@ -36,115 +39,107 @@ export class CoreModule {}
36
39
  ##### Create Auth Service and provide it
37
40
 
38
41
  ```typescript
39
-
40
42
  import { Service } from '@rxdi/core';
41
43
  import * as Boom from 'boom';
42
44
  import { AuthInterface, AuthInternalService, TokenData } from '@gapi/auth';
43
45
 
44
46
  export interface UserInfo {
45
- scope: ['ADMIN', 'USER'];
46
- type: 'ADMIN' | 'USER';
47
- iat: number;
47
+ scope: ['ADMIN', 'USER'];
48
+ type: 'ADMIN' | 'USER';
49
+ iat: number;
48
50
  }
49
51
 
50
52
  @Service()
51
53
  export class AuthService implements AuthInterface {
54
+ constructor(private authService: AuthInternalService) {}
52
55
 
53
- constructor(
54
- private authService: AuthInternalService
55
- ) { }
56
-
57
- onSubOperation(message, params, webSocket) {
58
- return params;
59
- }
60
-
61
- onSubConnection(connectionParams): TokenData {
62
- if (connectionParams.token) {
63
- return this.validateToken(connectionParams.token, 'Subscription');
64
- } else {
65
- throw Boom.unauthorized();
66
- }
67
- }
68
-
69
- validateToken(token: string, requestType: 'Query' | 'Subscription' = 'Query'): any {
70
- const user = <any>this.authService.verifyToken(token);
71
- user.type = user.scope[0];
72
- console.log(`${requestType} from: ${JSON.stringify(user)}`);
73
- if (user) {
74
- return user;
75
- } else {
76
- throw Boom.unauthorized();
77
- }
78
- }
79
-
80
- signJWTtoken(tokenData: TokenData): string {
81
- return this.authService.sign(tokenData);
82
- }
83
-
84
- issueJWTToken(tokenData: TokenData) {
85
- const jwtToken = this.authService.sign({
86
- email: '',
87
- id: 1,
88
- scope: ['ADMIN', 'USER']
89
- });
90
- return jwtToken;
91
- }
56
+ onSubOperation(message, params, webSocket) {
57
+ return params;
58
+ }
92
59
 
93
- verifyToken(token: string): TokenData {
94
- return this.authService.verifyToken(token);
60
+ onSubConnection(connectionParams): TokenData {
61
+ if (connectionParams.token) {
62
+ return this.validateToken(connectionParams.token, 'Subscription');
63
+ } else {
64
+ throw Boom.unauthorized();
95
65
  }
96
-
97
- decryptPassword(password: string): string {
98
- return this.authService.decrypt(password);
99
- }
100
-
101
- encryptPassword(password: string): string {
102
- return this.authService.encrypt(password);
66
+ }
67
+
68
+ validateToken(
69
+ token: string,
70
+ requestType: 'Query' | 'Subscription' = 'Query'
71
+ ): any {
72
+ const user = <any>this.authService.verifyToken(token);
73
+ user.type = user.scope[0];
74
+ console.log(`${requestType} from: ${JSON.stringify(user)}`);
75
+ if (user) {
76
+ return user;
77
+ } else {
78
+ throw Boom.unauthorized();
103
79
  }
104
-
80
+ }
81
+
82
+ signJWTtoken(tokenData: TokenData): string {
83
+ return this.authService.sign(tokenData);
84
+ }
85
+
86
+ issueJWTToken(tokenData: TokenData) {
87
+ const jwtToken = this.authService.sign({
88
+ email: '',
89
+ id: 1,
90
+ scope: ['ADMIN', 'USER'],
91
+ });
92
+ return jwtToken;
93
+ }
94
+
95
+ verifyToken(token: string): TokenData {
96
+ return this.authService.verifyToken(token);
97
+ }
98
+
99
+ decryptPassword(password: string): string {
100
+ return this.authService.decrypt(password);
101
+ }
102
+
103
+ encryptPassword(password: string): string {
104
+ return this.authService.encrypt(password);
105
+ }
105
106
  }
106
-
107
107
  ```
108
108
 
109
109
  ##### Provide this particular Auth Service to `authentication` parameter inside CoreModule.forRoot
110
110
 
111
111
  ```typescript
112
-
113
112
  import { CoreModule, Module } from '@gapi/core';
114
113
  import { AuthService } from './app/core/services/auth/auth.service';
115
114
  import { AuthModule } from '@gapi/auth';
116
115
  import { readFileSync } from 'fs';
117
116
 
118
117
  @Module({
119
- imports: [
120
- AuthModule.forRoot({
121
- algorithm: 'HS256',
122
- cert: readFileSync('./cert.key'),
123
- cyper: {
124
- algorithm: 'aes256',
125
- iv: 'Jkyt1H3FA8JK9L3B',
126
- privateKey: '8zTVzr3p53VC12jHV54rIYu2545x47lA'
127
- }
128
- }),
129
- CoreModule.forRoot({
130
- pubsub: {
131
- authentication: AuthService
132
- },
133
- graphql: {
134
- authentication: AuthService
135
- },
136
- }),
137
-
138
- ]
118
+ imports: [
119
+ AuthModule.forRoot({
120
+ algorithm: 'HS256',
121
+ cert: readFileSync('./cert.key'),
122
+ cyper: {
123
+ algorithm: 'aes256',
124
+ iv: 'Jkyt1H3FA8JK9L3B',
125
+ privateKey: '8zTVzr3p53VC12jHV54rIYu2545x47lA',
126
+ },
127
+ }),
128
+ CoreModule.forRoot({
129
+ pubsub: {
130
+ authentication: AuthService,
131
+ },
132
+ graphql: {
133
+ authentication: AuthService,
134
+ },
135
+ }),
136
+ ],
139
137
  })
140
138
  export class FrameworkImports {}
141
-
142
139
  ```
143
140
 
144
141
  Then Subscriptions, Mutations and Queries will be secured via single authentication method `validateToken` inside `AuthService`!
145
142
 
146
-
147
-
148
143
  TODO: Better documentation...
149
144
 
150
145
  Enjoy ! :)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gapi/auth",
3
- "version": "1.8.151",
3
+ "version": "1.8.153",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/Stradivario/gapi-auth"
@@ -10,6 +10,7 @@
10
10
  "patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist",
11
11
  "delete-dist": "rm -rf dist",
12
12
  "clean": "git clean -dxf",
13
+ "test": "echo test",
13
14
  "lint": "npx eslint . --ext .ts",
14
15
  "lint-fix": "npx eslint . --fix --ext .ts",
15
16
  "build": "rm -rf dist && tsc || true"
@@ -35,7 +36,7 @@
35
36
  "moment": "^2.22.2"
36
37
  },
37
38
  "devDependencies": {
38
- "@rxdi/core": "^0.7.173",
39
+ "@rxdi/core": "^0.7.182",
39
40
  "@types/node": "^13.11.1",
40
41
  "typescript": "^3.8.3"
41
42
  }