@celljs/oauth2-client 3.0.0

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 (249) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/cell.yml +57 -0
  4. package/lib/node/authentication/authentication-protocol.d.ts +25 -0
  5. package/lib/node/authentication/authentication-protocol.d.ts.map +1 -0
  6. package/lib/node/authentication/authentication-protocol.js +11 -0
  7. package/lib/node/authentication/authentication-protocol.js.map +1 -0
  8. package/lib/node/authentication/index.d.ts +4 -0
  9. package/lib/node/authentication/index.d.ts.map +1 -0
  10. package/lib/node/authentication/index.js +20 -0
  11. package/lib/node/authentication/index.js.map +1 -0
  12. package/lib/node/authentication/oauth2-authentication-provider.d.ts +30 -0
  13. package/lib/node/authentication/oauth2-authentication-provider.d.ts.map +1 -0
  14. package/lib/node/authentication/oauth2-authentication-provider.js +170 -0
  15. package/lib/node/authentication/oauth2-authentication-provider.js.map +1 -0
  16. package/lib/node/authentication/oidc-authentication-provider.d.ts +18 -0
  17. package/lib/node/authentication/oidc-authentication-provider.d.ts.map +1 -0
  18. package/lib/node/authentication/oidc-authentication-provider.js +74 -0
  19. package/lib/node/authentication/oidc-authentication-provider.js.map +1 -0
  20. package/lib/node/authorization/authorization-code-authorized-client-provider.d.ts +5 -0
  21. package/lib/node/authorization/authorization-code-authorized-client-provider.d.ts.map +1 -0
  22. package/lib/node/authorization/authorization-code-authorized-client-provider.js +27 -0
  23. package/lib/node/authorization/authorization-code-authorized-client-provider.js.map +1 -0
  24. package/lib/node/authorization/authorization-code-grant-middleware.d.ts +26 -0
  25. package/lib/node/authorization/authorization-code-grant-middleware.d.ts.map +1 -0
  26. package/lib/node/authorization/authorization-code-grant-middleware.js +129 -0
  27. package/lib/node/authorization/authorization-code-grant-middleware.js.map +1 -0
  28. package/lib/node/authorization/authorization-failure-handler.d.ts +10 -0
  29. package/lib/node/authorization/authorization-failure-handler.d.ts.map +1 -0
  30. package/lib/node/authorization/authorization-failure-handler.js +35 -0
  31. package/lib/node/authorization/authorization-failure-handler.js.map +1 -0
  32. package/lib/node/authorization/authorization-protocol.d.ts +78 -0
  33. package/lib/node/authorization/authorization-protocol.d.ts.map +1 -0
  34. package/lib/node/authorization/authorization-protocol.js +34 -0
  35. package/lib/node/authorization/authorization-protocol.js.map +1 -0
  36. package/lib/node/authorization/authorization-request-manager.d.ts +13 -0
  37. package/lib/node/authorization/authorization-request-manager.d.ts.map +1 -0
  38. package/lib/node/authorization/authorization-request-manager.js +64 -0
  39. package/lib/node/authorization/authorization-request-manager.js.map +1 -0
  40. package/lib/node/authorization/authorization-request-redirect-middleware.d.ts +20 -0
  41. package/lib/node/authorization/authorization-request-redirect-middleware.d.ts.map +1 -0
  42. package/lib/node/authorization/authorization-request-redirect-middleware.js +113 -0
  43. package/lib/node/authorization/authorization-request-redirect-middleware.js.map +1 -0
  44. package/lib/node/authorization/authorization-request-resolver.d.ts +38 -0
  45. package/lib/node/authorization/authorization-request-resolver.d.ts.map +1 -0
  46. package/lib/node/authorization/authorization-request-resolver.js +155 -0
  47. package/lib/node/authorization/authorization-request-resolver.js.map +1 -0
  48. package/lib/node/authorization/authorization-success-handler.d.ts +7 -0
  49. package/lib/node/authorization/authorization-success-handler.d.ts.map +1 -0
  50. package/lib/node/authorization/authorization-success-handler.js +28 -0
  51. package/lib/node/authorization/authorization-success-handler.js.map +1 -0
  52. package/lib/node/authorization/authorized-client-manager.d.ts +11 -0
  53. package/lib/node/authorization/authorized-client-manager.d.ts.map +1 -0
  54. package/lib/node/authorization/authorized-client-manager.js +48 -0
  55. package/lib/node/authorization/authorized-client-manager.js.map +1 -0
  56. package/lib/node/authorization/authorized-client-service.d.ts +12 -0
  57. package/lib/node/authorization/authorized-client-service.d.ts.map +1 -0
  58. package/lib/node/authorization/authorized-client-service.js +87 -0
  59. package/lib/node/authorization/authorized-client-service.js.map +1 -0
  60. package/lib/node/authorization/client-credentials-authorized-client-provider.d.ts +12 -0
  61. package/lib/node/authorization/client-credentials-authorized-client-provider.d.ts.map +1 -0
  62. package/lib/node/authorization/client-credentials-authorized-client-provider.js +72 -0
  63. package/lib/node/authorization/client-credentials-authorized-client-provider.js.map +1 -0
  64. package/lib/node/authorization/context-attributes-mapper.d.ts +5 -0
  65. package/lib/node/authorization/context-attributes-mapper.d.ts.map +1 -0
  66. package/lib/node/authorization/context-attributes-mapper.js +28 -0
  67. package/lib/node/authorization/context-attributes-mapper.js.map +1 -0
  68. package/lib/node/authorization/index.d.ts +14 -0
  69. package/lib/node/authorization/index.d.ts.map +1 -0
  70. package/lib/node/authorization/index.js +30 -0
  71. package/lib/node/authorization/index.js.map +1 -0
  72. package/lib/node/authorization/password-authorized-client-provider.d.ts +12 -0
  73. package/lib/node/authorization/password-authorized-client-provider.d.ts.map +1 -0
  74. package/lib/node/authorization/password-authorized-client-provider.js +85 -0
  75. package/lib/node/authorization/password-authorized-client-provider.js.map +1 -0
  76. package/lib/node/authorization/refresh-token-authorized-client-provider.d.ts +12 -0
  77. package/lib/node/authorization/refresh-token-authorized-client-provider.d.ts.map +1 -0
  78. package/lib/node/authorization/refresh-token-authorized-client-provider.js +68 -0
  79. package/lib/node/authorization/refresh-token-authorized-client-provider.js.map +1 -0
  80. package/lib/node/constants.d.ts +5 -0
  81. package/lib/node/constants.d.ts.map +1 -0
  82. package/lib/node/constants.js +8 -0
  83. package/lib/node/constants.js.map +1 -0
  84. package/lib/node/endpoint/authorization-code-token-response-client.d.ts +12 -0
  85. package/lib/node/endpoint/authorization-code-token-response-client.d.ts.map +1 -0
  86. package/lib/node/endpoint/authorization-code-token-response-client.js +83 -0
  87. package/lib/node/endpoint/authorization-code-token-response-client.js.map +1 -0
  88. package/lib/node/endpoint/client-credentials-token-response-client.d.ts +12 -0
  89. package/lib/node/endpoint/client-credentials-token-response-client.d.ts.map +1 -0
  90. package/lib/node/endpoint/client-credentials-token-response-client.js +80 -0
  91. package/lib/node/endpoint/client-credentials-token-response-client.js.map +1 -0
  92. package/lib/node/endpoint/endpoint-protocol.d.ts +48 -0
  93. package/lib/node/endpoint/endpoint-protocol.d.ts.map +1 -0
  94. package/lib/node/endpoint/endpoint-protocol.js +9 -0
  95. package/lib/node/endpoint/endpoint-protocol.js.map +1 -0
  96. package/lib/node/endpoint/index.d.ts +7 -0
  97. package/lib/node/endpoint/index.d.ts.map +1 -0
  98. package/lib/node/endpoint/index.js +23 -0
  99. package/lib/node/endpoint/index.js.map +1 -0
  100. package/lib/node/endpoint/password-token-response-client.d.ts +12 -0
  101. package/lib/node/endpoint/password-token-response-client.d.ts.map +1 -0
  102. package/lib/node/endpoint/password-token-response-client.js +82 -0
  103. package/lib/node/endpoint/password-token-response-client.js.map +1 -0
  104. package/lib/node/endpoint/refresh-token-token-response-client.d.ts +12 -0
  105. package/lib/node/endpoint/refresh-token-token-response-client.d.ts.map +1 -0
  106. package/lib/node/endpoint/refresh-token-token-response-client.js +87 -0
  107. package/lib/node/endpoint/refresh-token-token-response-client.js.map +1 -0
  108. package/lib/node/endpoint/user-response-client.d.ts +9 -0
  109. package/lib/node/endpoint/user-response-client.d.ts.map +1 -0
  110. package/lib/node/endpoint/user-response-client.js +84 -0
  111. package/lib/node/endpoint/user-response-client.js.map +1 -0
  112. package/lib/node/error/error-hander.d.ts +11 -0
  113. package/lib/node/error/error-hander.d.ts.map +1 -0
  114. package/lib/node/error/error-hander.js +52 -0
  115. package/lib/node/error/error-hander.js.map +1 -0
  116. package/lib/node/error/error-protocol.d.ts +3 -0
  117. package/lib/node/error/error-protocol.d.ts.map +1 -0
  118. package/lib/node/error/error-protocol.js +7 -0
  119. package/lib/node/error/error-protocol.js.map +1 -0
  120. package/lib/node/error/error.d.ts +10 -0
  121. package/lib/node/error/error.d.ts.map +1 -0
  122. package/lib/node/error/error.js +23 -0
  123. package/lib/node/error/error.js.map +1 -0
  124. package/lib/node/error/index.d.ts +4 -0
  125. package/lib/node/error/index.d.ts.map +1 -0
  126. package/lib/node/error/index.js +20 -0
  127. package/lib/node/error/index.js.map +1 -0
  128. package/lib/node/index.d.ts +8 -0
  129. package/lib/node/index.d.ts.map +1 -0
  130. package/lib/node/index.js +24 -0
  131. package/lib/node/index.js.map +1 -0
  132. package/lib/node/module.d.ts +4 -0
  133. package/lib/node/module.d.ts.map +1 -0
  134. package/lib/node/module.js +6 -0
  135. package/lib/node/module.js.map +1 -0
  136. package/lib/node/provider/index.d.ts +3 -0
  137. package/lib/node/provider/index.d.ts.map +1 -0
  138. package/lib/node/provider/index.js +19 -0
  139. package/lib/node/provider/index.js.map +1 -0
  140. package/lib/node/provider/provider-details-manager.d.ts +12 -0
  141. package/lib/node/provider/provider-details-manager.d.ts.map +1 -0
  142. package/lib/node/provider/provider-details-manager.js +50 -0
  143. package/lib/node/provider/provider-details-manager.js.map +1 -0
  144. package/lib/node/provider/provider-protocol.d.ts +21 -0
  145. package/lib/node/provider/provider-protocol.d.ts.map +1 -0
  146. package/lib/node/provider/provider-protocol.js +5 -0
  147. package/lib/node/provider/provider-protocol.js.map +1 -0
  148. package/lib/node/registration/id-token-jwt-decoder-facatory.d.ts +15 -0
  149. package/lib/node/registration/id-token-jwt-decoder-facatory.d.ts.map +1 -0
  150. package/lib/node/registration/id-token-jwt-decoder-facatory.js +89 -0
  151. package/lib/node/registration/id-token-jwt-decoder-facatory.js.map +1 -0
  152. package/lib/node/registration/index.d.ts +5 -0
  153. package/lib/node/registration/index.d.ts.map +1 -0
  154. package/lib/node/registration/index.js +21 -0
  155. package/lib/node/registration/index.js.map +1 -0
  156. package/lib/node/registration/jws-algorithm-resolver.d.ts +5 -0
  157. package/lib/node/registration/jws-algorithm-resolver.d.ts.map +1 -0
  158. package/lib/node/registration/jws-algorithm-resolver.js +22 -0
  159. package/lib/node/registration/jws-algorithm-resolver.js.map +1 -0
  160. package/lib/node/registration/registration-manager.d.ts +15 -0
  161. package/lib/node/registration/registration-manager.d.ts.map +1 -0
  162. package/lib/node/registration/registration-manager.js +64 -0
  163. package/lib/node/registration/registration-manager.js.map +1 -0
  164. package/lib/node/registration/registration-protocol.d.ts +22 -0
  165. package/lib/node/registration/registration-protocol.d.ts.map +1 -0
  166. package/lib/node/registration/registration-protocol.js +7 -0
  167. package/lib/node/registration/registration-protocol.js.map +1 -0
  168. package/lib/node/user/index.d.ts +4 -0
  169. package/lib/node/user/index.d.ts.map +1 -0
  170. package/lib/node/user/index.js +20 -0
  171. package/lib/node/user/index.js.map +1 -0
  172. package/lib/node/user/oauth2-user-service.d.ts +10 -0
  173. package/lib/node/user/oauth2-user-service.d.ts.map +1 -0
  174. package/lib/node/user/oauth2-user-service.js +61 -0
  175. package/lib/node/user/oauth2-user-service.js.map +1 -0
  176. package/lib/node/user/oidc-user-service.d.ts +13 -0
  177. package/lib/node/user/oidc-user-service.d.ts.map +1 -0
  178. package/lib/node/user/oidc-user-service.js +98 -0
  179. package/lib/node/user/oidc-user-service.js.map +1 -0
  180. package/lib/node/user/user-protocol.d.ts +6 -0
  181. package/lib/node/user/user-protocol.d.ts.map +1 -0
  182. package/lib/node/user/user-protocol.js +3 -0
  183. package/lib/node/user/user-protocol.js.map +1 -0
  184. package/lib/node/utils/authorization-grant-request-entity-util.d.ts +10 -0
  185. package/lib/node/utils/authorization-grant-request-entity-util.d.ts.map +1 -0
  186. package/lib/node/utils/authorization-grant-request-entity-util.js +28 -0
  187. package/lib/node/utils/authorization-grant-request-entity-util.js.map +1 -0
  188. package/lib/node/utils/authorization-response-util.d.ts +8 -0
  189. package/lib/node/utils/authorization-response-util.d.ts.map +1 -0
  190. package/lib/node/utils/authorization-response-util.js +53 -0
  191. package/lib/node/utils/authorization-response-util.js.map +1 -0
  192. package/lib/node/utils/index.d.ts +3 -0
  193. package/lib/node/utils/index.d.ts.map +1 -0
  194. package/lib/node/utils/index.js +19 -0
  195. package/lib/node/utils/index.js.map +1 -0
  196. package/lib/package.spec.d.ts +1 -0
  197. package/lib/package.spec.d.ts.map +1 -0
  198. package/lib/package.spec.js +4 -0
  199. package/lib/package.spec.js.map +1 -0
  200. package/package.json +51 -0
  201. package/src/node/authentication/authentication-protocol.ts +26 -0
  202. package/src/node/authentication/index.ts +3 -0
  203. package/src/node/authentication/oauth2-authentication-provider.ts +163 -0
  204. package/src/node/authentication/oidc-authentication-provider.ts +60 -0
  205. package/src/node/authorization/authorization-code-authorized-client-provider.ts +16 -0
  206. package/src/node/authorization/authorization-code-grant-middleware.ts +110 -0
  207. package/src/node/authorization/authorization-failure-handler.ts +23 -0
  208. package/src/node/authorization/authorization-protocol.ts +104 -0
  209. package/src/node/authorization/authorization-request-manager.ts +54 -0
  210. package/src/node/authorization/authorization-request-redirect-middleware.ts +91 -0
  211. package/src/node/authorization/authorization-request-resolver.ts +149 -0
  212. package/src/node/authorization/authorization-success-handler.ts +15 -0
  213. package/src/node/authorization/authorized-client-manager.ts +35 -0
  214. package/src/node/authorization/authorized-client-service.ts +73 -0
  215. package/src/node/authorization/client-credentials-authorized-client-provider.ts +61 -0
  216. package/src/node/authorization/context-attributes-mapper.ts +18 -0
  217. package/src/node/authorization/index.ts +13 -0
  218. package/src/node/authorization/password-authorized-client-provider.ts +78 -0
  219. package/src/node/authorization/refresh-token-authorized-client-provider.ts +58 -0
  220. package/src/node/constants.ts +4 -0
  221. package/src/node/endpoint/authorization-code-token-response-client.ts +73 -0
  222. package/src/node/endpoint/client-credentials-token-response-client.ts +69 -0
  223. package/src/node/endpoint/endpoint-protocol.ts +55 -0
  224. package/src/node/endpoint/index.ts +6 -0
  225. package/src/node/endpoint/password-token-response-client.ts +71 -0
  226. package/src/node/endpoint/refresh-token-token-response-client.ts +77 -0
  227. package/src/node/endpoint/user-response-client.ts +72 -0
  228. package/src/node/error/error-hander.ts +39 -0
  229. package/src/node/error/error-protocol.ts +6 -0
  230. package/src/node/error/error.ts +19 -0
  231. package/src/node/error/index.ts +3 -0
  232. package/src/node/index.ts +7 -0
  233. package/src/node/module.ts +4 -0
  234. package/src/node/provider/index.ts +2 -0
  235. package/src/node/provider/provider-details-manager.ts +33 -0
  236. package/src/node/provider/provider-protocol.ts +24 -0
  237. package/src/node/registration/id-token-jwt-decoder-facatory.ts +71 -0
  238. package/src/node/registration/index.ts +4 -0
  239. package/src/node/registration/jws-algorithm-resolver.ts +12 -0
  240. package/src/node/registration/registration-manager.ts +47 -0
  241. package/src/node/registration/registration-protocol.ts +27 -0
  242. package/src/node/user/index.ts +3 -0
  243. package/src/node/user/oauth2-user-service.ts +50 -0
  244. package/src/node/user/oidc-user-service.ts +92 -0
  245. package/src/node/user/user-protocol.ts +6 -0
  246. package/src/node/utils/authorization-grant-request-entity-util.ts +26 -0
  247. package/src/node/utils/authorization-response-util.ts +50 -0
  248. package/src/node/utils/index.ts +2 -0
  249. package/src/package.spec.ts +4 -0
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OidcUserService = void 0;
13
+ const core_1 = require("@celljs/core");
14
+ const endpoint_1 = require("../endpoint");
15
+ const provider_1 = require("../provider");
16
+ const oauth2_core_1 = require("@celljs/oauth2-core");
17
+ let OidcUserService = class OidcUserService {
18
+ async load(userRequest) {
19
+ var _a;
20
+ const { idToken, clientRegistration } = userRequest;
21
+ let claims = {};
22
+ if (await this.shuldRetrieveuserInfo(userRequest)) {
23
+ const { userAttributes } = await this.userResponseClient.getUserResponse(userRequest);
24
+ claims = Object.assign({}, userAttributes);
25
+ const subject = claims[oauth2_core_1.StandardClaimNames.SUB];
26
+ // https://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse
27
+ // 1) The sub (subject) Claim MUST always be returned in the UserInfo Response
28
+ if (!subject) {
29
+ throw new oauth2_core_1.OAuth2AuthenticationError({
30
+ errorCode: endpoint_1.INVALID_USER_INFO_RESPONSE_ERROR_CODE
31
+ });
32
+ }
33
+ // 2) Due to the possibility of token substitution attacks (see Section 16.11),
34
+ // the UserInfo Response is not guaranteed to be about the End-User
35
+ // identified by the sub (subject) element of the ID Token.
36
+ // The sub Claim in the UserInfo Response MUST be verified to exactly match
37
+ // the sub Claim in the ID Token; if they do not match,
38
+ // the UserInfo Response values MUST NOT be used.
39
+ if (subject !== idToken.payload[oauth2_core_1.IdTokenClaimNames.SUB]) {
40
+ throw new oauth2_core_1.OAuth2AuthenticationError({
41
+ errorCode: endpoint_1.INVALID_USER_INFO_RESPONSE_ERROR_CODE
42
+ });
43
+ }
44
+ }
45
+ claims = Object.assign(Object.assign({}, claims), idToken.payload);
46
+ const providerDetails = await this.providerDetailsManager.get(clientRegistration.provider);
47
+ const userNameAttributeName = ((_a = providerDetails === null || providerDetails === void 0 ? void 0 : providerDetails.userInfoEndpoint) === null || _a === void 0 ? void 0 : _a.userNameAttributeName) || oauth2_core_1.IdTokenClaimNames.SUB;
48
+ return {
49
+ type: clientRegistration.registrationId,
50
+ username: claims[userNameAttributeName],
51
+ password: '',
52
+ accountNonExpired: true,
53
+ accountNonLocked: true,
54
+ credentialsNonExpired: true,
55
+ enabled: true,
56
+ policies: [],
57
+ claims,
58
+ idToken
59
+ };
60
+ }
61
+ async shuldRetrieveuserInfo(userRequest) {
62
+ var _a, _b;
63
+ const { clientRegistration, accessToken } = userRequest;
64
+ const providerDetails = await this.providerDetailsManager.get(clientRegistration.provider);
65
+ // Auto-disabled if UserInfo Endpoint URI is not provided
66
+ if (!((_a = providerDetails === null || providerDetails === void 0 ? void 0 : providerDetails.userInfoEndpoint) === null || _a === void 0 ? void 0 : _a.uri)) {
67
+ return false;
68
+ }
69
+ // The Claims requested by the profile, email, address, and phone scope values
70
+ // are returned from the UserInfo Endpoint (as described in Section 5.3.2),
71
+ // when a response_type value is used that results in an Access Token being issued.
72
+ // However, when no Access Token is issued, which is the case for the response_type=id_token,
73
+ // the resulting Claims are returned in the ID Token.
74
+ // The Authorization Code Grant Flow, which is response_type=code, results in an Access Token being issued.
75
+ if (oauth2_core_1.AuthorizationGrantType.AuthorizationCode === clientRegistration.authorizationGrantType) {
76
+ // Return true if there is at least one match between the authorized scope(s) and accessible scope(s)
77
+ return !((_b = this.accessibleScopes) === null || _b === void 0 ? void 0 : _b.length) || this.accessibleScopes.some(v => accessToken.scopes.indexOf(v) !== -1);
78
+ }
79
+ return false;
80
+ }
81
+ };
82
+ __decorate([
83
+ (0, core_1.Value)('cell.oauth2.client.accessibleScopes'),
84
+ __metadata("design:type", Array)
85
+ ], OidcUserService.prototype, "accessibleScopes", void 0);
86
+ __decorate([
87
+ (0, core_1.Autowired)(provider_1.ProviderDetailsManager),
88
+ __metadata("design:type", Object)
89
+ ], OidcUserService.prototype, "providerDetailsManager", void 0);
90
+ __decorate([
91
+ (0, core_1.Autowired)(endpoint_1.UserResponseClient),
92
+ __metadata("design:type", Object)
93
+ ], OidcUserService.prototype, "userResponseClient", void 0);
94
+ OidcUserService = __decorate([
95
+ (0, core_1.Component)()
96
+ ], OidcUserService);
97
+ exports.OidcUserService = OidcUserService;
98
+ //# sourceMappingURL=oidc-user-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oidc-user-service.js","sourceRoot":"","sources":["../../../src/node/user/oidc-user-service.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,6 @@
1
+ import { Jwt } from '@celljs/oauth2-jose';
2
+ import { OAuth2UserRequest } from '../endpoint';
3
+ export interface OidcUserRequest extends OAuth2UserRequest {
4
+ idToken: Jwt;
5
+ }
6
+ //# sourceMappingURL=user-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-protocol.d.ts","sourceRoot":"","sources":["../../../src/node/user/user-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,eAAgB,SAAQ,iBAAiB;IACtD,OAAO,EAAE,GAAG,CAAC;CAChB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=user-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-protocol.js","sourceRoot":"","sources":["../../../src/node/user/user-protocol.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { ClientRegistration } from '../registration';
2
+ export declare namespace AuthorizationGrantRequestEntityUtil {
3
+ function getTokenRequestHeaders(clientRegistration: ClientRegistration): {
4
+ [key: string]: any;
5
+ };
6
+ function getDefaultTokenRequestHeaders(): {
7
+ [key: string]: any;
8
+ };
9
+ }
10
+ //# sourceMappingURL=authorization-grant-request-entity-util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization-grant-request-entity-util.d.ts","sourceRoot":"","sources":["../../../src/node/utils/authorization-grant-request-entity-util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAIrD,yBAAiB,mCAAmC,CAAC;IAEjD,SAAgB,sBAAsB,CAAC,kBAAkB,EAAE,kBAAkB,GAAG;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CASrG;IAED,SAAgB,6BAA6B,IAAI;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAMtE;CACJ"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthorizationGrantRequestEntityUtil = void 0;
4
+ const oauth2_core_1 = require("@celljs/oauth2-core");
5
+ const http_1 = require("@celljs/http");
6
+ const crypto_js_1 = require("crypto-js");
7
+ var AuthorizationGrantRequestEntityUtil;
8
+ (function (AuthorizationGrantRequestEntityUtil) {
9
+ function getTokenRequestHeaders(clientRegistration) {
10
+ const headers = Object.assign({}, getDefaultTokenRequestHeaders());
11
+ const { clientAuthenticationMethod, clientId, clientSecret } = clientRegistration;
12
+ if (clientAuthenticationMethod === oauth2_core_1.ClientAuthenticationMethod.Basic) {
13
+ const credentialsStr = `${clientId}:${clientSecret}`;
14
+ const encoded = crypto_js_1.enc.Latin1.parse(credentialsStr);
15
+ headers[http_1.HttpHeaders.AUTHORIZATION] = `${clientAuthenticationMethod} ${crypto_js_1.enc.Base64.stringify(encoded)}`;
16
+ }
17
+ return headers;
18
+ }
19
+ AuthorizationGrantRequestEntityUtil.getTokenRequestHeaders = getTokenRequestHeaders;
20
+ function getDefaultTokenRequestHeaders() {
21
+ return {
22
+ [http_1.HttpHeaders.ACCEPT]: http_1.MediaType.APPLICATION_JSON_UTF8,
23
+ [http_1.HttpHeaders.CONTENT_TYPE]: `${http_1.MediaType.APPLICATION_FORM_URLENCODED};charset=UTF-8`
24
+ };
25
+ }
26
+ AuthorizationGrantRequestEntityUtil.getDefaultTokenRequestHeaders = getDefaultTokenRequestHeaders;
27
+ })(AuthorizationGrantRequestEntityUtil = exports.AuthorizationGrantRequestEntityUtil || (exports.AuthorizationGrantRequestEntityUtil = {}));
28
+ //# sourceMappingURL=authorization-grant-request-entity-util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization-grant-request-entity-util.js","sourceRoot":"","sources":["../../../src/node/utils/authorization-grant-request-entity-util.ts"],"names":[],"mappings":";;;AAAA,qDAAiE;AAEjE,uCAAsD;AACtD,yCAAgC;AAEhC,IAAiB,mCAAmC,CAoBnD;AApBD,WAAiB,mCAAmC;IAEhD,SAAgB,sBAAsB,CAAC,kBAAsC;QACzE,MAAM,OAAO,qBAAQ,6BAA6B,EAAE,CAAE,CAAC;QACvD,MAAM,EAAE,0BAA0B,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,kBAAkB,CAAC;QAClF,IAAI,0BAA0B,KAAK,wCAA0B,CAAC,KAAK,EAAE;YACjE,MAAM,cAAc,GAAG,GAAG,QAAQ,IAAI,YAAY,EAAE,CAAC;YACrD,MAAM,OAAO,GAAG,eAAG,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;YACjD,OAAO,CAAC,kBAAW,CAAC,aAAa,CAAC,GAAG,GAAG,0BAA0B,IAAI,eAAG,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;SACzG;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;IATe,0DAAsB,yBASrC,CAAA;IAED,SAAgB,6BAA6B;QAEzC,OAAO;YACH,CAAC,kBAAW,CAAC,MAAM,CAAC,EAAE,gBAAS,CAAC,qBAAqB;YACrD,CAAC,kBAAW,CAAC,YAAY,CAAC,EAAE,GAAG,gBAAS,CAAC,2BAA2B,gBAAgB;SACvF,CAAC;IACN,CAAC;IANe,iEAA6B,gCAM5C,CAAA;AACL,CAAC,EApBgB,mCAAmC,GAAnC,2CAAmC,KAAnC,2CAAmC,QAoBnD"}
@@ -0,0 +1,8 @@
1
+ import { AuthorizationResponse } from '@celljs/oauth2-core';
2
+ export declare namespace AuthorizationResponseUtil {
3
+ function isAuthorizationResponse(): boolean;
4
+ function isAuthorizationResponseSuccess(): boolean;
5
+ function isAuthorizationResponseError(): boolean;
6
+ function convert(redirectUri: string): AuthorizationResponse;
7
+ }
8
+ //# sourceMappingURL=authorization-response-util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization-response-util.d.ts","sourceRoot":"","sources":["../../../src/node/utils/authorization-response-util.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAElF,yBAAiB,yBAAyB,CAAC;IAEvC,SAAgB,uBAAuB,IAAI,OAAO,CAEjD;IAED,SAAgB,8BAA8B,IAAI,OAAO,CAIxD;IAED,SAAgB,4BAA4B,IAAI,OAAO,CAItD;IAED,SAAgB,OAAO,CAAC,WAAW,EAAE,MAAM,yBA2B1C;CACJ"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthorizationResponseUtil = void 0;
4
+ const node_1 = require("@celljs/web/lib/node");
5
+ const oauth2_core_1 = require("@celljs/oauth2-core");
6
+ var AuthorizationResponseUtil;
7
+ (function (AuthorizationResponseUtil) {
8
+ function isAuthorizationResponse() {
9
+ return isAuthorizationResponseSuccess() || isAuthorizationResponseError();
10
+ }
11
+ AuthorizationResponseUtil.isAuthorizationResponse = isAuthorizationResponse;
12
+ function isAuthorizationResponseSuccess() {
13
+ const request = node_1.Context.getRequest();
14
+ const query = request.query || {};
15
+ return !!(query[oauth2_core_1.OAuth2ParameterNames.CODE] && query[oauth2_core_1.OAuth2ParameterNames.STATE]);
16
+ }
17
+ AuthorizationResponseUtil.isAuthorizationResponseSuccess = isAuthorizationResponseSuccess;
18
+ function isAuthorizationResponseError() {
19
+ const request = node_1.Context.getRequest();
20
+ const query = request.query || {};
21
+ return !!(query[oauth2_core_1.OAuth2ParameterNames.ERROR] && query[oauth2_core_1.OAuth2ParameterNames.STATE]);
22
+ }
23
+ AuthorizationResponseUtil.isAuthorizationResponseError = isAuthorizationResponseError;
24
+ function convert(redirectUri) {
25
+ const request = node_1.Context.getRequest();
26
+ const query = request.query || {};
27
+ const code = query[oauth2_core_1.OAuth2ParameterNames.CODE];
28
+ const errorCode = query[oauth2_core_1.OAuth2ParameterNames.ERROR];
29
+ const state = query[oauth2_core_1.OAuth2ParameterNames.STATE];
30
+ if (code) {
31
+ return {
32
+ code,
33
+ redirectUri,
34
+ state
35
+ };
36
+ }
37
+ else {
38
+ const errorDescription = query[oauth2_core_1.OAuth2ParameterNames.ERROR_DESCRIPTION];
39
+ const errorUri = query[oauth2_core_1.OAuth2ParameterNames.ERROR_URI];
40
+ return {
41
+ redirectUri,
42
+ state,
43
+ error: {
44
+ description: errorDescription,
45
+ uri: errorUri,
46
+ errorCode
47
+ },
48
+ };
49
+ }
50
+ }
51
+ AuthorizationResponseUtil.convert = convert;
52
+ })(AuthorizationResponseUtil = exports.AuthorizationResponseUtil || (exports.AuthorizationResponseUtil = {}));
53
+ //# sourceMappingURL=authorization-response-util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization-response-util.js","sourceRoot":"","sources":["../../../src/node/utils/authorization-response-util.ts"],"names":[],"mappings":";;;AAAA,+CAA+C;AAC/C,qDAAkF;AAElF,IAAiB,yBAAyB,CA8CzC;AA9CD,WAAiB,yBAAyB;IAEtC,SAAgB,uBAAuB;QACnC,OAAO,8BAA8B,EAAE,IAAI,4BAA4B,EAAE,CAAC;IAC9E,CAAC;IAFe,iDAAuB,0BAEtC,CAAA;IAED,SAAgB,8BAA8B;QAC1C,MAAM,OAAO,GAAG,cAAO,CAAC,UAAU,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;QAClC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,kCAAoB,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,kCAAoB,CAAC,KAAK,CAAC,CAAC,CAAC;IACrF,CAAC;IAJe,wDAA8B,iCAI7C,CAAA;IAED,SAAgB,4BAA4B;QACxC,MAAM,OAAO,GAAG,cAAO,CAAC,UAAU,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;QAClC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,kCAAoB,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,kCAAoB,CAAC,KAAK,CAAC,CAAC,CAAC;IACtF,CAAC;IAJe,sDAA4B,+BAI3C,CAAA;IAED,SAAgB,OAAO,CAAC,WAAmB;QACvC,MAAM,OAAO,GAAG,cAAO,CAAC,UAAU,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;QAElC,MAAM,IAAI,GAAG,KAAK,CAAC,kCAAoB,CAAC,IAAI,CAAC,CAAC;QAC9C,MAAM,SAAS,GAAG,KAAK,CAAC,kCAAoB,CAAC,KAAK,CAAC,CAAC;QACpD,MAAM,KAAK,GAAG,KAAK,CAAC,kCAAoB,CAAC,KAAK,CAAC,CAAC;QAEhD,IAAI,IAAI,EAAE;YACN,OAA8B;gBAC1B,IAAI;gBACJ,WAAW;gBACX,KAAK;aACR,CAAC;SACL;aAAM;YACH,MAAM,gBAAgB,GAAG,KAAK,CAAC,kCAAoB,CAAC,iBAAiB,CAAC,CAAC;YACvE,MAAM,QAAQ,GAAG,KAAK,CAAC,kCAAoB,CAAC,SAAS,CAAC,CAAC;YACvD,OAA8B;gBAC1B,WAAW;gBACX,KAAK;gBACL,KAAK,EAAE;oBACH,WAAW,EAAE,gBAAgB;oBAC7B,GAAG,EAAE,QAAQ;oBACb,SAAS;iBACZ;aACJ,CAAC;SACL;IACL,CAAC;IA3Be,iCAAO,UA2BtB,CAAA;AACL,CAAC,EA9CgB,yBAAyB,GAAzB,iCAAyB,KAAzB,iCAAyB,QA8CzC"}
@@ -0,0 +1,3 @@
1
+ export * from './authorization-response-util';
2
+ export * from './authorization-grant-request-entity-util';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2CAA2C,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./authorization-response-util"), exports);
18
+ __exportStar(require("./authorization-grant-request-entity-util"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA8C;AAC9C,4EAA0D"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=package.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.spec.d.ts","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ describe('oauth2 client package', () => {
2
+ it('support code coverage statistics', () => { });
3
+ });
4
+ //# sourceMappingURL=package.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":"AAAA,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IAEnC,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AACrD,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@celljs/oauth2-client",
3
+ "version": "3.0.0",
4
+ "description": "",
5
+ "main": "lib/node/index.js",
6
+ "typings": "lib/node/index.d.ts",
7
+ "dependencies": {
8
+ "@celljs/core": "3.0.0",
9
+ "@celljs/http": "3.0.0",
10
+ "@celljs/oauth2-core": "3.0.0",
11
+ "@celljs/oauth2-jose": "3.0.0",
12
+ "@celljs/security": "3.0.0",
13
+ "@celljs/web": "3.0.0",
14
+ "axios": "^0.26.1",
15
+ "crypto-js": "^3.1.47",
16
+ "jose": "^4.9.3",
17
+ "qs": "^6.9.4"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "keywords": [
23
+ "cell-component"
24
+ ],
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/cellbang/cell.git"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/cellbang/cell/issues"
32
+ },
33
+ "homepage": "https://github.com/cellbang/cell",
34
+ "files": [
35
+ "lib",
36
+ "src",
37
+ "cell.yml"
38
+ ],
39
+ "scripts": {
40
+ "lint": "cell-component lint",
41
+ "build": "cell-component build",
42
+ "watch": "cell-component watch",
43
+ "clean": "cell-component clean",
44
+ "test": "cell-component test:js"
45
+ },
46
+ "devDependencies": {
47
+ "@celljs/component": "3.0.0",
48
+ "@types/crypto-js": "^3.1.47"
49
+ },
50
+ "gitHead": "c0ef8d269e33a795406bcbb240cac4b845c6c24c"
51
+ }
@@ -0,0 +1,26 @@
1
+ import { Authentication, USERNAME_PASSWORD_AUTHENTICATION_PROVIDER_PRIORITY } from '@celljs/security/lib/node';
2
+ import { ClientRegistration } from '../registration';
3
+ import { AuthorizationExchange, AccessToken, RefreshToken } from '@celljs/oauth2-core';
4
+
5
+ export const INVALID_ID_TOKEN_ERROR_CODE = 'invalid_id_token';
6
+ export const INVALID_NONCE_ERROR_CODE = 'invalid_nonce';
7
+ export const AUTHORIZATION_REQUEST_NOT_FOUND_ERROR_CODE = 'authorization_request_not_found';
8
+ export const CLIENT_REGISTRATION_NOT_FOUND_ERROR_CODE = 'client_registration_not_found';
9
+
10
+ export const OAUTH2_AUTHENTICATION_PROVIDER_PRIORITY = USERNAME_PASSWORD_AUTHENTICATION_PROVIDER_PRIORITY + 100;
11
+ export const OIDC_AUTHENTICATION_PROVIDER_PRIORITY = OAUTH2_AUTHENTICATION_PROVIDER_PRIORITY + 100;
12
+
13
+ export interface OAuth2LoginAuthentication extends Authentication {
14
+ clientRegistration: ClientRegistration;
15
+ authorizationExchange: AuthorizationExchange;
16
+ accessToken: AccessToken;
17
+ refreshToken?: RefreshToken;
18
+ }
19
+
20
+ export interface OAuth2AuthorizationCodeAuthentication extends Authentication {
21
+ clientRegistration: ClientRegistration;
22
+ authorizationExchange: AuthorizationExchange;
23
+ accessToken: AccessToken;
24
+ refreshToken?: RefreshToken;
25
+ additionalParameters: { [key: string]: any };
26
+ }
@@ -0,0 +1,3 @@
1
+ export * from './authentication-protocol';
2
+ export * from './oidc-authentication-provider';
3
+ export * from './oauth2-authentication-provider';
@@ -0,0 +1,163 @@
1
+ import { Component, Autowired, Value } from '@celljs/core';
2
+ import { Context, RequestMatcher } from '@celljs/web/lib/node';
3
+ import { PathResolver, ENDPOINT } from '@celljs/web';
4
+ import { AuthorizationResponseUtil } from '../utils';
5
+ import { OAuth2AuthenticationError, AuthorizationRequest, OAuth2ParameterNames, OAuth2AuthorizationError,
6
+ OAuth2ErrorCodes, OidcScopes, AccessTokenResponse } from '@celljs/oauth2-core';
7
+ import { AuthorizationRequestManager, AuthorizedClientManager, AuthorizedClient, INVALID_STATE_PARAMETER_ERROR_CODE } from '../authorization';
8
+ import { ClientRegistration, ClientRegistrationManager } from '../registration';
9
+ import { AuthorizationCodeTokenResponseClient, OAuth2UserRequest } from '../endpoint';
10
+ import { AuthenticationProvider, UserChecker, UserService, UserMapper } from '@celljs/security/lib/node';
11
+ import { User } from '@celljs/security';
12
+
13
+ import { OAUTH2_AUTHENTICATION_PROVIDER_PRIORITY, AUTHORIZATION_REQUEST_NOT_FOUND_ERROR_CODE,
14
+ CLIENT_REGISTRATION_NOT_FOUND_ERROR_CODE, OAuth2LoginAuthentication } from './authentication-protocol';
15
+ import { OAuth2UserService } from '../user';
16
+
17
+ @Component(AuthenticationProvider)
18
+ export class OAuth2AuthenticationProvider implements AuthenticationProvider {
19
+
20
+ @Value('cell.oauth2.client')
21
+ protected readonly options: any;
22
+
23
+ @Autowired(AuthorizationRequestManager)
24
+ protected readonly authorizationRequestManager: AuthorizationRequestManager<AuthorizationRequest>;
25
+
26
+ @Autowired(ClientRegistrationManager)
27
+ protected readonly clientRegistrationManager: ClientRegistrationManager;
28
+
29
+ @Autowired(AuthorizedClientManager)
30
+ protected readonly authorizedClientManager: AuthorizedClientManager<AuthorizedClient>;
31
+
32
+ @Autowired(OAuth2UserService)
33
+ protected readonly userService: UserService<OAuth2UserRequest, User>;
34
+
35
+ @Autowired(UserChecker)
36
+ protected readonly userChecker: UserChecker;
37
+
38
+ @Autowired(UserMapper)
39
+ protected readonly userMapper: UserMapper;
40
+
41
+ @Autowired(AuthorizationCodeTokenResponseClient)
42
+ protected readonly authorizationCodeTokenResponseClient: AuthorizationCodeTokenResponseClient;
43
+
44
+ @Autowired(RequestMatcher)
45
+ protected readonly requestMatcher: RequestMatcher;
46
+
47
+ @Autowired(PathResolver)
48
+ protected readonly pathResolver: PathResolver;
49
+
50
+ @Value(ENDPOINT)
51
+ protected readonly endpoint: string;
52
+
53
+ priority = OAUTH2_AUTHENTICATION_PROVIDER_PRIORITY;
54
+
55
+ protected checkScopes(scopes: string[]) {
56
+ // Section 3.1.2.1 Authentication Request -
57
+ // https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest scope
58
+ // REQUIRED. OpenID Connect requests MUST contain the "openid" scope value.
59
+ if (scopes.indexOf(OidcScopes.OPENID) !== -1) {
60
+ // This is an OpenID Connect Authentication Request so return null
61
+ // and let OidcAuthorizationCodeAuthenticationProvider handle it instead
62
+ return false;
63
+ }
64
+ return true;
65
+ }
66
+
67
+ protected getUserinfo(clientRegistration: ClientRegistration, tokenResponse: AccessTokenResponse, additionalParameters: { [key: string]: string }) {
68
+ return this.userService.load({
69
+ clientRegistration,
70
+ accessToken: tokenResponse.accessToken,
71
+ additionalParameters
72
+ });
73
+ }
74
+
75
+ async authenticate(): Promise<OAuth2LoginAuthentication | undefined> {
76
+ if (!AuthorizationResponseUtil.isAuthorizationResponse()) {
77
+ throw new OAuth2AuthenticationError({
78
+ errorCode: OAuth2ErrorCodes.INVALID_REQUEST
79
+ });
80
+ }
81
+
82
+ const authorizationRequest = await this.authorizationRequestManager.get();
83
+ if (!authorizationRequest) {
84
+ throw new OAuth2AuthenticationError({
85
+ errorCode: AUTHORIZATION_REQUEST_NOT_FOUND_ERROR_CODE
86
+ });
87
+ }
88
+
89
+ if (!this.checkScopes(authorizationRequest.scopes)) {
90
+ return;
91
+ }
92
+
93
+ const registrationId = authorizationRequest.attributes[OAuth2ParameterNames.REGISTRATION_ID];
94
+ const clientRegistration = await this.clientRegistrationManager.get(registrationId);
95
+ if (!clientRegistration) {
96
+ throw new OAuth2AuthenticationError({
97
+ errorCode: CLIENT_REGISTRATION_NOT_FOUND_ERROR_CODE,
98
+ description: `Client Registration not found with Id: ${registrationId}`
99
+ });
100
+ }
101
+
102
+ const redirectUri = await this.pathResolver.resolve(this.endpoint, Context.getRequest().path);
103
+ const authorizationResponse = AuthorizationResponseUtil.convert(redirectUri);
104
+
105
+ if (authorizationResponse.error) {
106
+ throw new OAuth2AuthenticationError(authorizationResponse.error);
107
+ }
108
+ if (authorizationResponse.state !== authorizationRequest.state) {
109
+ throw new OAuth2AuthenticationError({
110
+ errorCode: INVALID_STATE_PARAMETER_ERROR_CODE
111
+ });
112
+ }
113
+
114
+ let tokenResponse: AccessTokenResponse;
115
+ try {
116
+ tokenResponse = await this.authorizationCodeTokenResponseClient.getTokenResponse({
117
+ authorizationGrantType: clientRegistration.authorizationGrantType,
118
+ clientRegistration,
119
+ authorizationExchange: {
120
+ authorizationRequest, authorizationResponse
121
+ }
122
+ });
123
+ } catch (error) {
124
+ if (error instanceof OAuth2AuthorizationError) {
125
+ throw new OAuth2AuthenticationError(error.oauth2Error);
126
+ }
127
+ throw error;
128
+ }
129
+
130
+ const { additionalParameters } = tokenResponse;
131
+
132
+ const user = await this.getUserinfo(clientRegistration, tokenResponse, additionalParameters);
133
+ await this.userChecker.check(user);
134
+ await this.userMapper.map(user);
135
+
136
+ await this.authorizedClientManager.save({
137
+ clientRegistration,
138
+ accessToken: tokenResponse.accessToken,
139
+ refreshToken: tokenResponse.refreshToken,
140
+ principalName: user.username
141
+ }, user.username);
142
+
143
+ await this.authorizationRequestManager.remove();
144
+
145
+ return {
146
+ name: user.username,
147
+ principal: user,
148
+ credentials: '',
149
+ policies: user.policies,
150
+ clientRegistration,
151
+ authorizationExchange: { authorizationRequest, authorizationResponse },
152
+ accessToken: tokenResponse.accessToken,
153
+ refreshToken: tokenResponse.refreshToken,
154
+ authenticated: true
155
+ };
156
+
157
+ }
158
+
159
+ async support(): Promise<boolean> {
160
+ return !!await this.requestMatcher.match(await this.pathResolver.resolve(this.options.redirectLoginPath));
161
+ }
162
+
163
+ }
@@ -0,0 +1,60 @@
1
+ import { Component, Autowired } from '@celljs/core';
2
+ import { OAuth2AuthenticationError, OidcScopes, AccessTokenResponse, OidcParameterNames} from '@celljs/oauth2-core';
3
+ import { IdTokenJwtDecoderFactory, ClientRegistration } from '../registration';
4
+ import { Jwt } from '@celljs/oauth2-jose';
5
+ import { errors } from 'jose';
6
+ import { OidcUserRequest, OidcUserService } from '../user';
7
+ import { UserService, AuthenticationProvider } from '@celljs/security/lib/node';
8
+ import { User } from '@celljs/security';
9
+ import { OIDC_AUTHENTICATION_PROVIDER_PRIORITY, INVALID_ID_TOKEN_ERROR_CODE } from './authentication-protocol';
10
+ import { OAuth2AuthenticationProvider } from './oauth2-authentication-provider';
11
+
12
+ @Component(AuthenticationProvider)
13
+ export class OidcAuthenticationProvider extends OAuth2AuthenticationProvider {
14
+
15
+ @Autowired(IdTokenJwtDecoderFactory)
16
+ protected readonly idTokenJwtDecoderFactory: IdTokenJwtDecoderFactory;
17
+
18
+ @Autowired(OidcUserService)
19
+ protected override readonly userService: UserService<OidcUserRequest, User>;
20
+
21
+ override priority = OIDC_AUTHENTICATION_PROVIDER_PRIORITY;
22
+
23
+ protected override checkScopes(scopes: string[]) {
24
+ // Section 3.1.2.1 Authentication Request - https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
25
+ // scope
26
+ // REQUIRED. OpenID Connect requests MUST contain the "openid" scope value.
27
+ if (scopes.indexOf(OidcScopes.OPENID) === -1) {
28
+ // This is NOT an OpenID Connect Authentication Request so return undefined
29
+ // and let OAuth2AuthenticationProvider handle it instead
30
+ return false;
31
+ }
32
+ return true;
33
+ }
34
+
35
+ protected override async getUserinfo(clientRegistration: ClientRegistration, tokenResponse: AccessTokenResponse, additionalParameters: { [key: string]: string }) {
36
+ const idToken = await this.createOidcToken(clientRegistration, tokenResponse);
37
+
38
+ return this.userService.load({
39
+ idToken,
40
+ clientRegistration,
41
+ accessToken: tokenResponse.accessToken,
42
+ additionalParameters
43
+ });
44
+ }
45
+
46
+ protected async createOidcToken(clientRegistration: ClientRegistration, tokenResponse: AccessTokenResponse): Promise<Jwt> {
47
+ const jwtDecoder = await this.idTokenJwtDecoderFactory.create(clientRegistration);
48
+ try {
49
+ return jwtDecoder.decode(tokenResponse.additionalParameters[OidcParameterNames.ID_TOKEN]);
50
+ } catch (error) {
51
+ if (error instanceof errors.JOSEError) {
52
+ throw new OAuth2AuthenticationError({
53
+ errorCode: INVALID_ID_TOKEN_ERROR_CODE,
54
+ description: error.message
55
+ });
56
+ }
57
+ throw error;
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,16 @@
1
+ import { AuthorizedClientProvider, AuthorizationContext, AuthorizedClient } from './authorization-protocol';
2
+ import { AuthorizationGrantType } from '@celljs/oauth2-core';
3
+ import { ClientAuthorizationRequiredError } from '../error';
4
+ import { Component } from '@celljs/core';
5
+
6
+ @Component(AuthorizedClientProvider)
7
+ export class AuthorizationCodeAuthorizedClientProvider implements AuthorizedClientProvider {
8
+ async provide(context: AuthorizationContext): Promise<AuthorizedClient | undefined> {
9
+ const { clientRegistration, authorizedClient } = context;
10
+ if (AuthorizationGrantType.AuthorizationCode === clientRegistration.authorizationGrantType && !authorizedClient) {
11
+ throw new ClientAuthorizationRequiredError(clientRegistration.registrationId);
12
+ }
13
+ return;
14
+ }
15
+
16
+ }