@rxap/oauth 12.1.0 → 13.0.0-next.2
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/_theming.scss +1 -1
- package/esm2020/index.mjs +17 -0
- package/esm2020/lib/container/container.component.mjs +38 -0
- package/esm2020/lib/container/container.component.module.mjs +22 -0
- package/esm2020/lib/get-o-auth-profile.method.mjs +40 -0
- package/esm2020/lib/loading/loading.component.mjs +12 -0
- package/esm2020/lib/loading/loading.component.module.mjs +26 -0
- package/esm2020/lib/o-auth-extract.guard.mjs +55 -0
- package/esm2020/lib/o-auth-redirect.guard.mjs +31 -0
- package/esm2020/lib/o-auth-routing.module.mjs +25 -0
- package/esm2020/lib/o-auth.method.mjs +111 -0
- package/esm2020/lib/o-auth.module.mjs +27 -0
- package/esm2020/lib/o-auth.service.mjs +303 -0
- package/esm2020/lib/profile.resolve.mjs +37 -0
- package/esm2020/lib/routes.mjs +26 -0
- package/esm2020/lib/sign-in-with-redirect/sign-in-with-redirect.component.mjs +47 -0
- package/esm2020/lib/sign-in-with-redirect/sign-in-with-redirect.component.module.mjs +38 -0
- package/esm2020/lib/tokens.mjs +17 -0
- package/esm2020/rxap-oauth.mjs +5 -0
- package/esm2020/single-sign-on/lib/continue/continue.component.mjs +70 -0
- package/esm2020/single-sign-on/lib/continue/continue.component.module.mjs +42 -0
- package/esm2020/single-sign-on/lib/error/error.component.mjs +44 -0
- package/esm2020/single-sign-on/lib/error/error.component.module.mjs +30 -0
- package/esm2020/single-sign-on/lib/o-auth-single-sign-on-routing.module.mjs +50 -0
- package/esm2020/single-sign-on/lib/o-auth-single-sign-on.guard.mjs +69 -0
- package/esm2020/single-sign-on/lib/o-auth-single-sign-on.service.mjs +77 -0
- package/esm2020/single-sign-on/lib/routes.mjs +33 -0
- package/esm2020/single-sign-on/lib/tokens.mjs +10 -0
- package/esm2020/single-sign-on/public_api.mjs +10 -0
- package/esm2020/single-sign-on/rxap-oauth-single-sign-on.mjs +5 -0
- package/fesm2015/rxap-oauth-single-sign-on.mjs +408 -0
- package/fesm2015/rxap-oauth-single-sign-on.mjs.map +1 -0
- package/fesm2015/{rxap-oauth.js → rxap-oauth.mjs} +137 -171
- package/fesm2015/rxap-oauth.mjs.map +1 -0
- package/fesm2020/rxap-oauth-single-sign-on.mjs +392 -0
- package/fesm2020/rxap-oauth-single-sign-on.mjs.map +1 -0
- package/fesm2020/rxap-oauth.mjs +801 -0
- package/fesm2020/rxap-oauth.mjs.map +1 -0
- package/lib/o-auth.method.d.ts +0 -2
- package/lib/o-auth.service.d.ts +2 -7
- package/package.json +43 -31
- package/single-sign-on/package.json +5 -5
- package/bundles/rxap-oauth-single-sign-on.umd.js +0 -811
- package/bundles/rxap-oauth-single-sign-on.umd.js.map +0 -1
- package/bundles/rxap-oauth.umd.js +0 -1373
- package/bundles/rxap-oauth.umd.js.map +0 -1
- package/esm2015/index.js +0 -17
- package/esm2015/index.js.map +0 -1
- package/esm2015/lib/container/container.component.js +0 -45
- package/esm2015/lib/container/container.component.js.map +0 -1
- package/esm2015/lib/container/container.component.module.js +0 -22
- package/esm2015/lib/container/container.component.module.js.map +0 -1
- package/esm2015/lib/get-o-auth-profile.method.js +0 -41
- package/esm2015/lib/get-o-auth-profile.method.js.map +0 -1
- package/esm2015/lib/loading/loading.component.js +0 -18
- package/esm2015/lib/loading/loading.component.js.map +0 -1
- package/esm2015/lib/loading/loading.component.module.js +0 -26
- package/esm2015/lib/loading/loading.component.module.js.map +0 -1
- package/esm2015/lib/o-auth-extract.guard.js +0 -55
- package/esm2015/lib/o-auth-extract.guard.js.map +0 -1
- package/esm2015/lib/o-auth-redirect.guard.js +0 -34
- package/esm2015/lib/o-auth-redirect.guard.js.map +0 -1
- package/esm2015/lib/o-auth-routing.module.js +0 -25
- package/esm2015/lib/o-auth-routing.module.js.map +0 -1
- package/esm2015/lib/o-auth.method.js +0 -120
- package/esm2015/lib/o-auth.method.js.map +0 -1
- package/esm2015/lib/o-auth.module.js +0 -28
- package/esm2015/lib/o-auth.module.js.map +0 -1
- package/esm2015/lib/o-auth.service.js +0 -336
- package/esm2015/lib/o-auth.service.js.map +0 -1
- package/esm2015/lib/profile.resolve.js +0 -40
- package/esm2015/lib/profile.resolve.js.map +0 -1
- package/esm2015/lib/routes.js +0 -26
- package/esm2015/lib/routes.js.map +0 -1
- package/esm2015/lib/sign-in-with-redirect/sign-in-with-redirect.component.js +0 -54
- package/esm2015/lib/sign-in-with-redirect/sign-in-with-redirect.component.js.map +0 -1
- package/esm2015/lib/sign-in-with-redirect/sign-in-with-redirect.component.module.js +0 -38
- package/esm2015/lib/sign-in-with-redirect/sign-in-with-redirect.component.module.js.map +0 -1
- package/esm2015/lib/tokens.js +0 -17
- package/esm2015/lib/tokens.js.map +0 -1
- package/esm2015/rxap-oauth.js +0 -5
- package/esm2015/rxap-oauth.js.map +0 -1
- package/esm2015/single-sign-on/lib/continue/continue.component.js +0 -77
- package/esm2015/single-sign-on/lib/continue/continue.component.js.map +0 -1
- package/esm2015/single-sign-on/lib/continue/continue.component.module.js +0 -42
- package/esm2015/single-sign-on/lib/continue/continue.component.module.js.map +0 -1
- package/esm2015/single-sign-on/lib/error/error.component.js +0 -51
- package/esm2015/single-sign-on/lib/error/error.component.js.map +0 -1
- package/esm2015/single-sign-on/lib/error/error.component.module.js +0 -30
- package/esm2015/single-sign-on/lib/error/error.component.module.js.map +0 -1
- package/esm2015/single-sign-on/lib/o-auth-single-sign-on-routing.module.js +0 -50
- package/esm2015/single-sign-on/lib/o-auth-single-sign-on-routing.module.js.map +0 -1
- package/esm2015/single-sign-on/lib/o-auth-single-sign-on.guard.js +0 -72
- package/esm2015/single-sign-on/lib/o-auth-single-sign-on.guard.js.map +0 -1
- package/esm2015/single-sign-on/lib/o-auth-single-sign-on.service.js +0 -85
- package/esm2015/single-sign-on/lib/o-auth-single-sign-on.service.js.map +0 -1
- package/esm2015/single-sign-on/lib/routes.js +0 -33
- package/esm2015/single-sign-on/lib/routes.js.map +0 -1
- package/esm2015/single-sign-on/lib/tokens.js +0 -10
- package/esm2015/single-sign-on/lib/tokens.js.map +0 -1
- package/esm2015/single-sign-on/public_api.js +0 -10
- package/esm2015/single-sign-on/public_api.js.map +0 -1
- package/esm2015/single-sign-on/rxap-oauth-single-sign-on.js +0 -5
- package/esm2015/single-sign-on/rxap-oauth-single-sign-on.js.map +0 -1
- package/fesm2015/rxap-oauth-single-sign-on.js +0 -416
- package/fesm2015/rxap-oauth-single-sign-on.js.map +0 -1
- package/fesm2015/rxap-oauth.js.map +0 -1
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
|
-
import { Injectable, Inject } from '@angular/core';
|
|
3
|
-
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
4
|
-
import * as i0 from "@angular/core";
|
|
5
|
-
import * as i1 from "@angular/common/http";
|
|
6
|
-
export function IsOAuthMethodWithRefreshTokenParameters(parameters) {
|
|
7
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
8
|
-
return parameters.hasOwnProperty('refreshToken');
|
|
9
|
-
}
|
|
10
|
-
export function IsOAuthMethodWithUsernamePasswordParameters(parameters) {
|
|
11
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
12
|
-
return (parameters.hasOwnProperty('username') &&
|
|
13
|
-
parameters.hasOwnProperty('password'));
|
|
14
|
-
}
|
|
15
|
-
export function AssertOAuthMethodWithUsernamePasswordParameters(parameters) {
|
|
16
|
-
if (!IsOAuthMethodWithUsernamePasswordParameters(parameters)) {
|
|
17
|
-
throw new Error('The grant type password requires the parameters username and password');
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export function AssertOAuthMethodWithRefreshTokenParameters(parameters) {
|
|
21
|
-
if (!IsOAuthMethodWithRefreshTokenParameters(parameters)) {
|
|
22
|
-
throw new Error('The grant type refresh token requires the parameters refreshToken');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export function AssertOAuthMethodParameters(parameters) {
|
|
26
|
-
if (!parameters.authEndpoint) {
|
|
27
|
-
throw new Error('The authEndpoint parameter must be defined');
|
|
28
|
-
}
|
|
29
|
-
if (!parameters.secret) {
|
|
30
|
-
throw new Error('The secret parameter must be defined');
|
|
31
|
-
}
|
|
32
|
-
if (parameters.grantType) {
|
|
33
|
-
switch (parameters.grantType) {
|
|
34
|
-
case 'password':
|
|
35
|
-
AssertOAuthMethodWithUsernamePasswordParameters(parameters);
|
|
36
|
-
break;
|
|
37
|
-
case 'refresh_token':
|
|
38
|
-
AssertOAuthMethodWithRefreshTokenParameters(parameters);
|
|
39
|
-
break;
|
|
40
|
-
default:
|
|
41
|
-
throw new Error(`The grant type '${parameters.grantType}' is not supported`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
if (!IsOAuthMethodWithRefreshTokenParameters(parameters) &&
|
|
46
|
-
!IsOAuthMethodWithUsernamePasswordParameters(parameters)) {
|
|
47
|
-
throw new Error('Either the refresh token or the username and password must be defined');
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
export class OAuthMethod {
|
|
52
|
-
constructor(http) {
|
|
53
|
-
this.http = http;
|
|
54
|
-
}
|
|
55
|
-
call(parameters) {
|
|
56
|
-
var _a;
|
|
57
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
AssertOAuthMethodParameters(parameters);
|
|
59
|
-
const params = new URLSearchParams();
|
|
60
|
-
const grantType = this.getGrantType(parameters);
|
|
61
|
-
params.append('grant_type', grantType);
|
|
62
|
-
switch (grantType) {
|
|
63
|
-
case 'password':
|
|
64
|
-
AssertOAuthMethodWithUsernamePasswordParameters(parameters);
|
|
65
|
-
params.append('username', parameters.username);
|
|
66
|
-
params.append('password', parameters.password);
|
|
67
|
-
break;
|
|
68
|
-
case 'refresh_token':
|
|
69
|
-
AssertOAuthMethodWithRefreshTokenParameters(parameters);
|
|
70
|
-
params.append('refresh_token', parameters.refreshToken);
|
|
71
|
-
break;
|
|
72
|
-
default:
|
|
73
|
-
throw new Error('Not supported grant type');
|
|
74
|
-
}
|
|
75
|
-
let headers = new HttpHeaders();
|
|
76
|
-
headers = headers.append('Content-type', 'application/x-www-form-urlencoded; charset=utf-8');
|
|
77
|
-
if (parameters.secret && parameters.clientId) {
|
|
78
|
-
params.append('client_id', parameters.clientId);
|
|
79
|
-
params.append('client_secret', parameters.secret);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
headers = headers.append('Authorization', `Basic ${parameters.secret}`);
|
|
83
|
-
}
|
|
84
|
-
const response = yield this.http
|
|
85
|
-
.post(parameters.authEndpoint, params.toString(), {
|
|
86
|
-
headers,
|
|
87
|
-
withCredentials: (_a = parameters.withCredentials) !== null && _a !== void 0 ? _a : true,
|
|
88
|
-
})
|
|
89
|
-
.toPromise();
|
|
90
|
-
return {
|
|
91
|
-
accessToken: response.access_token,
|
|
92
|
-
refreshToken: response.refresh_token,
|
|
93
|
-
expiresIn: response.expires_in,
|
|
94
|
-
expiresAt: new Date(Date.now() + response.expires_in * 1000),
|
|
95
|
-
};
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
getGrantType(parameters) {
|
|
99
|
-
if (parameters.grantType) {
|
|
100
|
-
return parameters.grantType;
|
|
101
|
-
}
|
|
102
|
-
if (IsOAuthMethodWithRefreshTokenParameters(parameters)) {
|
|
103
|
-
return 'refresh_token';
|
|
104
|
-
}
|
|
105
|
-
if (IsOAuthMethodWithUsernamePasswordParameters(parameters)) {
|
|
106
|
-
return 'password';
|
|
107
|
-
}
|
|
108
|
-
throw new Error('Could not guess the grant type');
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
OAuthMethod.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OAuthMethod, deps: [{ token: HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
112
|
-
OAuthMethod.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OAuthMethod, providedIn: 'root' });
|
|
113
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OAuthMethod, decorators: [{
|
|
114
|
-
type: Injectable,
|
|
115
|
-
args: [{ providedIn: 'root' }]
|
|
116
|
-
}], ctorParameters: function () { return [{ type: i1.HttpClient, decorators: [{
|
|
117
|
-
type: Inject,
|
|
118
|
-
args: [HttpClient]
|
|
119
|
-
}] }]; } });
|
|
120
|
-
//# sourceMappingURL=o-auth.method.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"o-auth.method.js","sourceRoot":"","sources":["../../../../../libs/oauth/src/lib/o-auth.method.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EACV,MAAM,EACP,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,UAAU,EACV,WAAW,EACZ,MAAM,sBAAsB,CAAC;;;AAyB9B,MAAM,UAAU,uCAAuC,CACrD,UAAiC;IAEjC,iDAAiD;IACjD,OAAO,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,2CAA2C,CACzD,UAAiC;IAEjC,iDAAiD;IACjD,OAAO,CACL,UAAU,CAAC,cAAc,CAAC,UAAU,CAAC;QACrC,UAAU,CAAC,cAAc,CAAC,UAAU,CAAC,CACtC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,+CAA+C,CAC7D,UAAiC;IAEjC,IAAI,CAAC,2CAA2C,CAAC,UAAU,CAAC,EAAE;QAC5D,MAAM,IAAI,KAAK,CACb,uEAAuE,CACxE,CAAC;KACH;AACH,CAAC;AAED,MAAM,UAAU,2CAA2C,CACzD,UAAiC;IAEjC,IAAI,CAAC,uCAAuC,CAAC,UAAU,CAAC,EAAE;QACxD,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;KACH;AACH,CAAC;AAED,MAAM,UAAU,2BAA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ACxB,OAAO,UAAU,CAAC,SAAS,CAAC;SAC7B;QAED,IAAI,uCAAuC,CAAC,UAAU,CAAC,EAAE;YACvD,OAAO,eAAe,CAAC;SACxB;QAED,IAAI,2CAA2C,CAAC,UAAU,CAAC,EAAE;YAC3D,OAAO,UAAU,CAAC;SACnB;QAED,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;;yGAxEU,WAAW,kBAIZ,UAAU;6GAJT,WAAW,cADE,MAAM;4FACnB,WAAW;kBADvB,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;0BAK7B,MAAM;2BAAC,UAAU","sourcesContent":["import {\n Injectable,\n Inject\n} from '@angular/core';\nimport {\n HttpClient,\n HttpHeaders\n} from '@angular/common/http';\nimport { Method } from '@rxap/utilities/rxjs';\n\nexport interface OAuthMethodWithUsernamePasswordParameters {\n grantType?: string;\n username: string;\n password: string;\n secret: string;\n clientId?: string;\n authEndpoint: string;\n}\n\nexport interface OAuthMethodWithRefreshTokenParameters {\n grantType?: string;\n refreshToken: string;\n secret: string;\n clientId?: string;\n authEndpoint: string;\n}\n\nexport type OAuthMethodParameters = (\n | OAuthMethodWithUsernamePasswordParameters\n | OAuthMethodWithRefreshTokenParameters\n) & { withCredentials?: boolean };\n\nexport function IsOAuthMethodWithRefreshTokenParameters(\n parameters: OAuthMethodParameters\n): parameters is OAuthMethodWithRefreshTokenParameters {\n // eslint-disable-next-line no-prototype-builtins\n return parameters.hasOwnProperty('refreshToken');\n}\n\nexport function IsOAuthMethodWithUsernamePasswordParameters(\n parameters: OAuthMethodParameters\n): parameters is OAuthMethodWithUsernamePasswordParameters {\n // eslint-disable-next-line no-prototype-builtins\n return (\n parameters.hasOwnProperty('username') &&\n parameters.hasOwnProperty('password')\n );\n}\n\nexport function AssertOAuthMethodWithUsernamePasswordParameters(\n parameters: OAuthMethodParameters\n): asserts parameters is OAuthMethodWithUsernamePasswordParameters {\n if (!IsOAuthMethodWithUsernamePasswordParameters(parameters)) {\n throw new Error(\n 'The grant type password requires the parameters username and password'\n );\n }\n}\n\nexport function AssertOAuthMethodWithRefreshTokenParameters(\n parameters: OAuthMethodParameters\n): asserts parameters is OAuthMethodWithRefreshTokenParameters {\n if (!IsOAuthMethodWithRefreshTokenParameters(parameters)) {\n throw new Error(\n 'The grant type refresh token requires the parameters refreshToken'\n );\n }\n}\n\nexport function AssertOAuthMethodParameters(\n parameters: any\n): asserts parameters is OAuthMethodParameters {\n if (!parameters.authEndpoint) {\n throw new Error('The authEndpoint parameter must be defined');\n }\n if (!parameters.secret) {\n throw new Error('The secret parameter must be defined');\n }\n if (parameters.grantType) {\n switch (parameters.grantType) {\n case 'password':\n AssertOAuthMethodWithUsernamePasswordParameters(parameters);\n break;\n\n case 'refresh_token':\n AssertOAuthMethodWithRefreshTokenParameters(parameters);\n break;\n\n default:\n throw new Error(\n `The grant type '${parameters.grantType}' is not supported`\n );\n }\n } else {\n if (\n !IsOAuthMethodWithRefreshTokenParameters(parameters) &&\n !IsOAuthMethodWithUsernamePasswordParameters(parameters)\n ) {\n throw new Error(\n 'Either the refresh token or the username and password must be defined'\n );\n }\n }\n}\n\nexport interface OAuthResponse {\n access_token: string;\n refresh_token: string;\n expires_in: number;\n}\n\nexport interface OAuthMethodResponse {\n accessToken: string;\n refreshToken: string;\n expiresIn: number;\n expiresAt: Date;\n}\n\n@Injectable({ providedIn: 'root' })\nexport class OAuthMethod\n implements Method<OAuthMethodResponse, OAuthMethodParameters>\n{\n constructor(\n @Inject(HttpClient)\n private readonly http: HttpClient\n ) {}\n\n public async call(\n parameters: OAuthMethodParameters\n ): Promise<OAuthMethodResponse> {\n AssertOAuthMethodParameters(parameters);\n\n const params = new URLSearchParams();\n const grantType = this.getGrantType(parameters);\n params.append('grant_type', grantType);\n switch (grantType) {\n case 'password':\n AssertOAuthMethodWithUsernamePasswordParameters(parameters);\n params.append('username', parameters.username);\n params.append('password', parameters.password);\n break;\n\n case 'refresh_token':\n AssertOAuthMethodWithRefreshTokenParameters(parameters);\n params.append('refresh_token', parameters.refreshToken);\n break;\n\n default:\n throw new Error('Not supported grant type');\n }\n\n let headers = new HttpHeaders();\n\n headers = headers.append('Content-type', 'application/x-www-form-urlencoded; charset=utf-8');\n\n if (parameters.secret && parameters.clientId) {\n params.append('client_id', parameters.clientId);\n params.append('client_secret', parameters.secret);\n } else {\n headers = headers.append('Authorization', `Basic ${parameters.secret}`);\n }\n\n const response = await this.http\n .post<OAuthResponse>(parameters.authEndpoint, params.toString(), {\n headers,\n withCredentials: parameters.withCredentials ?? true,\n })\n .toPromise();\n\n return {\n accessToken: response.access_token,\n refreshToken: response.refresh_token,\n expiresIn: response.expires_in,\n expiresAt: new Date(Date.now() + response.expires_in * 1000),\n };\n }\n\n private getGrantType(parameters: OAuthMethodParameters) {\n if (parameters.grantType) {\n return parameters.grantType;\n }\n\n if (IsOAuthMethodWithRefreshTokenParameters(parameters)) {\n return 'refresh_token';\n }\n\n if (IsOAuthMethodWithUsernamePasswordParameters(parameters)) {\n return 'password';\n }\n\n throw new Error('Could not guess the grant type');\n }\n}\n"]}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { NgModule } from '@angular/core';
|
|
2
|
-
import { RXAP_O_AUTH_REDIRECT_SIGN_IN, RXAP_O_AUTH_REDIRECT_SIGN_OUT } from './tokens';
|
|
3
|
-
import * as i0 from "@angular/core";
|
|
4
|
-
export class OAuthModule {
|
|
5
|
-
static forRoot(options = {}) {
|
|
6
|
-
var _a, _b;
|
|
7
|
-
return {
|
|
8
|
-
ngModule: OAuthModule,
|
|
9
|
-
providers: [
|
|
10
|
-
{
|
|
11
|
-
provide: RXAP_O_AUTH_REDIRECT_SIGN_IN,
|
|
12
|
-
useValue: (_a = options.signInPath) !== null && _a !== void 0 ? _a : ['/', 'oauth', 'redirect']
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
provide: RXAP_O_AUTH_REDIRECT_SIGN_OUT,
|
|
16
|
-
useValue: (_b = options.signOutPath) !== null && _b !== void 0 ? _b : null
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
OAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
23
|
-
OAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OAuthModule });
|
|
24
|
-
OAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OAuthModule });
|
|
25
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OAuthModule, decorators: [{
|
|
26
|
-
type: NgModule
|
|
27
|
-
}] });
|
|
28
|
-
//# sourceMappingURL=o-auth.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"o-auth.module.js","sourceRoot":"","sources":["../../../../../libs/oauth/src/lib/o-auth.module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAET,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,4BAA4B,EAC5B,6BAA6B,EAC9B,MAAM,UAAU,CAAC;;AAQlB,MAAM,OAAO,WAAW;IAEf,MAAM,CAAC,OAAO,CAAC,UAA8B,EAAE;;QACpD,OAAO;YACL,QAAQ,EAAG,WAAW;YACtB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAG,4BAA4B;oBACtC,QAAQ,EAAE,MAAA,OAAO,CAAC,UAAU,mCAAI,CAAE,GAAG,EAAE,OAAO,EAAE,UAAU,CAAE;iBAC7D;gBACD;oBACE,OAAO,EAAG,6BAA6B;oBACvC,QAAQ,EAAE,MAAA,OAAO,CAAC,WAAW,mCAAI,IAAI;iBACtC;aACF;SACF,CAAC;IACJ,CAAC;;yGAhBU,WAAW;0GAAX,WAAW;0GAAX,WAAW;4FAAX,WAAW;kBADvB,QAAQ","sourcesContent":["import {\n NgModule,\n ModuleWithProviders\n} from '@angular/core';\nimport {\n RXAP_O_AUTH_REDIRECT_SIGN_IN,\n RXAP_O_AUTH_REDIRECT_SIGN_OUT\n} from './tokens';\n\nexport interface OAuthModuleOptions {\n signInPath?: string[]\n signOutPath?: string[]\n}\n\n@NgModule()\nexport class OAuthModule {\n\n public static forRoot(options: OAuthModuleOptions = {}): ModuleWithProviders<OAuthModule> {\n return {\n ngModule: OAuthModule,\n providers: [\n {\n provide: RXAP_O_AUTH_REDIRECT_SIGN_IN,\n useValue: options.signInPath ?? [ '/', 'oauth', 'redirect' ]\n },\n {\n provide: RXAP_O_AUTH_REDIRECT_SIGN_OUT,\n useValue: options.signOutPath ?? null\n }\n ]\n };\n }\n\n}\n"]}
|
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
|
-
import { Inject, Injectable, InjectionToken, Optional } from '@angular/core';
|
|
3
|
-
import { GetOAuthProfileMethod, PROFILE_AUTH_ENDPOINT } from './get-o-auth-profile.method';
|
|
4
|
-
import { OAuthMethod } from './o-auth.method';
|
|
5
|
-
import { RXAP_O_AUTH_REDIRECT_SIGN_OUT, RXAP_O_AUTH_REDIRECT_URL } from './tokens';
|
|
6
|
-
import { Router } from '@angular/router';
|
|
7
|
-
import { ReplaySubject } from 'rxjs';
|
|
8
|
-
import { AuthenticationEventType } from '@rxap/authentication';
|
|
9
|
-
import * as i0 from "@angular/core";
|
|
10
|
-
import * as i1 from "./o-auth.method";
|
|
11
|
-
import * as i2 from "./get-o-auth-profile.method";
|
|
12
|
-
import * as i3 from "@angular/router";
|
|
13
|
-
export const OAUTH_SECRET = new InjectionToken('OAUTH_SECRET');
|
|
14
|
-
export const OAUTH_AUTH_ENDPOINT = new InjectionToken('OAUTH_AUTH_ENDPOINT');
|
|
15
|
-
export const OAUTH_SSO_URL = new InjectionToken('OAUTH_SSO_URL');
|
|
16
|
-
export const OAUTH_CLIENT_ID = new InjectionToken('OAUTH_CLIENT_ID');
|
|
17
|
-
export const ACCESS_TOKEN_LOCAL_STORAGE_KEY = 'access_token';
|
|
18
|
-
export const REFRESH_TOKEN_LOCAL_STORAGE_KEY = 'refresh_token';
|
|
19
|
-
export const EXPIRES_AT_LOCAL_STORAGE_KEY = 'expires_at';
|
|
20
|
-
export const REMEMBER_LOCAL_STORAGE_KEY = 'remember';
|
|
21
|
-
export class OAuthService {
|
|
22
|
-
constructor(oAuthMethod, getOAuthProfileMethod, router, profileEndpoint = null, authEndpoint = null, secret = null, ssoUrl = null, redirectSignOut = null, redirectUrl = null, clientId = null) {
|
|
23
|
-
this.oAuthMethod = oAuthMethod;
|
|
24
|
-
this.getOAuthProfileMethod = getOAuthProfileMethod;
|
|
25
|
-
this.router = router;
|
|
26
|
-
this.profileEndpoint = profileEndpoint;
|
|
27
|
-
this.authEndpoint = authEndpoint;
|
|
28
|
-
this.secret = secret;
|
|
29
|
-
this.ssoUrl = ssoUrl;
|
|
30
|
-
this.redirectSignOut = redirectSignOut;
|
|
31
|
-
this.redirectUrl = redirectUrl;
|
|
32
|
-
this.clientId = clientId;
|
|
33
|
-
this.events$ = new ReplaySubject();
|
|
34
|
-
this._isAuthenticated = null;
|
|
35
|
-
}
|
|
36
|
-
get expiresAt() {
|
|
37
|
-
const expiresAt = this.getItem(EXPIRES_AT_LOCAL_STORAGE_KEY);
|
|
38
|
-
if (expiresAt) {
|
|
39
|
-
return new Date(parseInt(this.getItem(EXPIRES_AT_LOCAL_STORAGE_KEY), 10));
|
|
40
|
-
}
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
set expiresAt(value) {
|
|
44
|
-
if (value) {
|
|
45
|
-
this.setItem(EXPIRES_AT_LOCAL_STORAGE_KEY, value.getTime().toFixed(0));
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
this.removeItem(EXPIRES_AT_LOCAL_STORAGE_KEY);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
get refreshToken() {
|
|
52
|
-
return this.getItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY);
|
|
53
|
-
}
|
|
54
|
-
set refreshToken(value) {
|
|
55
|
-
if (value) {
|
|
56
|
-
this.setItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY, value);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
this.removeItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
get accessToken() {
|
|
63
|
-
return this.getItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY);
|
|
64
|
-
}
|
|
65
|
-
set accessToken(value) {
|
|
66
|
-
if (value) {
|
|
67
|
-
this.setItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY, value);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
this.removeItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* The time until the access token expires in seconds
|
|
75
|
-
*/
|
|
76
|
-
get expiresIn() {
|
|
77
|
-
const expiresAt = this.expiresAt;
|
|
78
|
-
if (expiresAt) {
|
|
79
|
-
return Math.round((expiresAt.getTime() - Date.now()) / 1000);
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
get remember() {
|
|
84
|
-
return !!this.getItem(REMEMBER_LOCAL_STORAGE_KEY);
|
|
85
|
-
}
|
|
86
|
-
set remember(value) {
|
|
87
|
-
if (value) {
|
|
88
|
-
this.setItem(REMEMBER_LOCAL_STORAGE_KEY, 'true');
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
this.removeItem(REMEMBER_LOCAL_STORAGE_KEY);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
get profile() {
|
|
95
|
-
return this._profile;
|
|
96
|
-
}
|
|
97
|
-
signInWithRedirect(lastUrl) {
|
|
98
|
-
if (!this.redirectUrl) {
|
|
99
|
-
throw new Error('Redirect url is not defined');
|
|
100
|
-
}
|
|
101
|
-
location.replace(`${this.ssoUrl}?redirect=${btoa(this.redirectUrl)}&secret=${this.secret}&payload=${btoa(JSON.stringify({ lastUrl }))}`);
|
|
102
|
-
}
|
|
103
|
-
isAuthenticated() {
|
|
104
|
-
var _a;
|
|
105
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
if (!this.secret) {
|
|
107
|
-
throw new Error('The oauth secret is not defined');
|
|
108
|
-
}
|
|
109
|
-
if (!this.authEndpoint) {
|
|
110
|
-
throw new Error('The oauth auth endpoint is not defined');
|
|
111
|
-
}
|
|
112
|
-
if (this._isAuthenticated !== null) {
|
|
113
|
-
return this._isAuthenticated;
|
|
114
|
-
}
|
|
115
|
-
if (this.accessToken) {
|
|
116
|
-
console.debug('Access token is defined: ' + this.accessToken);
|
|
117
|
-
if (this.expiresIn && this.expiresIn > 60) {
|
|
118
|
-
const profile = yield this.getProfile();
|
|
119
|
-
if (!profile) {
|
|
120
|
-
console.log('profile is not defined');
|
|
121
|
-
return (this._isAuthenticated = false);
|
|
122
|
-
}
|
|
123
|
-
this.authenticated({
|
|
124
|
-
refreshToken: this.refreshToken,
|
|
125
|
-
accessToken: this.accessToken,
|
|
126
|
-
expiresAt: (_a = this.expiresAt) !== null && _a !== void 0 ? _a : new Date(Date.now() + 60 * 1000),
|
|
127
|
-
expiresIn: this.expiresIn,
|
|
128
|
-
}, this.remember);
|
|
129
|
-
return (this._isAuthenticated = true);
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
this.accessToken = null;
|
|
133
|
-
this.expiresAt = null;
|
|
134
|
-
console.warn('The access token expires soon. Use refresh token instead.');
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (this.refreshToken) {
|
|
138
|
-
console.debug('Refresh token is defined: ' + this.refreshToken);
|
|
139
|
-
try {
|
|
140
|
-
yield this.signInWithRefreshToken(this.refreshToken);
|
|
141
|
-
return (this._isAuthenticated = true);
|
|
142
|
-
}
|
|
143
|
-
catch (e) {
|
|
144
|
-
if (![401, 403, 400].includes(e.status)) {
|
|
145
|
-
console.error('Could not sign in with refresh token', e.message);
|
|
146
|
-
throw e;
|
|
147
|
-
}
|
|
148
|
-
console.warn('Refresh token is expired');
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
console.warn('Unauthenticated');
|
|
152
|
-
return (this._isAuthenticated = false);
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
signInWithEmailAndPassword(email, password, remember) {
|
|
156
|
-
var _a;
|
|
157
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
-
if (!this.secret) {
|
|
159
|
-
throw new Error('The oauth secret is not defined');
|
|
160
|
-
}
|
|
161
|
-
if (!this.authEndpoint) {
|
|
162
|
-
throw new Error('The oauth auth endpoint is not defined');
|
|
163
|
-
}
|
|
164
|
-
const response = yield this.oAuthMethod.call({
|
|
165
|
-
username: email,
|
|
166
|
-
password: password,
|
|
167
|
-
authEndpoint: this.authEndpoint,
|
|
168
|
-
secret: this.secret,
|
|
169
|
-
clientId: (_a = this.clientId) !== null && _a !== void 0 ? _a : undefined
|
|
170
|
-
}).catch(e => {
|
|
171
|
-
this.events$.next({ type: AuthenticationEventType.OnAuthError });
|
|
172
|
-
throw e;
|
|
173
|
-
});
|
|
174
|
-
this.authenticated(response, remember);
|
|
175
|
-
return response;
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
getProfile() {
|
|
179
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
-
let profile = null;
|
|
181
|
-
if (!this.accessToken) {
|
|
182
|
-
throw new Error('The access token is not defined');
|
|
183
|
-
}
|
|
184
|
-
if (this.profileEndpoint) {
|
|
185
|
-
try {
|
|
186
|
-
profile = yield this.getOAuthProfileMethod.call({
|
|
187
|
-
accessToken: this.accessToken,
|
|
188
|
-
profileEndpoint: this.profileEndpoint,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
catch (e) {
|
|
192
|
-
console.error('Could not request the user profile', e.message);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
console.warn('The profile endpoint is not defined!');
|
|
197
|
-
}
|
|
198
|
-
return (this._profile = profile);
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
signOut() {
|
|
202
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
-
this.clearStorage();
|
|
204
|
-
this.accessToken = null;
|
|
205
|
-
this.refreshToken = null;
|
|
206
|
-
this.expiresAt = null;
|
|
207
|
-
this._isAuthenticated = false;
|
|
208
|
-
if (this.redirectSignOut) {
|
|
209
|
-
yield this.router.navigate(this.redirectSignOut);
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
if (!this.redirectUrl) {
|
|
213
|
-
throw new Error('Redirect url is not defined');
|
|
214
|
-
}
|
|
215
|
-
location.replace(`${this.ssoUrl}?redirect=${btoa(this.redirectUrl)}&secret=${this.secret}&action=signOut`);
|
|
216
|
-
}
|
|
217
|
-
this.events$.next({ type: AuthenticationEventType.OnLogout });
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
authenticated(response, remember) {
|
|
221
|
-
var _a, _b;
|
|
222
|
-
if (remember === void 0) { remember = (_a = this.remember) !== null && _a !== void 0 ? _a : false; }
|
|
223
|
-
this.accessToken = response.accessToken;
|
|
224
|
-
this.refreshToken = (_b = response.refreshToken) !== null && _b !== void 0 ? _b : null;
|
|
225
|
-
this.expiresAt = response.expiresAt;
|
|
226
|
-
console.log(`Authenticated until ${this.expiresAt.toISOString()}`);
|
|
227
|
-
this.remember = remember;
|
|
228
|
-
if (remember) {
|
|
229
|
-
this.setItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY, response.accessToken);
|
|
230
|
-
if (response.refreshToken) {
|
|
231
|
-
this.setItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY, response.refreshToken);
|
|
232
|
-
}
|
|
233
|
-
this.setItem(REMEMBER_LOCAL_STORAGE_KEY, 'true');
|
|
234
|
-
if (response.expiresAt) {
|
|
235
|
-
console.log(`Authenticated until ${response.expiresAt.toISOString()}`);
|
|
236
|
-
this.setItem(EXPIRES_AT_LOCAL_STORAGE_KEY, response.expiresAt.getTime().toFixed(0));
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
this.removeItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY);
|
|
241
|
-
this.removeItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY);
|
|
242
|
-
this.removeItem(REMEMBER_LOCAL_STORAGE_KEY);
|
|
243
|
-
this.removeItem(EXPIRES_AT_LOCAL_STORAGE_KEY);
|
|
244
|
-
}
|
|
245
|
-
this._isAuthenticated = true;
|
|
246
|
-
this.events$.next({ type: AuthenticationEventType.OnAuthSuccess });
|
|
247
|
-
}
|
|
248
|
-
getKey(key) {
|
|
249
|
-
return [this.secret, key].join('__');
|
|
250
|
-
}
|
|
251
|
-
getItem(key) {
|
|
252
|
-
return localStorage.getItem(this.getKey(key));
|
|
253
|
-
}
|
|
254
|
-
setItem(key, value) {
|
|
255
|
-
localStorage.setItem(this.getKey(key), value);
|
|
256
|
-
}
|
|
257
|
-
removeItem(key) {
|
|
258
|
-
localStorage.removeItem(this.getKey(key));
|
|
259
|
-
}
|
|
260
|
-
clearStorage() {
|
|
261
|
-
this.removeItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY);
|
|
262
|
-
this.removeItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY);
|
|
263
|
-
this.removeItem(REMEMBER_LOCAL_STORAGE_KEY);
|
|
264
|
-
this.removeItem(EXPIRES_AT_LOCAL_STORAGE_KEY);
|
|
265
|
-
}
|
|
266
|
-
signInWithRefreshToken(refreshToken) {
|
|
267
|
-
var _a;
|
|
268
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
269
|
-
if (!this.secret) {
|
|
270
|
-
throw new Error('The oauth secret is not defined');
|
|
271
|
-
}
|
|
272
|
-
if (!this.authEndpoint) {
|
|
273
|
-
throw new Error('The oauth auth endpoint is not defined');
|
|
274
|
-
}
|
|
275
|
-
const response = yield this.oAuthMethod.call({
|
|
276
|
-
refreshToken,
|
|
277
|
-
authEndpoint: this.authEndpoint,
|
|
278
|
-
secret: this.secret,
|
|
279
|
-
clientId: (_a = this.clientId) !== null && _a !== void 0 ? _a : undefined,
|
|
280
|
-
});
|
|
281
|
-
this.authenticated(response);
|
|
282
|
-
return response;
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
OAuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OAuthService, deps: [{ token: OAuthMethod }, { token: GetOAuthProfileMethod }, { token: Router }, { token: PROFILE_AUTH_ENDPOINT, optional: true }, { token: OAUTH_AUTH_ENDPOINT, optional: true }, { token: OAUTH_SECRET, optional: true }, { token: OAUTH_SSO_URL, optional: true }, { token: RXAP_O_AUTH_REDIRECT_SIGN_OUT, optional: true }, { token: RXAP_O_AUTH_REDIRECT_URL, optional: true }, { token: OAUTH_CLIENT_ID, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
287
|
-
OAuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OAuthService, providedIn: 'root' });
|
|
288
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: OAuthService, decorators: [{
|
|
289
|
-
type: Injectable,
|
|
290
|
-
args: [{ providedIn: 'root' }]
|
|
291
|
-
}], ctorParameters: function () { return [{ type: i1.OAuthMethod, decorators: [{
|
|
292
|
-
type: Inject,
|
|
293
|
-
args: [OAuthMethod]
|
|
294
|
-
}] }, { type: i2.GetOAuthProfileMethod, decorators: [{
|
|
295
|
-
type: Inject,
|
|
296
|
-
args: [GetOAuthProfileMethod]
|
|
297
|
-
}] }, { type: i3.Router, decorators: [{
|
|
298
|
-
type: Inject,
|
|
299
|
-
args: [Router]
|
|
300
|
-
}] }, { type: undefined, decorators: [{
|
|
301
|
-
type: Optional
|
|
302
|
-
}, {
|
|
303
|
-
type: Inject,
|
|
304
|
-
args: [PROFILE_AUTH_ENDPOINT]
|
|
305
|
-
}] }, { type: undefined, decorators: [{
|
|
306
|
-
type: Optional
|
|
307
|
-
}, {
|
|
308
|
-
type: Inject,
|
|
309
|
-
args: [OAUTH_AUTH_ENDPOINT]
|
|
310
|
-
}] }, { type: undefined, decorators: [{
|
|
311
|
-
type: Optional
|
|
312
|
-
}, {
|
|
313
|
-
type: Inject,
|
|
314
|
-
args: [OAUTH_SECRET]
|
|
315
|
-
}] }, { type: undefined, decorators: [{
|
|
316
|
-
type: Optional
|
|
317
|
-
}, {
|
|
318
|
-
type: Inject,
|
|
319
|
-
args: [OAUTH_SSO_URL]
|
|
320
|
-
}] }, { type: undefined, decorators: [{
|
|
321
|
-
type: Optional
|
|
322
|
-
}, {
|
|
323
|
-
type: Inject,
|
|
324
|
-
args: [RXAP_O_AUTH_REDIRECT_SIGN_OUT]
|
|
325
|
-
}] }, { type: undefined, decorators: [{
|
|
326
|
-
type: Optional
|
|
327
|
-
}, {
|
|
328
|
-
type: Inject,
|
|
329
|
-
args: [RXAP_O_AUTH_REDIRECT_URL]
|
|
330
|
-
}] }, { type: undefined, decorators: [{
|
|
331
|
-
type: Optional
|
|
332
|
-
}, {
|
|
333
|
-
type: Inject,
|
|
334
|
-
args: [OAUTH_CLIENT_ID]
|
|
335
|
-
}] }]; } });
|
|
336
|
-
//# sourceMappingURL=o-auth.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"o-auth.service.js","sourceRoot":"","sources":["../../../../../libs/oauth/src/lib/o-auth.service.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,MAAM,EACN,UAAU,EACV,cAAc,EACd,QAAQ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C,IAAI,CAAC,YAAY,EAAE;gBACtB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;aAC3D;YAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;gBAC3C,YAAY;gBACZ,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,QAAQ,EAAE,MAAA,IAAI,CAAC,QAAQ,mCAAI,SAAS;aACrC,CAAC,CAAC;YAEH,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YAE7B,OAAO,QAAQ,CAAC;;KACjB;;0GA5UU,YAAY,kBAgFb,WAAW,aAEX,qBAAqB,aAErB,MAAM,aAGN,qBAAqB,6BAGrB,mBAAmB,6BAGnB,YAAY,6BAGZ,aAAa,6BAGb,6BAA6B,6BAG7B,wBAAwB,6BAGxB,eAAe;8GAzGd,YAAY,cADC,MAAM;4FACnB,YAAY;kBADxB,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;0BAiF7B,MAAM;2BAAC,WAAW;;0BAElB,MAAM;2BAAC,qBAAqB;;0BAE5B,MAAM;2BAAC,MAAM;;0BAEb,QAAQ;;0BACR,MAAM;2BAAC,qBAAqB;;0BAE5B,QAAQ;;0BACR,MAAM;2BAAC,mBAAmB;;0BAE1B,QAAQ;;0BACR,MAAM;2BAAC,YAAY;;0BAEnB,QAAQ;;0BACR,MAAM;2BAAC,aAAa;;0BAEpB,QAAQ;;0BACR,MAAM;2BAAC,6BAA6B;;0BAEpC,QAAQ;;0BACR,MAAM;2BAAC,wBAAwB;;0BAE/B,QAAQ;;0BACR,MAAM;2BAAC,eAAe","sourcesContent":["import {\n Inject,\n Injectable,\n InjectionToken,\n Optional\n} from '@angular/core';\nimport {\n GetOAuthProfileMethod,\n PROFILE_AUTH_ENDPOINT\n} from './get-o-auth-profile.method';\nimport {\n OAuthMethod,\n OAuthMethodResponse\n} from './o-auth.method';\nimport {\n RXAP_O_AUTH_REDIRECT_SIGN_OUT,\n RXAP_O_AUTH_REDIRECT_URL\n} from './tokens';\nimport { Router } from '@angular/router';\nimport { ReplaySubject, Subject } from 'rxjs';\nimport { AuthenticationEvent, AuthenticationEventType } from '@rxap/authentication';\n\nexport const OAUTH_SECRET = new InjectionToken('OAUTH_SECRET');\nexport const OAUTH_AUTH_ENDPOINT = new InjectionToken('OAUTH_AUTH_ENDPOINT');\nexport const OAUTH_SSO_URL = new InjectionToken('OAUTH_SSO_URL');\nexport const OAUTH_CLIENT_ID = new InjectionToken('OAUTH_CLIENT_ID');\n\nexport const ACCESS_TOKEN_LOCAL_STORAGE_KEY = 'access_token';\nexport const REFRESH_TOKEN_LOCAL_STORAGE_KEY = 'refresh_token';\nexport const EXPIRES_AT_LOCAL_STORAGE_KEY = 'expires_at';\nexport const REMEMBER_LOCAL_STORAGE_KEY = 'remember';\n\nexport interface OAuthStatus {\n accessToken: string;\n refreshToken?: string | null;\n expiresIn: number;\n expiresAt: Date;\n}\n\n@Injectable({ providedIn: 'root' })\nexport class OAuthService<Profile = any> {\n\n public readonly events$ = new ReplaySubject<AuthenticationEvent>();\n\n get expiresAt(): Date | null {\n const expiresAt = this.getItem(EXPIRES_AT_LOCAL_STORAGE_KEY);\n if (expiresAt) {\n return new Date(\n parseInt(this.getItem(EXPIRES_AT_LOCAL_STORAGE_KEY)!, 10)\n );\n }\n return null;\n }\n\n set expiresAt(value: Date | null) {\n if (value) {\n this.setItem(EXPIRES_AT_LOCAL_STORAGE_KEY, value.getTime().toFixed(0));\n } else {\n this.removeItem(EXPIRES_AT_LOCAL_STORAGE_KEY);\n }\n }\n\n get refreshToken(): string | null {\n return this.getItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY);\n }\n\n set refreshToken(value: string | null) {\n if (value) {\n this.setItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY, value);\n } else {\n this.removeItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY);\n }\n }\n\n get accessToken(): string | null {\n return this.getItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY);\n }\n\n set accessToken(value: string | null) {\n if (value) {\n this.setItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY, value);\n } else {\n this.removeItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY);\n }\n }\n\n /**\n * The time until the access token expires in seconds\n */\n public get expiresIn(): number | null {\n const expiresAt = this.expiresAt;\n if (expiresAt) {\n return Math.round(\n (expiresAt.getTime() - Date.now()) / 1000\n );\n }\n return null;\n }\n\n public get remember(): boolean {\n return !!this.getItem(REMEMBER_LOCAL_STORAGE_KEY);\n }\n\n public set remember(value: boolean) {\n if (value) {\n this.setItem(REMEMBER_LOCAL_STORAGE_KEY, 'true');\n } else {\n this.removeItem(REMEMBER_LOCAL_STORAGE_KEY);\n }\n }\n\n private _profile?: Profile | null;\n\n protected _isAuthenticated: boolean | null = null;\n\n public get profile(): Profile | null | undefined {\n return this._profile;\n }\n\n constructor(\n @Inject(OAuthMethod)\n public readonly oAuthMethod: OAuthMethod,\n @Inject(GetOAuthProfileMethod)\n public readonly getOAuthProfileMethod: GetOAuthProfileMethod,\n @Inject(Router)\n private readonly router: Router,\n @Optional()\n @Inject(PROFILE_AUTH_ENDPOINT)\n public profileEndpoint: string | null = null,\n @Optional()\n @Inject(OAUTH_AUTH_ENDPOINT)\n public authEndpoint: string | null = null,\n @Optional()\n @Inject(OAUTH_SECRET)\n public secret: string | null = null,\n @Optional()\n @Inject(OAUTH_SSO_URL)\n private readonly ssoUrl: string | null = null,\n @Optional()\n @Inject(RXAP_O_AUTH_REDIRECT_SIGN_OUT)\n private readonly redirectSignOut: string[] | null = null,\n @Optional()\n @Inject(RXAP_O_AUTH_REDIRECT_URL)\n private readonly redirectUrl: string | null = null,\n @Optional()\n @Inject(OAUTH_CLIENT_ID)\n public clientId: string | null = null,\n ) {}\n\n public signInWithRedirect(lastUrl?: string): void {\n if (!this.redirectUrl) {\n throw new Error('Redirect url is not defined');\n }\n location.replace(\n `${this.ssoUrl}?redirect=${btoa(this.redirectUrl)}&secret=${\n this.secret\n }&payload=${btoa(JSON.stringify({ lastUrl }))}`\n );\n }\n\n public async isAuthenticated(): Promise<boolean> {\n if (!this.secret) {\n throw new Error('The oauth secret is not defined');\n }\n\n if (!this.authEndpoint) {\n throw new Error('The oauth auth endpoint is not defined');\n }\n\n if (this._isAuthenticated !== null) {\n return this._isAuthenticated;\n }\n\n if (this.accessToken) {\n console.debug('Access token is defined: ' + this.accessToken);\n if (this.expiresIn && this.expiresIn > 60) {\n const profile = await this.getProfile();\n\n if (!profile) {\n console.log('profile is not defined');\n return (this._isAuthenticated = false);\n }\n\n this.authenticated(\n {\n refreshToken: this.refreshToken,\n accessToken: this.accessToken,\n expiresAt: this.expiresAt ?? new Date(Date.now() + 60 * 1000),\n expiresIn: this.expiresIn,\n },\n this.remember\n );\n\n return (this._isAuthenticated = true);\n } else {\n this.accessToken = null;\n this.expiresAt = null;\n console.warn(\n 'The access token expires soon. Use refresh token instead.'\n );\n }\n }\n if (this.refreshToken) {\n console.debug('Refresh token is defined: ' + this.refreshToken);\n try {\n await this.signInWithRefreshToken(this.refreshToken);\n return (this._isAuthenticated = true);\n } catch (e) {\n if (![401, 403, 400].includes(e.status)) {\n console.error('Could not sign in with refresh token', e.message);\n throw e;\n }\n console.warn('Refresh token is expired');\n }\n }\n\n console.warn('Unauthenticated');\n\n return (this._isAuthenticated = false);\n }\n\n public async signInWithEmailAndPassword(\n email: string,\n password: string,\n remember: boolean\n ): Promise<OAuthMethodResponse> {\n if (!this.secret) {\n throw new Error('The oauth secret is not defined');\n }\n\n if (!this.authEndpoint) {\n throw new Error('The oauth auth endpoint is not defined');\n }\n\n const response = await this.oAuthMethod.call({\n username: email,\n password: password,\n authEndpoint: this.authEndpoint,\n secret: this.secret,\n clientId: this.clientId ?? undefined\n }).catch(e => {\n this.events$.next({ type: AuthenticationEventType.OnAuthError });\n throw e;\n });\n\n this.authenticated(response, remember);\n\n return response;\n }\n\n public async getProfile<T extends Profile = Profile>(): Promise<T | null> {\n let profile: T | null = null;\n\n if (!this.accessToken) {\n throw new Error('The access token is not defined');\n }\n\n if (this.profileEndpoint) {\n try {\n profile = await this.getOAuthProfileMethod.call({\n accessToken: this.accessToken,\n profileEndpoint: this.profileEndpoint,\n });\n } catch (e) {\n console.error('Could not request the user profile', e.message);\n }\n } else {\n console.warn('The profile endpoint is not defined!');\n }\n\n return (this._profile = profile);\n }\n\n public async signOut() {\n this.clearStorage();\n this.accessToken = null;\n this.refreshToken = null;\n this.expiresAt = null;\n this._isAuthenticated = false;\n if (this.redirectSignOut) {\n await this.router.navigate(this.redirectSignOut);\n } else {\n if (!this.redirectUrl) {\n throw new Error('Redirect url is not defined');\n }\n location.replace(\n `${this.ssoUrl}?redirect=${btoa(this.redirectUrl)}&secret=${this.secret}&action=signOut`\n );\n }\n this.events$.next({ type: AuthenticationEventType.OnLogout });\n }\n\n public authenticated(\n response: OAuthStatus,\n remember: boolean = this.remember ?? false\n ): void {\n this.accessToken = response.accessToken;\n this.refreshToken = response.refreshToken ?? null;\n this.expiresAt = response.expiresAt;\n\n console.log(`Authenticated until ${this.expiresAt.toISOString()}`);\n\n this.remember = remember;\n\n if (remember) {\n this.setItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY, response.accessToken);\n if (response.refreshToken) {\n this.setItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY, response.refreshToken);\n }\n this.setItem(REMEMBER_LOCAL_STORAGE_KEY, 'true');\n if (response.expiresAt) {\n console.log(`Authenticated until ${response.expiresAt.toISOString()}`);\n this.setItem(\n EXPIRES_AT_LOCAL_STORAGE_KEY,\n response.expiresAt.getTime().toFixed(0)\n );\n }\n } else {\n this.removeItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY);\n this.removeItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY);\n this.removeItem(REMEMBER_LOCAL_STORAGE_KEY);\n this.removeItem(EXPIRES_AT_LOCAL_STORAGE_KEY);\n }\n\n this._isAuthenticated = true;\n this.events$.next({ type: AuthenticationEventType.OnAuthSuccess });\n }\n\n private getKey(key: string): string {\n return [this.secret, key].join('__');\n }\n\n private getItem(key: string): string | null {\n return localStorage.getItem(this.getKey(key));\n }\n\n private setItem(key: string, value: string): void {\n localStorage.setItem(this.getKey(key), value);\n }\n\n private removeItem(key: string): void {\n localStorage.removeItem(this.getKey(key));\n }\n\n protected clearStorage() {\n this.removeItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY);\n this.removeItem(REFRESH_TOKEN_LOCAL_STORAGE_KEY);\n this.removeItem(REMEMBER_LOCAL_STORAGE_KEY);\n this.removeItem(EXPIRES_AT_LOCAL_STORAGE_KEY);\n }\n\n private async signInWithRefreshToken(\n refreshToken: string\n ): Promise<OAuthMethodResponse> {\n if (!this.secret) {\n throw new Error('The oauth secret is not defined');\n }\n\n if (!this.authEndpoint) {\n throw new Error('The oauth auth endpoint is not defined');\n }\n\n const response = await this.oAuthMethod.call({\n refreshToken,\n authEndpoint: this.authEndpoint,\n secret: this.secret,\n clientId: this.clientId ?? undefined,\n });\n\n this.authenticated(response);\n\n return response;\n }\n}\n"]}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
|
-
import { Router } from '@angular/router';
|
|
3
|
-
import { Inject, Injectable } from '@angular/core';
|
|
4
|
-
import { OAuthService } from './o-auth.service';
|
|
5
|
-
import { RXAP_O_AUTH_REDIRECT_SIGN_IN } from './tokens';
|
|
6
|
-
import * as i0 from "@angular/core";
|
|
7
|
-
import * as i1 from "./o-auth.service";
|
|
8
|
-
import * as i2 from "@angular/router";
|
|
9
|
-
export class ProfileResolve {
|
|
10
|
-
constructor(oAuthService, router, redirectLogin) {
|
|
11
|
-
this.oAuthService = oAuthService;
|
|
12
|
-
this.router = router;
|
|
13
|
-
this.redirectLogin = redirectLogin;
|
|
14
|
-
}
|
|
15
|
-
resolve() {
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const profile = yield this.oAuthService.getProfile();
|
|
18
|
-
if (!profile) {
|
|
19
|
-
yield this.router.navigate(this.redirectLogin);
|
|
20
|
-
}
|
|
21
|
-
return profile;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
ProfileResolve.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: ProfileResolve, deps: [{ token: OAuthService }, { token: Router }, { token: RXAP_O_AUTH_REDIRECT_SIGN_IN }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
26
|
-
ProfileResolve.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: ProfileResolve, providedIn: 'root' });
|
|
27
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0, type: ProfileResolve, decorators: [{
|
|
28
|
-
type: Injectable,
|
|
29
|
-
args: [{ providedIn: 'root' }]
|
|
30
|
-
}], ctorParameters: function () { return [{ type: i1.OAuthService, decorators: [{
|
|
31
|
-
type: Inject,
|
|
32
|
-
args: [OAuthService]
|
|
33
|
-
}] }, { type: i2.Router, decorators: [{
|
|
34
|
-
type: Inject,
|
|
35
|
-
args: [Router]
|
|
36
|
-
}] }, { type: undefined, decorators: [{
|
|
37
|
-
type: Inject,
|
|
38
|
-
args: [RXAP_O_AUTH_REDIRECT_SIGN_IN]
|
|
39
|
-
}] }]; } });
|
|
40
|
-
//# sourceMappingURL=profile.resolve.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"profile.resolve.js","sourceRoot":"","sources":["../../../../../libs/oauth/src/lib/profile.resolve.ts"],"names":[],"mappings":";AAAA,OAAO,EAEL,MAAM,EACP,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,MAAM,EACN,UAAU,EACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;;;;AAGxD,MAAM,OAAO,cAAc;IAEzB,YAEmB,YAA0B,EAE1B,MAAc,EAEd,aAAuB;QAJvB,iBAAY,GAAZ,YAAY,CAAc;QAE1B,WAAM,GAAN,MAAM,CAAQ;QAEd,kBAAa,GAAb,aAAa,CAAU;IAE1C,CAAC;IAEY,OAAO;;YAClB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,CAAC;YAErD,IAAI,CAAC,OAAO,EAAE;gBACZ,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;aAChD;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;KAAA;;4GApBU,cAAc,kBAGf,YAAY,aAEZ,MAAM,aAEN,4BAA4B;gHAP3B,cAAc,cADD,MAAM;4FACnB,cAAc;kBAD1B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;0BAI7B,MAAM;2BAAC,YAAY;;0BAEnB,MAAM;2BAAC,MAAM;;0BAEb,MAAM;2BAAC,4BAA4B","sourcesContent":["import {\n Resolve,\n Router\n} from '@angular/router';\nimport {\n Inject,\n Injectable\n} from '@angular/core';\nimport { OAuthService } from './o-auth.service';\nimport { RXAP_O_AUTH_REDIRECT_SIGN_IN } from './tokens';\n\n@Injectable({ providedIn: 'root' })\nexport class ProfileResolve<T = Record<string, any>> implements Resolve<T> {\n\n constructor(\n @Inject(OAuthService)\n private readonly oAuthService: OAuthService,\n @Inject(Router)\n private readonly router: Router,\n @Inject(RXAP_O_AUTH_REDIRECT_SIGN_IN)\n private readonly redirectLogin: string[]\n ) {\n }\n\n public async resolve(): Promise<T> {\n const profile = await this.oAuthService.getProfile();\n\n if (!profile) {\n await this.router.navigate(this.redirectLogin);\n }\n\n return profile;\n }\n\n}\n"]}
|
package/esm2015/lib/routes.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ContainerComponent } from './container/container.component';
|
|
2
|
-
import { LoadingComponent } from './loading/loading.component';
|
|
3
|
-
import { SignInWithRedirectComponent } from './sign-in-with-redirect/sign-in-with-redirect.component';
|
|
4
|
-
import { OAuthExtractGuard } from './o-auth-extract.guard';
|
|
5
|
-
export const RXAP_O_AUTH_ROUTES = [
|
|
6
|
-
{
|
|
7
|
-
path: 'oauth',
|
|
8
|
-
component: ContainerComponent,
|
|
9
|
-
children: [
|
|
10
|
-
{
|
|
11
|
-
path: 'redirect',
|
|
12
|
-
component: SignInWithRedirectComponent
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
canActivate: [OAuthExtractGuard],
|
|
16
|
-
path: '',
|
|
17
|
-
component: LoadingComponent
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
path: '**',
|
|
21
|
-
redirectTo: ''
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
}
|
|
25
|
-
];
|
|
26
|
-
//# sourceMappingURL=routes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../../../../libs/oauth/src/lib/routes.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EACnB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,yDAAyD,CAAC;AACtG,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,MAAM,CAAC,MAAM,kBAAkB,GAAW;IACxC;QACE,IAAI,EAAO,OAAO;QAClB,SAAS,EAAE,kBAAkB;QAC7B,QAAQ,EAAG;YACT;gBACE,IAAI,EAAO,UAAU;gBACrB,SAAS,EAAE,2BAA2B;aACvC;YACD;gBACE,WAAW,EAAE,CAAE,iBAAiB,CAAE;gBAClC,IAAI,EAAS,EAAE;gBACf,SAAS,EAAI,gBAAgB;aAC9B;YACD;gBACE,IAAI,EAAQ,IAAI;gBAChB,UAAU,EAAE,EAAE;aACf;SACF;KACF;CACF,CAAC","sourcesContent":["import { Routes } from '@angular/router';\nimport {\n ContainerComponent\n} from './container/container.component';\nimport { LoadingComponent } from './loading/loading.component';\nimport { SignInWithRedirectComponent } from './sign-in-with-redirect/sign-in-with-redirect.component';\nimport { OAuthExtractGuard } from './o-auth-extract.guard';\n\nexport const RXAP_O_AUTH_ROUTES: Routes = [\n {\n path: 'oauth',\n component: ContainerComponent,\n children: [\n {\n path: 'redirect',\n component: SignInWithRedirectComponent\n },\n {\n canActivate: [ OAuthExtractGuard ],\n path: '',\n component: LoadingComponent\n },\n {\n path: '**',\n redirectTo: ''\n }\n ]\n }\n];\n"]}
|