@vcita/oauth-client-nestjs 1.17.4 → 1.18.3
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/CHANGELOG.md +58 -0
- package/README.md +164 -23
- package/dist/oauth/controllers/oauth.controller.js +2 -2
- package/dist/oauth/controllers/oauth.controller.js.map +1 -1
- package/dist/oauth/enums/auth.enum.d.ts +1 -0
- package/dist/oauth/enums/auth.enum.js +1 -0
- package/dist/oauth/enums/auth.enum.js.map +1 -1
- package/dist/oauth/interfaces/oauth.interface.d.ts +4 -1
- package/dist/oauth/middleware/auth.middleware.d.ts +1 -1
- package/dist/oauth/middleware/auth.middleware.js +25 -13
- package/dist/oauth/middleware/auth.middleware.js.map +1 -1
- package/dist/oauth/middleware/oauth-authorization.middleware.js +2 -2
- package/dist/oauth/middleware/oauth-authorization.middleware.js.map +1 -1
- package/dist/oauth/oauth.module.js +29 -3
- package/dist/oauth/oauth.module.js.map +1 -1
- package/dist/oauth/repositories/actor.entity.d.ts +4 -2
- package/dist/oauth/repositories/actor.entity.js +13 -11
- package/dist/oauth/repositories/actor.entity.js.map +1 -1
- package/dist/oauth/repositories/oauth.repository.js +2 -2
- package/dist/oauth/repositories/oauth.repository.js.map +1 -1
- package/dist/oauth/services/infra-proxy.service.d.ts +10 -19
- package/dist/oauth/services/infra-proxy.service.js +25 -23
- package/dist/oauth/services/infra-proxy.service.js.map +1 -1
- package/dist/oauth/services/internal-proxy.service.d.ts +12 -5
- package/dist/oauth/services/internal-proxy.service.js +101 -54
- package/dist/oauth/services/internal-proxy.service.js.map +1 -1
- package/dist/oauth/services/oauth.service.js +4 -4
- package/dist/oauth/services/oauth.service.js.map +1 -1
- package/dist/oauth/utils/oauth.utils.js +20 -1
- package/dist/oauth/utils/oauth.utils.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,31 +6,89 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## Unreleased
|
|
8
8
|
|
|
9
|
+
|
|
10
|
+
___
|
|
11
|
+
# Releases
|
|
12
|
+
## 1.18.3 (2022-01-10)
|
|
13
|
+
### Fixed
|
|
14
|
+
- Fetching service token through IdP (Core) and not API-GW
|
|
15
|
+
- `UrlBuilder` overload definitions improvement
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## 1.18.2 (2021-12-29)
|
|
19
|
+
### Changed
|
|
20
|
+
- No longer relying on `DeployedEnvironment` enum
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## 1.18.1 (2021-12-27)
|
|
24
|
+
### Fixed
|
|
25
|
+
- Getting token at oauth grant flow would go to `API_GW_SERVER` which does now expose such APIS. (That would get 404 error when in need to generate token AND API_GW_SERVER env var would point to the actual API-GW (and not falsely `Core`))
|
|
26
|
+
Now properly goes to our `Authorization Server` which is Core.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## 1.18.0 (2021-12-21)
|
|
30
|
+
### Fixed
|
|
31
|
+
- Redis connection error.
|
|
32
|
+
Redis connection arguments now fetched from proper place via configurations.
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
- External packages imports refactor. Now importing performed from the global package.
|
|
36
|
+
- Redis keys are now pre-fixed with app name supporting usage of different services on same redis. (even tho that's a bad practice and should be fixed!)
|
|
37
|
+
- Formalizing saved keys to redis complying with `bull` package conventions.
|
|
38
|
+
- Some code optimizations and refactoring.
|
|
39
|
+
|
|
40
|
+
### Added
|
|
41
|
+
- `ActorEntity` now holds the original identification from which it was created for future features.
|
|
42
|
+
- Ability to make requests on behalf of a staff member (to act as that staff member).
|
|
43
|
+
- Authentication middleware now supports simplified mode for development!
|
|
44
|
+
This feature allows rapid developing without the need to use the entire authentication mechanisms.
|
|
45
|
+
Now developers may simply pass `Bearer <JSON.stringify-output-of-actor-entity>` instead of a real JWT token.
|
|
46
|
+
- `BelongsEntity` now get itself if it is the type searched
|
|
47
|
+
- `ApplicationConfig.excludesOauth` now accepts `string[] | RegExp[]`.
|
|
48
|
+
`RegExp[]` is the proper and intended way to exclude paths `string[]` will receive deprecation warnings.
|
|
49
|
+
- Excluding paths now gets a warning notifying security issues it might introduce.
|
|
50
|
+
- Autoformatting routes in local development based on runtime environment (docker or local).
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
## 1.17.4 (2021-12-15)
|
|
54
|
+
### Changed
|
|
55
|
+
- Query params now overtake cookies to meet 3rd party cookies problem. also see: https://myvcita.atlassian.net/browse/VCITA-22147
|
|
56
|
+
|
|
57
|
+
### Added
|
|
58
|
+
- Support of `brand_host` being transferred to applications. see also: https://myvcita.atlassian.net/browse/VCITA-22070
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
9
62
|
## 1.17.3 (2021-12-06)
|
|
10
63
|
### Fixed
|
|
11
64
|
- `ActorEntity` class `getActingAs` now also returns the direct actor if he's not acting as anyone else
|
|
12
65
|
|
|
66
|
+
|
|
13
67
|
## 1.17.2 (2021-12-05)
|
|
14
68
|
### Added
|
|
15
69
|
- Added the ability to mock the `AuthorizationPayloadEntity` object for testing purposes
|
|
16
70
|
Added the option to mock the oauth process for e2e tests by adding to the `setup.ts` file
|
|
17
71
|
this mockTesters `[new OauthMocker()]`
|
|
18
72
|
|
|
73
|
+
|
|
19
74
|
## 1.17.1 (2021-12-02)
|
|
20
75
|
### Fixed
|
|
21
76
|
- `AuthorizationPayloadEntity` now properly exported.
|
|
22
77
|
|
|
78
|
+
|
|
23
79
|
## 1.17.0 (2021-12-02)
|
|
24
80
|
### Added
|
|
25
81
|
- Support for `belongs` claim
|
|
26
82
|
- New optional attribute for `ActorEntity` class, `belongTo` with methods for fetching specific entity types.
|
|
27
83
|
This property holds the information about the relations of the acting entity (the one who initiated the request)
|
|
28
84
|
|
|
85
|
+
|
|
29
86
|
## 1.16.1 (2021-11-30)
|
|
30
87
|
### Changes
|
|
31
88
|
- Auth middleware now verify authentication only with cookies (and does not compare it to query params).
|
|
32
89
|
_Note:_ That flow applies to application only
|
|
33
90
|
|
|
91
|
+
|
|
34
92
|
## 1.16.0 (2021-11-28)
|
|
35
93
|
### Changes
|
|
36
94
|
- AuthorizationPayloadEntity constructor has been changed (using new syntax)
|
package/README.md
CHANGED
|
@@ -1,32 +1,173 @@
|
|
|
1
|
-
# oauth-client-nestjs
|
|
2
|
-
This package includes client oauth authentication module based upon
|
|
1
|
+
# **oauth-client-nestjs**
|
|
2
|
+
This package includes client oauth authentication module based upon NestJS framework.
|
|
3
3
|
This package includes vcita authentication, and can also interact with additional providers.
|
|
4
4
|
|
|
5
|
+
## Content
|
|
6
|
+
Using this package you will be able to:
|
|
7
|
+
1. Authenticate incoming requests
|
|
8
|
+
* Internal services: with the internal token generated by the `IdP` (Identity Provider)
|
|
9
|
+
* External services (apps):
|
|
10
|
+
1. Using the Oauth grant flow (authorizing the service to make changes for logged-in user)
|
|
11
|
+
2. Using cookies for stateful keeping the user information
|
|
12
|
+
> :warning: Usage of cookies will be deprecated.
|
|
13
|
+
|
|
14
|
+
2. Object allowing to make requests to vCita's services (AKA *consuming Platform API's*) safely through the API-GW
|
|
15
|
+
1. Internal services
|
|
16
|
+
2. External services
|
|
17
|
+
|
|
18
|
+
3. Utilities for rapid testing and developing
|
|
19
|
+
1. Authentication mocking on `testing` environments
|
|
20
|
+
2. Simplified authentication mechanism for `development` environments
|
|
21
|
+
|
|
22
|
+
## Glossary
|
|
23
|
+
* **Oauth grant flow:**
|
|
24
|
+
A series of steps defined by the [Oauth 2.0](https://nordicapis.com/api-security-oauth-openid-connect-depth/) protocol allowing a user to give an external application access to a resource he owns in a different application.
|
|
25
|
+
<br/>
|
|
26
|
+
* **Platform API(s):**
|
|
27
|
+
APIs exposed by the API-GW and are consumed by both vCita's hosted apps/services and 3rd party apps/services.
|
|
28
|
+
<br/>
|
|
29
|
+
* **Internal Service:**
|
|
30
|
+
A service which is part of the vCita's eco-system and exposes _Platform APIs_ via the API-GW.
|
|
31
|
+
<br/>
|
|
32
|
+
* **Application:**
|
|
33
|
+
A service which not part of the vCita eco-system.
|
|
34
|
+
* It may be hosted by vCita or by a 3rd party host.
|
|
35
|
+
* It may be created by vCita or by a 3rd party developer.
|
|
36
|
+
* It may have frontend which could hosted in vCita's SaaS website.
|
|
37
|
+
* It may consume _Platform APIs_.
|
|
38
|
+
* Users **must** authorize apps to preform actions on their behalf using the _Oauth-grant-flow_.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
5
42
|
## Installation
|
|
6
|
-
|
|
7
|
-
|
|
43
|
+
1. Install this package using npm in your NestJS app.
|
|
44
|
+
```sh
|
|
45
|
+
npm install @vcita/oauth-client-nestjs
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
2. You _**must**_ have these env variables available on your application (accessible through `process.env.<env-var>`):
|
|
49
|
+
You may do so by adding them to your `.env`.
|
|
50
|
+
> :bulb: When opening a project from template, you will only need to add values or make sure they are filled correctly
|
|
51
|
+
<br/>
|
|
52
|
+
|
|
53
|
+
> :lock_with_ink_pen: When deploying your project, some values will be overridden with deployment secrets (this is good)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
| Env var | Explanation | Development Value | Deployment Overridden |
|
|
57
|
+
|--------------------|------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|---------------------|
|
|
58
|
+
| OAUTH_CLIENT_ID | String representing `oauth application` uid | Obtained when registering app | Yes |
|
|
59
|
+
| OAUTH_CLIENT_SECRET | String representing `oauth application` secret | Obtained when registering app | Yes |
|
|
60
|
+
| OAUTH_SERVER | URL of frontend _oauth-grant-flow_ start (frontage). | http://localhost:7200/app/oauth/authorize | Yes |
|
|
61
|
+
| OAUTH_REDIRECT_URI | URL of redirection in a _oauth-grant-flow_ | Location of your service in development. <br>Example: http://localhost:47745 | Yes |
|
|
62
|
+
| API_GW_SERVER | URL of vCita's API-GW | Will be explained in section | Yes |
|
|
63
|
+
| AUTHORIZATION_SERVER | URL of vCita's Authorization Server | http://localhost:7100 | Yes |
|
|
64
|
+
| CUSTOM_ENTITIES | Array of location(s) of additional entities | `["/home/node_modules/@vcita/oauth-client-nestjs/dist/oauth/**/*.entity.js","./node_modules/@vcita/oauth-client-nestjs/dist/oauth/**/*.entity.js"]` | No |
|
|
65
|
+
|
|
66
|
+
## Migration
|
|
67
|
+
After the package installation, you **must** generate and run a new migration for oauth module - [migration docs](https://typeorm.io/#/migrations/generating-migrations)
|
|
68
|
+
|
|
69
|
+
## Usage
|
|
70
|
+
To use the package content we must first import the `OauthModule` into our root module (`AppModule` for most cases).
|
|
71
|
+
This is a [dynamic module](https://docs.nestjs.com/fundamentals/dynamic-modules), use it you should call register method and supply object complying with `ApplicationConfig` interface.
|
|
72
|
+
```javascript
|
|
73
|
+
OauthModule.register({ mainRoute: '' })
|
|
74
|
+
```
|
|
75
|
+
**mainRoute** - the default route to redirect to after OAuth completed.
|
|
76
|
+
> :warning: **Note!**
|
|
77
|
+
> The interface will be changed on version 2.0.0
|
|
78
|
+
|
|
79
|
+
### Consuming Platform APIs
|
|
80
|
+
#### Internal Services
|
|
81
|
+
As an _Internal Service_ you have 2 options to consume a _Platform API_:
|
|
82
|
+
1. Make a request on behalf of the service itself.
|
|
83
|
+
Example: The service needs to update some other service with it's current state.
|
|
84
|
+
<br/>
|
|
85
|
+
2. Make a request on behalf of some user (staff, client etc...).
|
|
86
|
+
Example: The service needs to change the calendar of the user, yet Calendars are the responsibility of a different service.
|
|
87
|
+
|
|
88
|
+
To consume _Platform APIs_ you must use the `InternalProxyService` object - a provider exported by the `OauthModule`.
|
|
89
|
+
To use the provider you must declare it as a dependency of the consuming class so NestJS would inject it at initialization.
|
|
90
|
+
```typescript
|
|
91
|
+
@Processor('channels')
|
|
92
|
+
export class ChannelsProcessor extends BaseProcessor { // consuming class
|
|
93
|
+
constructor(
|
|
94
|
+
private readonly internalProxy: InternalProxyService, // NestJS will inject the `InternalProxyService` fatory object
|
|
95
|
+
) {
|
|
96
|
+
super();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
> :bulb: Now `ChannelProcessor` object is automatically injected with `InternalProxyService` intance when NestJS framework initializes.
|
|
101
|
+
|
|
102
|
+
This object exposes methods for making an HTTP requests: getRequest, postRequst, putRequest, deleteRequest for proper usage.
|
|
103
|
+
Those methods can be used for both _Platform API_ consuming by simply giving the last argument `actingAs`.
|
|
104
|
+
Examples:
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
// Request example fitting option 1
|
|
108
|
+
import { ActorType } from "@vcita/oauth-client-nestjs";
|
|
109
|
+
|
|
110
|
+
this.internalProxy.getRequest<ResponseDataType>(
|
|
111
|
+
'platform/v1/test',
|
|
112
|
+
6,
|
|
113
|
+
{ query_param: 'some value' }
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
/* Reuest example fitting option 2
|
|
118
|
+
* Note this invocation contains another argument to the same method!
|
|
119
|
+
* This argument is the `actingAs` argument
|
|
120
|
+
*/
|
|
121
|
+
this.internalProxy.getRequest<ResponseDataType>(
|
|
122
|
+
'platform/v1/test',
|
|
123
|
+
6,
|
|
124
|
+
{ query_param: 'some value' },
|
|
125
|
+
actor.getActingAs(ActorType.STAFF)
|
|
126
|
+
)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
> :bulb: Each HTTP request method have a different interface, but they all allow the `actingAs` optional argument.
|
|
130
|
+
> Also notice that without the optional argument given, the **default behaviour is of option 1!**
|
|
131
|
+
|
|
132
|
+
#### Applications
|
|
133
|
+
> :warning: **Note!**
|
|
134
|
+
> This section is not final and might be subject to various changes in the next version.
|
|
135
|
+
|
|
136
|
+
As an _application_ you must use the `OAuthHttpAppService`.
|
|
137
|
+
To obtain this object you must declare it's _factory object_ `OauthHttpService` as a dependency of the consumer.
|
|
138
|
+
`OauthHttpService` is a provider exported by the `OauthModule`.
|
|
139
|
+
Example:
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
@Injectable()
|
|
143
|
+
export class ConnectorService { // Consumer class
|
|
144
|
+
private vcitaOauthHttpService: OAuthHttpAppService;
|
|
8
145
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- CUSTOM_ENTITIES=["/home/node_modules/@vcita/oauth-client-nestjs/dist/oauth/**/*.entity.{ts,js}"]
|
|
146
|
+
constructor(
|
|
147
|
+
httpClient: OauthHttpService, // NestJS will inject the `OAuthHttpAppService` fatory object
|
|
148
|
+
) {
|
|
149
|
+
this.vcitaOauthHttpService = httpClient.getInstance('vcita'); // Getting the proper instance to consume vCita's Platform APIs
|
|
150
|
+
}
|
|
15
151
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
mainRoute - the default route to redirect to after OAuth completed.
|
|
152
|
+
async doWork(staffUid: string, path: string) {
|
|
153
|
+
const platformApiAns = await this.vcitaOauthHttpService.getRequest(
|
|
154
|
+
staffUid,
|
|
155
|
+
path,
|
|
156
|
+
);
|
|
22
157
|
|
|
23
|
-
|
|
24
|
-
|
|
158
|
+
return 'Answer from Platform Api is: ' + platformApiAns.toString();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
```
|
|
25
162
|
|
|
26
|
-
|
|
27
|
-
|
|
163
|
+
### Internal Services Consuming External APIs
|
|
164
|
+
There are cases where an internal service will need to call some external api.
|
|
165
|
+
We provide a way for the external api to authenticate that some arbitrary incoming API request was made by vCita's eco-system (one of vCita's internal services to be exact).
|
|
166
|
+
Example use case:
|
|
167
|
+
1. vCita needs to inform external application A about some operation that happened (a webhook)
|
|
168
|
+
2. A receives an API request.
|
|
169
|
+
How will A know that the incoming request was made by vCita?
|
|
28
170
|
|
|
171
|
+
Some external application/service might not care, but those who do care we offer a mechanism for authenticating.
|
|
29
172
|
|
|
30
|
-
|
|
31
|
-
- oauthConfig: a config object that includes oauth config for another provider, and target endpoint for vcita oauth - if different from 'vcita'
|
|
32
|
-
- logger: a logger for the app.
|
|
173
|
+
TBD
|
|
@@ -17,14 +17,14 @@ exports.OauthController = void 0;
|
|
|
17
17
|
const common_1 = require("@nestjs/common");
|
|
18
18
|
const config_1 = require("@nestjs/config");
|
|
19
19
|
const swagger_1 = require("@nestjs/swagger");
|
|
20
|
-
const
|
|
20
|
+
const infra_nestjs_1 = require("@vcita/infra-nestjs");
|
|
21
21
|
const oauth_service_1 = require("../services/oauth.service");
|
|
22
22
|
const auth_enum_1 = require("../enums/auth.enum");
|
|
23
23
|
let OauthController = OauthController_1 = class OauthController {
|
|
24
24
|
constructor(configService, connectService) {
|
|
25
25
|
this.configService = configService;
|
|
26
26
|
this.connectService = connectService;
|
|
27
|
-
this.logger = new
|
|
27
|
+
this.logger = new infra_nestjs_1.InfraLoggerService(OauthController_1.name);
|
|
28
28
|
}
|
|
29
29
|
async generateOauthToken(code, state, request, response) {
|
|
30
30
|
const isSecure = this.configService.get('ENVIRONMENT') !== 'development';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.controller.js","sourceRoot":"","sources":["../../../src/oauth/controllers/oauth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAkE;AAClE,2CAA+C;AAC/C,6CAA0C;AAC1C,
|
|
1
|
+
{"version":3,"file":"oauth.controller.js","sourceRoot":"","sources":["../../../src/oauth/controllers/oauth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAkE;AAClE,2CAA+C;AAC/C,6CAA0C;AAC1C,sDAAyD;AAEzD,6DAAyD;AAKzD,kDAAgE;AAIhE,IAAa,eAAe,uBAA5B,MAAa,eAAe;IAE1B,YACU,aAA+C,EACtC,cAA4B;QADrC,kBAAa,GAAb,aAAa,CAAkC;QACtC,mBAAc,GAAd,cAAc,CAAc;QAH9B,WAAM,GAAG,IAAI,iCAAkB,CAAC,iBAAe,CAAC,IAAI,CAAC,CAAC;IAIpE,CAAC;IAGJ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,IAAI,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,UAAU,EAAE;gBAC3B,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;aACjD;SACF;QAGD,MAAM,cAAc,GAAG;YACrB,MAAM,EAAE,IAAI;YACZ,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,IAAI,QAAQ,EAAE;YACZ,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE;gBAC5B,MAAM,EAAE,IAAI;gBACZ,QAAQ,EAAE,MAAM;aACjB,CAAC,CAAC;SACJ;QAED,QAAQ,CAAC,MAAM,CAAC,GAAG,QAAQ,GAAG,sBAAU,EAAE,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC;QACxE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sCAAsC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;QAC5E,OAAO,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;CACF,CAAA;AAnDC;IADC,IAAA,YAAG,EAAC,EAAE,CAAC;IAEL,WAAA,IAAA,cAAK,EAAC,MAAM,CAAC,CAAA;IACb,WAAA,IAAA,cAAK,EAAC,OAAO,CAAC,CAAA;IACd,WAAA,IAAA,YAAG,GAAE,CAAA;IACL,WAAA,IAAA,YAAG,GAAE,CAAA;;;;yDA8CP;AA1DU,eAAe;IAF3B,IAAA,iBAAO,EAAC,OAAO,CAAC;IAChB,IAAA,mBAAU,EAAC,OAAO,CAAC;qCAIO,sBAAa;QACH,4BAAY;GAJpC,eAAe,CA2D3B;AA3DY,0CAAe"}
|
|
@@ -25,6 +25,7 @@ var ResponseTypes;
|
|
|
25
25
|
var InfraAuthentication;
|
|
26
26
|
(function (InfraAuthentication) {
|
|
27
27
|
InfraAuthentication["InboundHeaderName"] = "X-AUTHORIZATION";
|
|
28
|
+
InfraAuthentication["INBOUND_HEADER_NAME_FALLBACK"] = "Authorization";
|
|
28
29
|
InfraAuthentication["OutboundHeaderName"] = "Authorization";
|
|
29
30
|
InfraAuthentication["Algorithm"] = "RS512";
|
|
30
31
|
})(InfraAuthentication = exports.InfraAuthentication || (exports.InfraAuthentication = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.enum.js","sourceRoot":"","sources":["../../../src/oauth/enums/auth.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAEX;AAFD,WAAY,UAAU;IACpB,+BAAiB,CAAA;AACnB,CAAC,EAFW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAErB;AAED,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,0CAA6B,CAAA;IAC7B,sDAAyC,CAAA;AAC3C,CAAC,EAHW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAGpB;AACD,IAAY,MAEX;AAFD,WAAY,MAAM;IAChB,2BAAiB,CAAA;AACnB,CAAC,EAFW,MAAM,GAAN,cAAM,KAAN,cAAM,QAEjB;AAED,IAAY,UAEX;AAFD,WAAY,UAAU;IACpB,sDAAwC,CAAA;AAC1C,CAAC,EAFW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAErB;AAED,IAAY,aAEX;AAFD,WAAY,aAAa;IACvB,8BAAa,CAAA;AACf,CAAC,EAFW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAExB;AAED,IAAY,
|
|
1
|
+
{"version":3,"file":"auth.enum.js","sourceRoot":"","sources":["../../../src/oauth/enums/auth.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAEX;AAFD,WAAY,UAAU;IACpB,+BAAiB,CAAA;AACnB,CAAC,EAFW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAErB;AAED,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,0CAA6B,CAAA;IAC7B,sDAAyC,CAAA;AAC3C,CAAC,EAHW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAGpB;AACD,IAAY,MAEX;AAFD,WAAY,MAAM;IAChB,2BAAiB,CAAA;AACnB,CAAC,EAFW,MAAM,GAAN,cAAM,KAAN,cAAM,QAEjB;AAED,IAAY,UAEX;AAFD,WAAY,UAAU;IACpB,sDAAwC,CAAA;AAC1C,CAAC,EAFW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAErB;AAED,IAAY,aAEX;AAFD,WAAY,aAAa;IACvB,8BAAa,CAAA;AACf,CAAC,EAFW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAExB;AAED,IAAY,mBAKX;AALD,WAAY,mBAAmB;IAC7B,4DAAqC,CAAA;IACrC,qEAA8C,CAAA;IAC9C,2DAAoC,CAAA;IACpC,0CAAmB,CAAA;AACrB,CAAC,EALW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAK9B;AAEY,QAAA,cAAc,GAAG,KAAK,CAAC;AAEvB,QAAA,UAAU,GAAG,eAAe,CAAC;AAE7B,QAAA,YAAY,GAAG,OAAO,CAAC;AAEvB,QAAA,eAAe,GAAG,sBAAsB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GrantTypes, ResponseTypes, TokenTypes, Scopes } from '../enums/auth.enum';
|
|
2
|
+
declare type OauthExcludePath = string[] | RegExp[];
|
|
2
3
|
export declare type ClaimConfig = Array<{
|
|
3
4
|
dataName?: string;
|
|
4
5
|
claimName: string;
|
|
@@ -7,7 +8,7 @@ export declare type ClaimConfig = Array<{
|
|
|
7
8
|
isEntityId?: boolean;
|
|
8
9
|
}>;
|
|
9
10
|
export interface ApplicationConfig {
|
|
10
|
-
excludesOauth?:
|
|
11
|
+
excludesOauth?: OauthExcludePath;
|
|
11
12
|
oauthConfig?: ProviderOauthConfig;
|
|
12
13
|
mainRoute: string;
|
|
13
14
|
ENVIRONMENT?: string;
|
|
@@ -21,6 +22,7 @@ export interface OauthInterface {
|
|
|
21
22
|
claimsConfig: ClaimConfig;
|
|
22
23
|
scope?: 'openid' | string;
|
|
23
24
|
headersType?: TokenTypes;
|
|
25
|
+
authorizationServer: string;
|
|
24
26
|
}
|
|
25
27
|
export interface AccessTokenRequest {
|
|
26
28
|
code: string;
|
|
@@ -50,3 +52,4 @@ export interface JwtClaimsInterface extends Record<string, string | number> {
|
|
|
50
52
|
iat: number;
|
|
51
53
|
}
|
|
52
54
|
export declare type ProviderOauthConfig = Record<string, OauthInterface>;
|
|
55
|
+
export {};
|
|
@@ -9,7 +9,7 @@ export declare class AuthMiddleware implements NestMiddleware {
|
|
|
9
9
|
private logger;
|
|
10
10
|
constructor(connectService: OauthService, configService: ConfigService<ApplicationConfig>);
|
|
11
11
|
use(req: Request, res: Response, next: () => void): Promise<void>;
|
|
12
|
-
authenticateInternalToken(
|
|
12
|
+
authenticateInternalToken(token: string): Promise<any>;
|
|
13
13
|
isProviderAuthenticated(provider: any, config: OauthInterface, req: Request): Promise<boolean>;
|
|
14
14
|
redirectToProvider(provider: string, config: OauthInterface, req: Request, res: Response): void;
|
|
15
15
|
private defaultExclusion;
|
|
@@ -13,7 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
13
|
exports.AuthMiddleware = void 0;
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
15
|
const config_1 = require("@nestjs/config");
|
|
16
|
-
const
|
|
16
|
+
const infra_nestjs_1 = require("@vcita/infra-nestjs");
|
|
17
17
|
const configuration_1 = require("@vcita/infra-nestjs/dist/infra/config/configuration");
|
|
18
18
|
const auth_enum_1 = require("../enums/auth.enum");
|
|
19
19
|
const oauth_service_1 = require("../services/oauth.service");
|
|
@@ -23,7 +23,7 @@ let AuthMiddleware = AuthMiddleware_1 = class AuthMiddleware {
|
|
|
23
23
|
constructor(connectService, configService) {
|
|
24
24
|
this.connectService = connectService;
|
|
25
25
|
this.configService = configService;
|
|
26
|
-
this.logger = new
|
|
26
|
+
this.logger = new infra_nestjs_1.InfraLoggerService(AuthMiddleware_1.name);
|
|
27
27
|
}
|
|
28
28
|
async use(req, res, next) {
|
|
29
29
|
const url = req.baseUrl || req.originalUrl;
|
|
@@ -34,9 +34,23 @@ let AuthMiddleware = AuthMiddleware_1 = class AuthMiddleware {
|
|
|
34
34
|
}
|
|
35
35
|
if ((0, configuration_1.default)().authInternalRsaPublic != null) {
|
|
36
36
|
this.logger.debug('About to check if it is internal request');
|
|
37
|
-
const
|
|
37
|
+
const token = authentication_utils_1.AuthenticationUtils.extractTokenFromRequest(req);
|
|
38
|
+
let decodedToken;
|
|
39
|
+
try {
|
|
40
|
+
decodedToken = await this.authenticateInternalToken(token);
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
if (process.env.ENVIRONMENT === 'development') {
|
|
44
|
+
this.logger.warn('Fallback to development simplified authentication');
|
|
45
|
+
decodedToken = JSON.parse(token);
|
|
46
|
+
}
|
|
47
|
+
else
|
|
48
|
+
throw e;
|
|
49
|
+
}
|
|
38
50
|
if (decodedToken) {
|
|
39
|
-
|
|
51
|
+
const wrapper = authentication_utils_1.AuthenticationUtils.parseActorFromPayload(decodedToken);
|
|
52
|
+
wrapper.actor.originJWT = token;
|
|
53
|
+
req[auth_enum_1.authActorHeader] = wrapper;
|
|
40
54
|
return next();
|
|
41
55
|
}
|
|
42
56
|
}
|
|
@@ -57,8 +71,7 @@ let AuthMiddleware = AuthMiddleware_1 = class AuthMiddleware {
|
|
|
57
71
|
return next();
|
|
58
72
|
}
|
|
59
73
|
}
|
|
60
|
-
async authenticateInternalToken(
|
|
61
|
-
const token = authentication_utils_1.AuthenticationUtils.extractTokenFromRequest(req);
|
|
74
|
+
async authenticateInternalToken(token) {
|
|
62
75
|
if (!token)
|
|
63
76
|
return Promise.resolve(false);
|
|
64
77
|
const PromiseResult = new Promise((resolve, reject) => {
|
|
@@ -97,13 +110,12 @@ let AuthMiddleware = AuthMiddleware_1 = class AuthMiddleware {
|
|
|
97
110
|
res.redirect(authorizationUrl.href);
|
|
98
111
|
}
|
|
99
112
|
defaultExclusion(url = '') {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
url.includes('favicon.ico'));
|
|
113
|
+
const excludes = [
|
|
114
|
+
...(this.configService.get('excludesOauth') || []),
|
|
115
|
+
/assets\/.*\..*$/,
|
|
116
|
+
/.*favicon\.ico$/,
|
|
117
|
+
];
|
|
118
|
+
return excludes.some((regex) => regex.test(url));
|
|
107
119
|
}
|
|
108
120
|
};
|
|
109
121
|
AuthMiddleware = AuthMiddleware_1 = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.middleware.js","sourceRoot":"","sources":["../../../src/oauth/middleware/auth.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAmF;AACnF,2CAA+C;AAE/C,
|
|
1
|
+
{"version":3,"file":"auth.middleware.js","sourceRoot":"","sources":["../../../src/oauth/middleware/auth.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAmF;AACnF,2CAA+C;AAE/C,sDAAyD;AACzD,uFAAgF;AAEhF,kDAAiE;AAMjE,6DAAyD;AACzD,wEAAoE;AACpE,qFAAuF;AAGvF,IAAa,cAAc,sBAA3B,MAAa,cAAc;IAEzB,YACU,cAA4B,EAC5B,aAA+C;QAD/C,mBAAc,GAAd,cAAc,CAAc;QAC5B,kBAAa,GAAb,aAAa,CAAkC;QAHjD,WAAM,GAAG,IAAI,iCAAkB,CAAC,gBAAc,CAAC,IAAI,CAAC,CAAC;IAI1D,CAAC;IAEJ,KAAK,CAAC,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAgB;QACrD,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,WAAW,CAAC;QAE3C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wCAAwC,GAAG,EAAE,CAAC,CAAC;QAEjE,IAAI,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE;YAC9B,IAAI,CAAC,MAAM,CA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,CAAA;AApIY,cAAc;IAD1B,IAAA,mBAAU,GAAE;qCAIe,4BAAY;QACb,sBAAa;GAJ3B,cAAc,CAoI1B;AApIY,wCAAc"}
|
|
@@ -13,14 +13,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
13
|
exports.OauthAuthorizationMiddleware = void 0;
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
15
|
const config_1 = require("@nestjs/config");
|
|
16
|
-
const
|
|
16
|
+
const infra_nestjs_1 = require("@vcita/infra-nestjs");
|
|
17
17
|
const auth_enum_1 = require("../enums/auth.enum");
|
|
18
18
|
const oauth_service_1 = require("../services/oauth.service");
|
|
19
19
|
let OauthAuthorizationMiddleware = OauthAuthorizationMiddleware_1 = class OauthAuthorizationMiddleware {
|
|
20
20
|
constructor(connectService, configService) {
|
|
21
21
|
this.connectService = connectService;
|
|
22
22
|
this.configService = configService;
|
|
23
|
-
this.logger = new
|
|
23
|
+
this.logger = new infra_nestjs_1.InfraLoggerService(OauthAuthorizationMiddleware_1.name);
|
|
24
24
|
}
|
|
25
25
|
async use(req, res, next) {
|
|
26
26
|
this.logger.debug(`in authorization middleware, about to check authentication ${req.url}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth-authorization.middleware.js","sourceRoot":"","sources":["../../../src/oauth/middleware/oauth-authorization.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA4D;AAC5D,2CAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"oauth-authorization.middleware.js","sourceRoot":"","sources":["../../../src/oauth/middleware/oauth-authorization.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA4D;AAC5D,2CAA+C;AAC/C,sDAAyD;AAEzD,kDAAkE;AAKlE,6DAAyD;AAGzD,IAAa,4BAA4B,oCAAzC,MAAa,4BAA4B;IAEvC,YACU,cAA4B,EAC5B,aAA+C;QAD/C,mBAAc,GAAd,cAAc,CAAc;QAC5B,kBAAa,GAAb,aAAa,CAAkC;QAHjD,WAAM,GAAG,IAAI,iCAAkB,CAAC,8BAA4B,CAAC,IAAI,CAAC,CAAC;IAIxE,CAAC;IACJ,KAAK,CAAC,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAgB;QACrD,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,8DAA8D,GAAG,CAAC,GAAG,EAAE,CACxE,CAAC;QACF,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC;QACtB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;QAC9B,MAAM,CAAC,QAAQ,EAAE,WAAW,GAAG,EAAE,CAAC,GAAG,CAClC,KAAgB,IAAI,wBAAY,CAClC,CAAC,KAAK,CAAC,0BAAc,CAAC,CAAC;QACxB,IAAI,IAAI,EAAE;YACR,IAAI,EAAE,CAAC;SACR;aAAM;YACL,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,4DAA4D,CAC7D,CAAC;YACF,MAAM,WAAW,GACf,IAAI,CAAC,aAAa,CAAC,GAAG,CAAsB,aAAa,CAAC,CAAC,QAAQ,CAAC,CAAC;YACvE,MAAM,gBAAgB,GAAG,IAAI,CAAC,cAAc,CAAC,aAAa,CACxD,WAAW,EACX,WAAW,EACX,QAAQ,CACT,CAAC;YACF,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,yBAAyB,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC;YAClE,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;SACrC;IACH,CAAC;CACF,CAAA;AAhCY,4BAA4B;IADxC,IAAA,mBAAU,GAAE;qCAIe,4BAAY;QACb,sBAAa;GAJ3B,4BAA4B,CAgCxC;AAhCY,oEAA4B"}
|
|
@@ -26,6 +26,7 @@ const infra_proxy_service_1 = require("./services/infra-proxy.service");
|
|
|
26
26
|
const external_proxy_service_1 = require("./services/external-proxy.service");
|
|
27
27
|
const internal_proxy_service_1 = require("./services/internal-proxy.service");
|
|
28
28
|
const nestjs_redis_1 = require("nestjs-redis");
|
|
29
|
+
const infra_utils_1 = require("@vcita/infra-nestjs/dist/infra/utils/infra.utils");
|
|
29
30
|
let OauthModule = OauthModule_1 = class OauthModule {
|
|
30
31
|
configure(consumer) {
|
|
31
32
|
consumer.apply(cookieParser('secret')).exclude('*.*').forRoutes('*');
|
|
@@ -36,6 +37,7 @@ let OauthModule = OauthModule_1 = class OauthModule {
|
|
|
36
37
|
consumer.apply(oauth_authorization_middleware_1.OauthAuthorizationMiddleware).forRoutes(oauth_controller_1.OauthController);
|
|
37
38
|
}
|
|
38
39
|
static register(config) {
|
|
40
|
+
logOauthExcludeWarnings(config);
|
|
39
41
|
const configModule = config_1.ConfigModule.forFeature(() => {
|
|
40
42
|
const applicationOauthConfig = (0, oauth_utils_1.getOauthConfiguration)(config.oauthConfig);
|
|
41
43
|
const appConfig = {
|
|
@@ -61,9 +63,14 @@ let OauthModule = OauthModule_1 = class OauthModule {
|
|
|
61
63
|
common_1.HttpModule,
|
|
62
64
|
terminus_1.TerminusModule,
|
|
63
65
|
typeorm_1.TypeOrmModule.forFeature([oauth_data_entity_1.OauthData]),
|
|
64
|
-
nestjs_redis_1.RedisModule.
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
nestjs_redis_1.RedisModule.forRootAsync({
|
|
67
|
+
imports: [config_1.ConfigModule],
|
|
68
|
+
useFactory: (config) => ({
|
|
69
|
+
host: config.get('redis').host,
|
|
70
|
+
port: config.get('redis').port,
|
|
71
|
+
keyPrefix: config.get('name') + ':',
|
|
72
|
+
}),
|
|
73
|
+
inject: [config_1.ConfigService],
|
|
67
74
|
}),
|
|
68
75
|
],
|
|
69
76
|
exports: [
|
|
@@ -81,4 +88,23 @@ OauthModule = OauthModule_1 = __decorate([
|
|
|
81
88
|
(0, common_1.Module)({})
|
|
82
89
|
], OauthModule);
|
|
83
90
|
exports.OauthModule = OauthModule;
|
|
91
|
+
function logOauthExcludeWarnings(externalConfigs) {
|
|
92
|
+
if (externalConfigs.excludesOauth && externalConfigs.excludesOauth.length) {
|
|
93
|
+
if (typeof externalConfigs.excludesOauth[0] === 'string') {
|
|
94
|
+
(0, infra_utils_1.deprecationWarning)('You are using deprecated form of [ excludeOauth ] attribute, which is of type: `string[]`', 'You should use the `RegExp[]` type instead!', '2.0.0');
|
|
95
|
+
externalConfigs.excludesOauth = externalConfigs.excludesOauth.map((str) => new RegExp(`^${str}$`));
|
|
96
|
+
}
|
|
97
|
+
const excludedPaths = [
|
|
98
|
+
'You have excluded the following paths from authentication !!!',
|
|
99
|
+
'[',
|
|
100
|
+
externalConfigs.excludesOauth.map((regex) => regex.source).join(', '),
|
|
101
|
+
']',
|
|
102
|
+
];
|
|
103
|
+
infra_utils_1.infraAnnouncementsLogger.warn([
|
|
104
|
+
excludedPaths.join(' '),
|
|
105
|
+
'That might pose severe security risks',
|
|
106
|
+
'Are you sure of that?',
|
|
107
|
+
].join('\n'));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
84
110
|
//# sourceMappingURL=oauth.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.module.js","sourceRoot":"","sources":["../../src/oauth/oauth.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAOwB;AACxB,8CAA8C;AAC9C,4DAAwD;AACxD,qEAAiE;AACjE,kEAA8D;AAC9D,sEAAkE;AAClE,6CAAgD;AAChD,wEAA6D;AAC7D,
|
|
1
|
+
{"version":3,"file":"oauth.module.js","sourceRoot":"","sources":["../../src/oauth/oauth.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAOwB;AACxB,8CAA8C;AAC9C,4DAAwD;AACxD,qEAAiE;AACjE,kEAA8D;AAC9D,sEAAkE;AAClE,6CAAgD;AAChD,wEAA6D;AAC7D,2CAA6D;AAE7D,gGAA2F;AAC3F,qDAA4D;AAC5D,+CAAkD;AAClD,sEAAiE;AACjE,sDAAkD;AAClD,wEAAmE;A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CAAC;YACvB,uCAAuC;YACvC,uBAAuB;SACxB,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;KACH;AACH,CAAC"}
|
|
@@ -22,8 +22,10 @@ export declare class ActorEntity extends BelongsEntity implements Acts {
|
|
|
22
22
|
readonly type: ActorType;
|
|
23
23
|
readonly belongsTo?: BelongsEntity;
|
|
24
24
|
readonly actingAs?: BelongsEntity;
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
private _originJWT;
|
|
26
|
+
constructor(uid: string, type: ActorType, belongsTo?: BelongsEntity, actingAs?: BelongsEntity, originJWT?: string);
|
|
27
|
+
get originJWT(): string;
|
|
28
|
+
set originJWT(jwt: string);
|
|
27
29
|
isActingAs(): boolean;
|
|
28
30
|
getActingAs(type: ActorType): BelongsEntity | null;
|
|
29
31
|
}
|