@arv-bedrock/auth-sso 0.1.9 → 0.1.11
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/dist/cjs/auth.js +41 -27
- package/dist/cjs/constant.js +5 -3
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/types/auth.d.ts +7 -3
- package/dist/cjs/types/auth.d.ts.map +1 -1
- package/dist/cjs/types/constant.d.ts +2 -1
- package/dist/cjs/types/constant.d.ts.map +1 -1
- package/dist/cjs/types/index.d.ts +2 -2
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/esm/auth.js +41 -30
- package/dist/esm/constant.js +4 -3
- package/dist/esm/index.mjs +4 -1
- package/dist/esm/types/auth.d.ts +7 -3
- package/dist/esm/types/auth.d.ts.map +1 -1
- package/dist/esm/types/constant.d.ts +2 -1
- package/dist/esm/types/constant.d.ts.map +1 -1
- package/dist/esm/types/index.d.ts +2 -2
- package/dist/esm/types/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/auth.js
CHANGED
|
@@ -25,26 +25,25 @@ class Auth {
|
|
|
25
25
|
this.doLogin();
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
|
-
this.userType =
|
|
29
|
-
this.authHost =
|
|
30
|
-
this.clientId =
|
|
31
|
-
this.clientSecret =
|
|
32
|
-
this.
|
|
33
|
-
this.defaultCallback = "";
|
|
28
|
+
this.userType = 'officer';
|
|
29
|
+
this.authHost = '';
|
|
30
|
+
this.clientId = '';
|
|
31
|
+
this.clientSecret = '';
|
|
32
|
+
this.defaultCallback = '';
|
|
34
33
|
this.user = { userId: '', email: '' };
|
|
35
34
|
this.queryString = '';
|
|
36
35
|
this.clientInit = { logoutUrl: '', portalHomeUrl: '', isPortal: false };
|
|
37
36
|
}
|
|
38
37
|
isCitizen() {
|
|
39
|
-
return this.userType ===
|
|
38
|
+
return this.userType === 'citizen';
|
|
40
39
|
}
|
|
41
40
|
getCode() {
|
|
42
41
|
const params = new URLSearchParams(window.location.search);
|
|
43
|
-
return params.get(constant_1.CODE) ||
|
|
42
|
+
return params.get(constant_1.CODE) || '';
|
|
44
43
|
}
|
|
45
44
|
getRedirectUri() {
|
|
46
45
|
const params = new URLSearchParams(window.location.search);
|
|
47
|
-
return params.get(constant_1.REDIRECT_URI) ||
|
|
46
|
+
return params.get(constant_1.REDIRECT_URI) || '';
|
|
48
47
|
}
|
|
49
48
|
setUser(profile) {
|
|
50
49
|
this.user.userId = profile.user_id;
|
|
@@ -54,10 +53,8 @@ class Auth {
|
|
|
54
53
|
const params = new URLSearchParams(window.location.search);
|
|
55
54
|
params.delete(key);
|
|
56
55
|
const { pathname } = window.location;
|
|
57
|
-
const replaceURL = params.toString()
|
|
58
|
-
|
|
59
|
-
: pathname;
|
|
60
|
-
window.history.replaceState({}, "", replaceURL);
|
|
56
|
+
const replaceURL = params.toString() ? `${pathname}?${params.toString()}` : pathname;
|
|
57
|
+
window.history.replaceState({}, '', replaceURL);
|
|
61
58
|
}
|
|
62
59
|
doLogin(redirectUrl = this.defaultCallback) {
|
|
63
60
|
let url = new URL(redirectUrl, window.location.origin).toString();
|
|
@@ -65,7 +62,7 @@ class Auth {
|
|
|
65
62
|
url = url.slice(0, url.length - 1);
|
|
66
63
|
}
|
|
67
64
|
const callbackURL = encodeURIComponent(url);
|
|
68
|
-
let target = `${this.authHost}/auth
|
|
65
|
+
let target = `${this.authHost}/auth/login?redirectUri=${callbackURL}&client_id=${this.clientId}`;
|
|
69
66
|
if (this.isCitizen()) {
|
|
70
67
|
target = `${this.authHost}/auth/${constant_1.CITIZEN}/login?redirectUri=${callbackURL}&client_id=${this.clientId}`;
|
|
71
68
|
}
|
|
@@ -77,7 +74,7 @@ class Auth {
|
|
|
77
74
|
url = url.slice(0, url.length - 1);
|
|
78
75
|
}
|
|
79
76
|
const callbackURL = encodeURIComponent(url);
|
|
80
|
-
let location = `${this.authHost}/auth
|
|
77
|
+
let location = `${this.authHost}/auth/create-account?redirectUri=${callbackURL}&client_id=${this.clientId}`;
|
|
81
78
|
if (this.isCitizen()) {
|
|
82
79
|
location = `${this.authHost}/auth/${constant_1.CITIZEN}/main-register?redirectUri=${callbackURL}&client_id=${this.clientId}`;
|
|
83
80
|
}
|
|
@@ -97,8 +94,8 @@ class Auth {
|
|
|
97
94
|
this.clientId = options.clientId;
|
|
98
95
|
this.clientSecret = options.clientSecret;
|
|
99
96
|
this.queryString = this.createQueryParam({
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
client_id: this.clientId,
|
|
98
|
+
user_type: this.userType,
|
|
102
99
|
});
|
|
103
100
|
const res = yield this.getClientInit();
|
|
104
101
|
if (res.code != '200') {
|
|
@@ -110,14 +107,32 @@ class Auth {
|
|
|
110
107
|
setCookie(code) {
|
|
111
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
109
|
const codeParam = `${constant_1.CODE}=${code}`;
|
|
113
|
-
|
|
114
|
-
method:
|
|
115
|
-
body: JSON.stringify({ code })
|
|
110
|
+
yield (0, _fetch_1.default)(`${this.authHost}/api/v1/oauth/cookies?${this.queryString}&${codeParam}`, {
|
|
111
|
+
method: 'POST',
|
|
112
|
+
body: JSON.stringify({ code }),
|
|
116
113
|
});
|
|
117
114
|
this.removeUrlParam(constant_1.CODE);
|
|
118
|
-
|
|
115
|
+
const shouldDoLoginMethod = this.getParam(constant_1.LOGIN_METHOD_REQUEST) == 'true';
|
|
116
|
+
if (shouldDoLoginMethod) {
|
|
117
|
+
yield this.doLoginMethodReqeust();
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
doLoginMethodReqeust() {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
try {
|
|
124
|
+
const result = yield (0, _fetch_1.default)(`${this.authHost}/api/v1/oauth/loginMethodRequest?${this.queryString}`);
|
|
125
|
+
window.location.replace(result.data.redirectUri);
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
console.log(err);
|
|
129
|
+
throw err;
|
|
130
|
+
}
|
|
119
131
|
});
|
|
120
132
|
}
|
|
133
|
+
getParam(key) {
|
|
134
|
+
return new URLSearchParams(window.location.search).get(key);
|
|
135
|
+
}
|
|
121
136
|
getClientInfo() {
|
|
122
137
|
return __awaiter(this, void 0, void 0, function* () {
|
|
123
138
|
const result = yield (0, _fetch_1.default)(`${this.authHost}/api/v1/oauth/clientInfo?${this.queryString}`);
|
|
@@ -134,15 +149,15 @@ class Auth {
|
|
|
134
149
|
clearCookie() {
|
|
135
150
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
151
|
yield (0, _fetch_1.default)(`${this.authHost}/api/v1/oauth/cookies?${this.queryString}`, {
|
|
137
|
-
method:
|
|
152
|
+
method: 'DELETE',
|
|
138
153
|
});
|
|
139
154
|
});
|
|
140
155
|
}
|
|
141
156
|
getProfile() {
|
|
142
157
|
return __awaiter(this, void 0, void 0, function* () {
|
|
143
158
|
try {
|
|
144
|
-
const secretParam =
|
|
145
|
-
const result = yield (0, _fetch_1.default)(`${this.authHost}/api/v1/oauth/profile_sso?${this.queryString}
|
|
159
|
+
const secretParam = `&${constant_1.CLIENT_SECRET}=${this.clientSecret}`;
|
|
160
|
+
const result = yield (0, _fetch_1.default)(`${this.authHost}/api/v1/oauth/profile_sso?${this.queryString}${secretParam}`);
|
|
146
161
|
const profile = result.data;
|
|
147
162
|
this.setUser(profile);
|
|
148
163
|
return profile;
|
|
@@ -159,9 +174,8 @@ class Auth {
|
|
|
159
174
|
window.location.replace(`${this.clientInit.portalHomeUrl}?client_id=${this.clientId}&user_type=${this.userType}`);
|
|
160
175
|
}
|
|
161
176
|
verifyToken() {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
method: "POST"
|
|
177
|
+
return (0, _fetch_1.default)(`${this.authHost}/api/v1/oauth/verifyToken?${this.queryString}`, {
|
|
178
|
+
method: 'POST',
|
|
165
179
|
});
|
|
166
180
|
}
|
|
167
181
|
}
|
package/dist/cjs/constant.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OFFICER = exports.
|
|
3
|
+
exports.REDIRECT_URI = exports.OFFICER = exports.LOGIN_METHOD_REQUEST = exports.CODE = exports.CLIENT_SECRET = exports.CITIZEN = void 0;
|
|
4
4
|
const CITIZEN = "citizen";
|
|
5
5
|
exports.CITIZEN = CITIZEN;
|
|
6
6
|
const OFFICER = "officer";
|
|
7
7
|
exports.OFFICER = OFFICER;
|
|
8
8
|
const CLIENT_SECRET = "client_secret";
|
|
9
9
|
exports.CLIENT_SECRET = CLIENT_SECRET;
|
|
10
|
-
const CODE =
|
|
10
|
+
const CODE = "code";
|
|
11
11
|
exports.CODE = CODE;
|
|
12
|
-
const REDIRECT_URI =
|
|
12
|
+
const REDIRECT_URI = "redirectUri";
|
|
13
13
|
exports.REDIRECT_URI = REDIRECT_URI;
|
|
14
|
+
const LOGIN_METHOD_REQUEST = "loginMethod";
|
|
15
|
+
exports.LOGIN_METHOD_REQUEST = LOGIN_METHOD_REQUEST;
|
package/dist/cjs/index.js
CHANGED
|
@@ -15,7 +15,10 @@ const initBedrockAuth = ({ authUri, clientId, clientSecret, callback, userType,
|
|
|
15
15
|
.then(() => {
|
|
16
16
|
callback();
|
|
17
17
|
})
|
|
18
|
-
.catch((error) =>
|
|
18
|
+
.catch((error) => {
|
|
19
|
+
callback(error);
|
|
20
|
+
console.log(error);
|
|
21
|
+
});
|
|
19
22
|
};
|
|
20
23
|
exports.initBedrockAuth = initBedrockAuth;
|
|
21
24
|
const doLogin = (redirectUrl) => auth_1.default.doLogin(redirectUrl);
|
package/dist/cjs/types/auth.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type UserType =
|
|
1
|
+
export type UserType = 'citizen' | 'officer';
|
|
2
2
|
interface Options {
|
|
3
3
|
authHost: string;
|
|
4
4
|
clientId: string;
|
|
@@ -28,10 +28,12 @@ export interface ClientInit {
|
|
|
28
28
|
portalHomeUrl: string;
|
|
29
29
|
isPortal: boolean;
|
|
30
30
|
}
|
|
31
|
+
export interface LoginMethodRequest {
|
|
32
|
+
redirectUri: string;
|
|
33
|
+
}
|
|
31
34
|
declare class Auth {
|
|
32
35
|
private userType;
|
|
33
36
|
private authHost;
|
|
34
|
-
private frontendHost;
|
|
35
37
|
private defaultCallback;
|
|
36
38
|
private clientId;
|
|
37
39
|
private clientSecret;
|
|
@@ -49,7 +51,9 @@ declare class Auth {
|
|
|
49
51
|
doRegister(redirectUrl?: string): void;
|
|
50
52
|
private createQueryParam;
|
|
51
53
|
init(options: Options): Promise<void>;
|
|
52
|
-
setCookie(code: string): Promise<
|
|
54
|
+
setCookie(code: string): Promise<void>;
|
|
55
|
+
private doLoginMethodReqeust;
|
|
56
|
+
private getParam;
|
|
53
57
|
getClientInfo(): Promise<ResponseData<ClientInfo>>;
|
|
54
58
|
private getClientInit;
|
|
55
59
|
clearCookie(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../auth.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../auth.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAA;AAM5C,UAAU,OAAO;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,QAAQ,CAAA;CACnB;AAED,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,CAAC,CAAA;IACP,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,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
|
|
|
3
3
|
declare const CLIENT_SECRET = "client_secret";
|
|
4
4
|
declare const CODE = "code";
|
|
5
5
|
declare const REDIRECT_URI = "redirectUri";
|
|
6
|
-
|
|
6
|
+
declare const LOGIN_METHOD_REQUEST = "loginMethod";
|
|
7
|
+
export { CITIZEN, CLIENT_SECRET, CODE, LOGIN_METHOD_REQUEST, OFFICER, REDIRECT_URI, };
|
|
7
8
|
//# sourceMappingURL=constant.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../../constant.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,YAAY,CAAC;AAC1B,QAAA,MAAM,OAAO,YAAY,CAAC;AAC1B,QAAA,MAAM,aAAa,kBAAkB,CAAC;AACtC,QAAA,MAAM,IAAI,SAAS,CAAC;AACpB,QAAA,MAAM,YAAY,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../../constant.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,YAAY,CAAC;AAC1B,QAAA,MAAM,OAAO,YAAY,CAAC;AAC1B,QAAA,MAAM,aAAa,kBAAkB,CAAC;AACtC,QAAA,MAAM,IAAI,SAAS,CAAC;AACpB,QAAA,MAAM,YAAY,gBAAgB,CAAC;AACnC,QAAA,MAAM,oBAAoB,gBAAgB,CAAC;AAE3C,OAAO,EACL,OAAO,EACP,aAAa,EACb,IAAI,EACJ,oBAAoB,EACpB,OAAO,EACP,YAAY,GACb,CAAC"}
|
|
@@ -4,13 +4,13 @@ export type AuthProps = {
|
|
|
4
4
|
authUri: string;
|
|
5
5
|
clientId: string;
|
|
6
6
|
clientSecret: string;
|
|
7
|
-
callback: () => void;
|
|
7
|
+
callback: (error?: any) => void;
|
|
8
8
|
};
|
|
9
9
|
export declare const initBedrockAuth: ({ authUri, clientId, clientSecret, callback, userType, }: AuthProps) => void;
|
|
10
10
|
export declare const doLogin: (redirectUrl?: string) => void;
|
|
11
11
|
export declare const doLogout: () => Promise<void>;
|
|
12
12
|
export declare const doRegister: (redirectUrl?: string) => void;
|
|
13
|
-
export declare const setCookie: (code: string) => Promise<
|
|
13
|
+
export declare const setCookie: (code: string) => Promise<void>;
|
|
14
14
|
export declare const getProfile: () => Promise<import("./auth").AuthServiceResponse | undefined>;
|
|
15
15
|
export declare const clearCookie: () => Promise<void>;
|
|
16
16
|
export declare const getCode: () => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../index.ts"],"names":[],"mappings":"AAAA,OAAW,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../index.ts"],"names":[],"mappings":"AAAA,OAAW,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF,eAAO,MAAM,eAAe,6DAMzB,SAAS,SAcX,CAAC;AAEF,eAAO,MAAM,OAAO,iBAAkB,MAAM,SAA4B,CAAC;AAEzE,eAAO,MAAM,QAAQ,qBAAsB,CAAC;AAE5C,eAAO,MAAM,UAAU,iBAAkB,MAAM,SAA+B,CAAC;AAE/E,eAAO,MAAM,SAAS,SAAU,MAAM,kBAAuB,CAAC;AAE9D,eAAO,MAAM,UAAU,iEAAwB,CAAC;AAEhD,eAAO,MAAM,WAAW,qBAAyB,CAAC;AAElD,eAAO,MAAM,OAAO,cAAqB,CAAC;AAE1C,eAAO,MAAM,QAAQ,iCAAsB,CAAC;AAE5C,eAAO,MAAM,cAAc,cAA4B,CAAC;AAExD,eAAO,MAAM,WAAW,kDAAyB,CAAC"}
|
package/dist/esm/auth.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import customFetch from
|
|
2
|
-
import { CITIZEN, CLIENT_SECRET, CODE,
|
|
1
|
+
import customFetch from './_fetch';
|
|
2
|
+
import { CITIZEN, CLIENT_SECRET, CODE, LOGIN_METHOD_REQUEST, REDIRECT_URI } from './constant';
|
|
3
3
|
class Auth {
|
|
4
4
|
userType;
|
|
5
5
|
authHost;
|
|
6
|
-
frontendHost;
|
|
7
6
|
defaultCallback;
|
|
8
7
|
clientId;
|
|
9
8
|
clientSecret;
|
|
@@ -11,26 +10,25 @@ class Auth {
|
|
|
11
10
|
queryString;
|
|
12
11
|
clientInit;
|
|
13
12
|
constructor() {
|
|
14
|
-
this.userType =
|
|
15
|
-
this.authHost =
|
|
16
|
-
this.clientId =
|
|
17
|
-
this.clientSecret =
|
|
18
|
-
this.
|
|
19
|
-
this.defaultCallback = "";
|
|
13
|
+
this.userType = 'officer';
|
|
14
|
+
this.authHost = '';
|
|
15
|
+
this.clientId = '';
|
|
16
|
+
this.clientSecret = '';
|
|
17
|
+
this.defaultCallback = '';
|
|
20
18
|
this.user = { userId: '', email: '' };
|
|
21
19
|
this.queryString = '';
|
|
22
20
|
this.clientInit = { logoutUrl: '', portalHomeUrl: '', isPortal: false };
|
|
23
21
|
}
|
|
24
22
|
isCitizen() {
|
|
25
|
-
return this.userType ===
|
|
23
|
+
return this.userType === 'citizen';
|
|
26
24
|
}
|
|
27
25
|
getCode() {
|
|
28
26
|
const params = new URLSearchParams(window.location.search);
|
|
29
|
-
return params.get(CODE) ||
|
|
27
|
+
return params.get(CODE) || '';
|
|
30
28
|
}
|
|
31
29
|
getRedirectUri() {
|
|
32
30
|
const params = new URLSearchParams(window.location.search);
|
|
33
|
-
return params.get(REDIRECT_URI) ||
|
|
31
|
+
return params.get(REDIRECT_URI) || '';
|
|
34
32
|
}
|
|
35
33
|
setUser(profile) {
|
|
36
34
|
this.user.userId = profile.user_id;
|
|
@@ -40,10 +38,8 @@ class Auth {
|
|
|
40
38
|
const params = new URLSearchParams(window.location.search);
|
|
41
39
|
params.delete(key);
|
|
42
40
|
const { pathname } = window.location;
|
|
43
|
-
const replaceURL = params.toString()
|
|
44
|
-
|
|
45
|
-
: pathname;
|
|
46
|
-
window.history.replaceState({}, "", replaceURL);
|
|
41
|
+
const replaceURL = params.toString() ? `${pathname}?${params.toString()}` : pathname;
|
|
42
|
+
window.history.replaceState({}, '', replaceURL);
|
|
47
43
|
}
|
|
48
44
|
doLogin(redirectUrl = this.defaultCallback) {
|
|
49
45
|
let url = new URL(redirectUrl, window.location.origin).toString();
|
|
@@ -51,7 +47,7 @@ class Auth {
|
|
|
51
47
|
url = url.slice(0, url.length - 1);
|
|
52
48
|
}
|
|
53
49
|
const callbackURL = encodeURIComponent(url);
|
|
54
|
-
let target = `${this.authHost}/auth
|
|
50
|
+
let target = `${this.authHost}/auth/login?redirectUri=${callbackURL}&client_id=${this.clientId}`;
|
|
55
51
|
if (this.isCitizen()) {
|
|
56
52
|
target = `${this.authHost}/auth/${CITIZEN}/login?redirectUri=${callbackURL}&client_id=${this.clientId}`;
|
|
57
53
|
}
|
|
@@ -72,7 +68,7 @@ class Auth {
|
|
|
72
68
|
url = url.slice(0, url.length - 1);
|
|
73
69
|
}
|
|
74
70
|
const callbackURL = encodeURIComponent(url);
|
|
75
|
-
let location = `${this.authHost}/auth
|
|
71
|
+
let location = `${this.authHost}/auth/create-account?redirectUri=${callbackURL}&client_id=${this.clientId}`;
|
|
76
72
|
if (this.isCitizen()) {
|
|
77
73
|
location = `${this.authHost}/auth/${CITIZEN}/main-register?redirectUri=${callbackURL}&client_id=${this.clientId}`;
|
|
78
74
|
}
|
|
@@ -91,8 +87,8 @@ class Auth {
|
|
|
91
87
|
this.clientId = options.clientId;
|
|
92
88
|
this.clientSecret = options.clientSecret;
|
|
93
89
|
this.queryString = this.createQueryParam({
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
client_id: this.clientId,
|
|
91
|
+
user_type: this.userType,
|
|
96
92
|
});
|
|
97
93
|
const res = await this.getClientInit();
|
|
98
94
|
if (res.code != '200') {
|
|
@@ -102,12 +98,28 @@ class Auth {
|
|
|
102
98
|
}
|
|
103
99
|
async setCookie(code) {
|
|
104
100
|
const codeParam = `${CODE}=${code}`;
|
|
105
|
-
|
|
106
|
-
method:
|
|
107
|
-
body: JSON.stringify({ code })
|
|
101
|
+
await customFetch(`${this.authHost}/api/v1/oauth/cookies?${this.queryString}&${codeParam}`, {
|
|
102
|
+
method: 'POST',
|
|
103
|
+
body: JSON.stringify({ code }),
|
|
108
104
|
});
|
|
109
105
|
this.removeUrlParam(CODE);
|
|
110
|
-
|
|
106
|
+
const shouldDoLoginMethod = this.getParam(LOGIN_METHOD_REQUEST) == 'true';
|
|
107
|
+
if (shouldDoLoginMethod) {
|
|
108
|
+
await this.doLoginMethodReqeust();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async doLoginMethodReqeust() {
|
|
112
|
+
try {
|
|
113
|
+
const result = await customFetch(`${this.authHost}/api/v1/oauth/loginMethodRequest?${this.queryString}`);
|
|
114
|
+
window.location.replace(result.data.redirectUri);
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
console.log(err);
|
|
118
|
+
throw err;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
getParam(key) {
|
|
122
|
+
return new URLSearchParams(window.location.search).get(key);
|
|
111
123
|
}
|
|
112
124
|
async getClientInfo() {
|
|
113
125
|
const result = await customFetch(`${this.authHost}/api/v1/oauth/clientInfo?${this.queryString}`);
|
|
@@ -120,13 +132,13 @@ class Auth {
|
|
|
120
132
|
}
|
|
121
133
|
async clearCookie() {
|
|
122
134
|
await customFetch(`${this.authHost}/api/v1/oauth/cookies?${this.queryString}`, {
|
|
123
|
-
method:
|
|
135
|
+
method: 'DELETE',
|
|
124
136
|
});
|
|
125
137
|
}
|
|
126
138
|
async getProfile() {
|
|
127
139
|
try {
|
|
128
|
-
const secretParam =
|
|
129
|
-
const result = await customFetch(`${this.authHost}/api/v1/oauth/profile_sso?${this.queryString}
|
|
140
|
+
const secretParam = `&${CLIENT_SECRET}=${this.clientSecret}`;
|
|
141
|
+
const result = await customFetch(`${this.authHost}/api/v1/oauth/profile_sso?${this.queryString}${secretParam}`);
|
|
130
142
|
const profile = result.data;
|
|
131
143
|
this.setUser(profile);
|
|
132
144
|
return profile;
|
|
@@ -142,9 +154,8 @@ class Auth {
|
|
|
142
154
|
window.location.replace(`${this.clientInit.portalHomeUrl}?client_id=${this.clientId}&user_type=${this.userType}`);
|
|
143
155
|
}
|
|
144
156
|
verifyToken() {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
method: "POST"
|
|
157
|
+
return customFetch(`${this.authHost}/api/v1/oauth/verifyToken?${this.queryString}`, {
|
|
158
|
+
method: 'POST',
|
|
148
159
|
});
|
|
149
160
|
}
|
|
150
161
|
}
|
package/dist/esm/constant.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const CITIZEN = "citizen";
|
|
2
2
|
const OFFICER = "officer";
|
|
3
3
|
const CLIENT_SECRET = "client_secret";
|
|
4
|
-
const CODE =
|
|
5
|
-
const REDIRECT_URI =
|
|
6
|
-
|
|
4
|
+
const CODE = "code";
|
|
5
|
+
const REDIRECT_URI = "redirectUri";
|
|
6
|
+
const LOGIN_METHOD_REQUEST = "loginMethod";
|
|
7
|
+
export { CITIZEN, CLIENT_SECRET, CODE, LOGIN_METHOD_REQUEST, OFFICER, REDIRECT_URI, };
|
package/dist/esm/index.mjs
CHANGED
|
@@ -9,7 +9,10 @@ export const initBedrockAuth = ({ authUri, clientId, clientSecret, callback, use
|
|
|
9
9
|
.then(() => {
|
|
10
10
|
callback();
|
|
11
11
|
})
|
|
12
|
-
.catch((error) =>
|
|
12
|
+
.catch((error) => {
|
|
13
|
+
callback(error);
|
|
14
|
+
console.log(error);
|
|
15
|
+
});
|
|
13
16
|
};
|
|
14
17
|
export const doLogin = (redirectUrl) => BR.doLogin(redirectUrl);
|
|
15
18
|
export const doLogout = () => BR.doLogout();
|
package/dist/esm/types/auth.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type UserType =
|
|
1
|
+
export type UserType = 'citizen' | 'officer';
|
|
2
2
|
interface Options {
|
|
3
3
|
authHost: string;
|
|
4
4
|
clientId: string;
|
|
@@ -28,10 +28,12 @@ export interface ClientInit {
|
|
|
28
28
|
portalHomeUrl: string;
|
|
29
29
|
isPortal: boolean;
|
|
30
30
|
}
|
|
31
|
+
export interface LoginMethodRequest {
|
|
32
|
+
redirectUri: string;
|
|
33
|
+
}
|
|
31
34
|
declare class Auth {
|
|
32
35
|
private userType;
|
|
33
36
|
private authHost;
|
|
34
|
-
private frontendHost;
|
|
35
37
|
private defaultCallback;
|
|
36
38
|
private clientId;
|
|
37
39
|
private clientSecret;
|
|
@@ -49,7 +51,9 @@ declare class Auth {
|
|
|
49
51
|
doRegister(redirectUrl?: string): void;
|
|
50
52
|
private createQueryParam;
|
|
51
53
|
init(options: Options): Promise<void>;
|
|
52
|
-
setCookie(code: string): Promise<
|
|
54
|
+
setCookie(code: string): Promise<void>;
|
|
55
|
+
private doLoginMethodReqeust;
|
|
56
|
+
private getParam;
|
|
53
57
|
getClientInfo(): Promise<ResponseData<ClientInfo>>;
|
|
54
58
|
private getClientInit;
|
|
55
59
|
clearCookie(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../auth.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,QAAQ,GAAG,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P,cAAc;IAKrB,OAAO,CAAC,OAAO;IAKf,OAAO,CAAC,cAAc;IAQf,OAAO,CAAC,WAAW,GAAE,MAA6B;IAalD,QAAQ,sBAOd;IAEM,UAAU,CAAC,WAAW,GAAE,MAA6B;IAc5D,OAAO,CAAC,gBAAgB;IAQX,IAAI,CAAC,OAAO,EAAE,OAAO;IAiBrB,SAAS,CAAC,IAAI,EAAE,MAAM;YAcrB,oBAAoB;IAalC,OAAO,CAAC,QAAQ;IAIH,aAAa;YAOZ,aAAa;IAQd,WAAW;IAMX,UAAU;IAchB,QAAQ;IASR,WAAW;CAQnB;AAED,QAAA,MAAM,WAAW,MAAa,CAAA;AAE9B,eAAe,WAAW,CAAA"}
|
|
@@ -3,5 +3,6 @@ declare const OFFICER = "officer";
|
|
|
3
3
|
declare const CLIENT_SECRET = "client_secret";
|
|
4
4
|
declare const CODE = "code";
|
|
5
5
|
declare const REDIRECT_URI = "redirectUri";
|
|
6
|
-
|
|
6
|
+
declare const LOGIN_METHOD_REQUEST = "loginMethod";
|
|
7
|
+
export { CITIZEN, CLIENT_SECRET, CODE, LOGIN_METHOD_REQUEST, OFFICER, REDIRECT_URI, };
|
|
7
8
|
//# sourceMappingURL=constant.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../../constant.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,YAAY,CAAC;AAC1B,QAAA,MAAM,OAAO,YAAY,CAAC;AAC1B,QAAA,MAAM,aAAa,kBAAkB,CAAC;AACtC,QAAA,MAAM,IAAI,SAAS,CAAC;AACpB,QAAA,MAAM,YAAY,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../../constant.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,YAAY,CAAC;AAC1B,QAAA,MAAM,OAAO,YAAY,CAAC;AAC1B,QAAA,MAAM,aAAa,kBAAkB,CAAC;AACtC,QAAA,MAAM,IAAI,SAAS,CAAC;AACpB,QAAA,MAAM,YAAY,gBAAgB,CAAC;AACnC,QAAA,MAAM,oBAAoB,gBAAgB,CAAC;AAE3C,OAAO,EACL,OAAO,EACP,aAAa,EACb,IAAI,EACJ,oBAAoB,EACpB,OAAO,EACP,YAAY,GACb,CAAC"}
|
|
@@ -4,13 +4,13 @@ export type AuthProps = {
|
|
|
4
4
|
authUri: string;
|
|
5
5
|
clientId: string;
|
|
6
6
|
clientSecret: string;
|
|
7
|
-
callback: () => void;
|
|
7
|
+
callback: (error?: any) => void;
|
|
8
8
|
};
|
|
9
9
|
export declare const initBedrockAuth: ({ authUri, clientId, clientSecret, callback, userType, }: AuthProps) => void;
|
|
10
10
|
export declare const doLogin: (redirectUrl?: string) => void;
|
|
11
11
|
export declare const doLogout: () => Promise<void>;
|
|
12
12
|
export declare const doRegister: (redirectUrl?: string) => void;
|
|
13
|
-
export declare const setCookie: (code: string) => Promise<
|
|
13
|
+
export declare const setCookie: (code: string) => Promise<void>;
|
|
14
14
|
export declare const getProfile: () => Promise<import("./auth").AuthServiceResponse | undefined>;
|
|
15
15
|
export declare const clearCookie: () => Promise<void>;
|
|
16
16
|
export declare const getCode: () => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../index.ts"],"names":[],"mappings":"AAAA,OAAW,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../index.ts"],"names":[],"mappings":"AAAA,OAAW,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF,eAAO,MAAM,eAAe,6DAMzB,SAAS,SAcX,CAAC;AAEF,eAAO,MAAM,OAAO,iBAAkB,MAAM,SAA4B,CAAC;AAEzE,eAAO,MAAM,QAAQ,qBAAsB,CAAC;AAE5C,eAAO,MAAM,UAAU,iBAAkB,MAAM,SAA+B,CAAC;AAE/E,eAAO,MAAM,SAAS,SAAU,MAAM,kBAAuB,CAAC;AAE9D,eAAO,MAAM,UAAU,iEAAwB,CAAC;AAEhD,eAAO,MAAM,WAAW,qBAAyB,CAAC;AAElD,eAAO,MAAM,OAAO,cAAqB,CAAC;AAE1C,eAAO,MAAM,QAAQ,iCAAsB,CAAC;AAE5C,eAAO,MAAM,cAAc,cAA4B,CAAC;AAExD,eAAO,MAAM,WAAW,kDAAyB,CAAC"}
|