@arv-bedrock/auth-sso 0.2.2 → 0.2.4
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/README.md +5 -1
- package/dist/cjs/auth.js +45 -24
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/types/auth.d.ts +31 -5
- package/dist/cjs/types/auth.d.ts.map +1 -1
- package/dist/cjs/types/index.d.ts +2 -1
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/esm/auth.js +46 -27
- package/dist/esm/index.mjs +3 -2
- package/dist/esm/types/auth.d.ts +31 -5
- package/dist/esm/types/auth.d.ts.map +1 -1
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/types/index.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/cjs/auth.js
CHANGED
|
@@ -12,8 +12,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.UserStatus = exports.AccountProviders = exports.TypeAccount = void 0;
|
|
15
16
|
const _fetch_1 = __importDefault(require("./_fetch"));
|
|
16
17
|
const constant_1 = require("./constant");
|
|
18
|
+
var TypeAccount;
|
|
19
|
+
(function (TypeAccount) {
|
|
20
|
+
TypeAccount["EMAIL"] = "email";
|
|
21
|
+
TypeAccount["PHONE_NUMBER"] = "phone_number";
|
|
22
|
+
TypeAccount["USERNAME"] = "username";
|
|
23
|
+
TypeAccount["LINE"] = "line";
|
|
24
|
+
TypeAccount["LINE_OA"] = "line_oa";
|
|
25
|
+
})(TypeAccount = exports.TypeAccount || (exports.TypeAccount = {}));
|
|
26
|
+
var AccountProviders;
|
|
27
|
+
(function (AccountProviders) {
|
|
28
|
+
AccountProviders["EMAIL"] = "email";
|
|
29
|
+
AccountProviders["GOOGEL"] = "google";
|
|
30
|
+
})(AccountProviders = exports.AccountProviders || (exports.AccountProviders = {}));
|
|
31
|
+
var UserStatus;
|
|
32
|
+
(function (UserStatus) {
|
|
33
|
+
UserStatus["ACTIVE"] = "active";
|
|
34
|
+
UserStatus["INACTIVE"] = "inactive";
|
|
35
|
+
})(UserStatus = exports.UserStatus || (exports.UserStatus = {}));
|
|
17
36
|
class Auth {
|
|
18
37
|
constructor() {
|
|
19
38
|
this.doLogout = () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -25,36 +44,33 @@ class Auth {
|
|
|
25
44
|
this.doLogin();
|
|
26
45
|
}
|
|
27
46
|
});
|
|
28
|
-
this.userType =
|
|
29
|
-
this.authHost =
|
|
30
|
-
this.clientId =
|
|
31
|
-
this.clientSecret =
|
|
32
|
-
this.defaultCallback =
|
|
33
|
-
this.
|
|
34
|
-
this.
|
|
35
|
-
this.clientInit = { logoutUrl: '', portalHomeUrl: '', isPortal: false };
|
|
47
|
+
this.userType = "officer";
|
|
48
|
+
this.authHost = "";
|
|
49
|
+
this.clientId = "";
|
|
50
|
+
this.clientSecret = "";
|
|
51
|
+
this.defaultCallback = "";
|
|
52
|
+
this.queryString = "";
|
|
53
|
+
this.clientInit = { logoutUrl: "", portalHomeUrl: "", isPortal: false };
|
|
36
54
|
}
|
|
37
55
|
isCitizen() {
|
|
38
|
-
return this.userType ===
|
|
56
|
+
return this.userType === "citizen";
|
|
39
57
|
}
|
|
40
58
|
getCode() {
|
|
41
59
|
const params = new URLSearchParams(window.location.search);
|
|
42
|
-
return params.get(constant_1.CODE) ||
|
|
60
|
+
return params.get(constant_1.CODE) || "";
|
|
43
61
|
}
|
|
44
62
|
getRedirectUri() {
|
|
45
63
|
const params = new URLSearchParams(window.location.search);
|
|
46
|
-
return params.get(constant_1.REDIRECT_URI) ||
|
|
47
|
-
}
|
|
48
|
-
setUser(profile) {
|
|
49
|
-
this.user.userId = profile.user_id;
|
|
50
|
-
this.user.email = profile.user_email;
|
|
64
|
+
return params.get(constant_1.REDIRECT_URI) || "";
|
|
51
65
|
}
|
|
52
66
|
removeUrlParam(key) {
|
|
53
67
|
const params = new URLSearchParams(window.location.search);
|
|
54
68
|
params.delete(key);
|
|
55
69
|
const { pathname } = window.location;
|
|
56
|
-
const replaceURL = params.toString()
|
|
57
|
-
|
|
70
|
+
const replaceURL = params.toString()
|
|
71
|
+
? `${pathname}?${params.toString()}`
|
|
72
|
+
: pathname;
|
|
73
|
+
window.history.replaceState({}, "", replaceURL);
|
|
58
74
|
}
|
|
59
75
|
doLogin(redirectUrl = this.defaultCallback) {
|
|
60
76
|
let url = new URL(redirectUrl, window.location.origin).toString();
|
|
@@ -98,7 +114,7 @@ class Auth {
|
|
|
98
114
|
user_type: this.userType,
|
|
99
115
|
});
|
|
100
116
|
const res = yield this.getClientInit();
|
|
101
|
-
if (res.statusResponse.statusCode !=
|
|
117
|
+
if (res.statusResponse.statusCode != "200") {
|
|
102
118
|
return this.doLogin();
|
|
103
119
|
}
|
|
104
120
|
this.clientInit = res.data;
|
|
@@ -109,11 +125,11 @@ class Auth {
|
|
|
109
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
126
|
const codeParam = `${constant_1.CODE}=${code}`;
|
|
111
127
|
yield (0, _fetch_1.default)(`${this.authHost}/api/v1/oauth/cookies?${this.queryString}&${codeParam}`, {
|
|
112
|
-
method:
|
|
128
|
+
method: "POST",
|
|
113
129
|
body: JSON.stringify({ code }),
|
|
114
130
|
});
|
|
115
131
|
this.removeUrlParam(constant_1.CODE);
|
|
116
|
-
const shouldDoLoginMethod = this.getParam(constant_1.LOGIN_METHOD_REQUEST) ==
|
|
132
|
+
const shouldDoLoginMethod = this.getParam(constant_1.LOGIN_METHOD_REQUEST) == "true";
|
|
117
133
|
if (shouldDoLoginMethod) {
|
|
118
134
|
yield this.doLoginMethodReqeust();
|
|
119
135
|
}
|
|
@@ -150,7 +166,7 @@ class Auth {
|
|
|
150
166
|
clearCookie() {
|
|
151
167
|
return __awaiter(this, void 0, void 0, function* () {
|
|
152
168
|
yield (0, _fetch_1.default)(`${this.authHost}/api/v1/oauth/cookies?${this.queryString}`, {
|
|
153
|
-
method:
|
|
169
|
+
method: "DELETE",
|
|
154
170
|
});
|
|
155
171
|
});
|
|
156
172
|
}
|
|
@@ -160,11 +176,10 @@ class Auth {
|
|
|
160
176
|
const secretParam = `&${constant_1.CLIENT_SECRET}=${this.clientSecret}`;
|
|
161
177
|
const result = yield (0, _fetch_1.default)(`${this.authHost}/api/v1/ums/profile?${this.queryString}${secretParam}`);
|
|
162
178
|
const profile = result.data;
|
|
163
|
-
this.setUser(profile);
|
|
164
179
|
return profile;
|
|
165
180
|
}
|
|
166
181
|
catch (error) {
|
|
167
|
-
console.log(
|
|
182
|
+
console.log("error", error);
|
|
168
183
|
}
|
|
169
184
|
});
|
|
170
185
|
}
|
|
@@ -176,7 +191,13 @@ class Auth {
|
|
|
176
191
|
}
|
|
177
192
|
verifyToken() {
|
|
178
193
|
return (0, _fetch_1.default)(`${this.authHost}/api/v1/oauth/verifyToken?${this.queryString}`, {
|
|
179
|
-
method:
|
|
194
|
+
method: "POST",
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
requestInviting(email) {
|
|
198
|
+
const query = `${this.queryString}&email=${email}`;
|
|
199
|
+
return (0, _fetch_1.default)(`${this.authHost}/api/v1/register/invite?${query}`, {
|
|
200
|
+
method: "GET",
|
|
180
201
|
});
|
|
181
202
|
}
|
|
182
203
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.verifyToken = exports.getRedirectUri = exports.doPortal = exports.getCode = exports.clearCookie = exports.getProfile = exports.setCookie = exports.doRegister = exports.doLogout = exports.doLogin = exports.initBedrockAuth = void 0;
|
|
6
|
+
exports.requestInviting = exports.verifyToken = exports.getRedirectUri = exports.doPortal = exports.getCode = exports.clearCookie = exports.getProfile = exports.setCookie = exports.doRegister = exports.doLogout = exports.doLogin = exports.initBedrockAuth = void 0;
|
|
7
7
|
const auth_1 = __importDefault(require("./auth"));
|
|
8
8
|
const initBedrockAuth = ({ authUri, clientId, clientSecret, callback, userType, }) => {
|
|
9
9
|
auth_1.default.init({
|
|
10
10
|
authHost: authUri,
|
|
11
11
|
clientId,
|
|
12
12
|
clientSecret,
|
|
13
|
-
userType: userType !== null && userType !== void 0 ? userType :
|
|
13
|
+
userType: userType !== null && userType !== void 0 ? userType : "officer",
|
|
14
14
|
})
|
|
15
15
|
.then((data) => {
|
|
16
16
|
callback(data);
|
|
@@ -41,3 +41,5 @@ const getRedirectUri = () => auth_1.default.getRedirectUri();
|
|
|
41
41
|
exports.getRedirectUri = getRedirectUri;
|
|
42
42
|
const verifyToken = () => auth_1.default.verifyToken();
|
|
43
43
|
exports.verifyToken = verifyToken;
|
|
44
|
+
const requestInviting = (email) => auth_1.default.requestInviting(email);
|
|
45
|
+
exports.requestInviting = requestInviting;
|
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;
|
|
@@ -17,8 +17,35 @@ export interface StatusResponse {
|
|
|
17
17
|
messageEN: string;
|
|
18
18
|
}
|
|
19
19
|
export interface AuthServiceResponse {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
id: string;
|
|
21
|
+
title: string;
|
|
22
|
+
firstName: string;
|
|
23
|
+
lastName: string;
|
|
24
|
+
phoneNumber: string;
|
|
25
|
+
picture: string | null;
|
|
26
|
+
status: UserStatus;
|
|
27
|
+
accounts: Accounts[];
|
|
28
|
+
}
|
|
29
|
+
export interface Accounts {
|
|
30
|
+
account: string;
|
|
31
|
+
provider: AccountProviders;
|
|
32
|
+
type: TypeAccount;
|
|
33
|
+
status: UserStatus;
|
|
34
|
+
}
|
|
35
|
+
export declare enum TypeAccount {
|
|
36
|
+
EMAIL = "email",
|
|
37
|
+
PHONE_NUMBER = "phone_number",
|
|
38
|
+
USERNAME = "username",
|
|
39
|
+
LINE = "line",
|
|
40
|
+
LINE_OA = "line_oa"
|
|
41
|
+
}
|
|
42
|
+
export declare enum AccountProviders {
|
|
43
|
+
EMAIL = "email",
|
|
44
|
+
GOOGEL = "google"
|
|
45
|
+
}
|
|
46
|
+
export declare enum UserStatus {
|
|
47
|
+
ACTIVE = "active",
|
|
48
|
+
INACTIVE = "inactive"
|
|
22
49
|
}
|
|
23
50
|
export interface AuthServiceRequest {
|
|
24
51
|
access_token: string;
|
|
@@ -43,14 +70,12 @@ declare class Auth {
|
|
|
43
70
|
private defaultCallback;
|
|
44
71
|
private clientId;
|
|
45
72
|
private clientSecret;
|
|
46
|
-
private user;
|
|
47
73
|
private queryString;
|
|
48
74
|
private clientInit;
|
|
49
75
|
constructor();
|
|
50
76
|
isCitizen(): boolean;
|
|
51
77
|
getCode(): string;
|
|
52
78
|
getRedirectUri(): string;
|
|
53
|
-
private setUser;
|
|
54
79
|
private removeUrlParam;
|
|
55
80
|
doLogin(redirectUrl?: string): void;
|
|
56
81
|
doLogout: () => Promise<void>;
|
|
@@ -66,6 +91,7 @@ declare class Auth {
|
|
|
66
91
|
getProfile(): Promise<AuthServiceResponse | undefined>;
|
|
67
92
|
doPortal(): Promise<void> | undefined;
|
|
68
93
|
verifyToken(): Promise<ResponseData<[]>>;
|
|
94
|
+
requestInviting(email: string): Promise<ResponseData<[]>>;
|
|
69
95
|
}
|
|
70
96
|
declare const bedRockAuth: Auth;
|
|
71
97
|
export default bedRockAuth;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../auth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@ -17,4 +17,5 @@ export declare const getCode: () => string;
|
|
|
17
17
|
export declare const doPortal: () => Promise<void> | undefined;
|
|
18
18
|
export declare const getRedirectUri: () => string;
|
|
19
19
|
export declare const verifyToken: () => Promise<import("./auth").ResponseData<[]>>;
|
|
20
|
+
export declare const requestInviting: (email: string) => Promise<import("./auth").ResponseData<[]>>;
|
|
20
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../index.ts"],"names":[],"mappings":"AAAA,OAAW,EAAE,QAAQ,EAAE,MAAM,QAAQ,
|
|
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;AAElD,eAAO,MAAM,eAAe,UAAW,MAAM,+CAA8B,CAAC"}
|
package/dist/esm/auth.js
CHANGED
|
@@ -1,45 +1,59 @@
|
|
|
1
|
-
import customFetch from
|
|
2
|
-
import { CITIZEN, CLIENT_SECRET, CODE, LOGIN_METHOD_REQUEST, REDIRECT_URI } from
|
|
1
|
+
import customFetch from "./_fetch";
|
|
2
|
+
import { CITIZEN, CLIENT_SECRET, CODE, LOGIN_METHOD_REQUEST, REDIRECT_URI, } from "./constant";
|
|
3
|
+
export var TypeAccount;
|
|
4
|
+
(function (TypeAccount) {
|
|
5
|
+
TypeAccount["EMAIL"] = "email";
|
|
6
|
+
TypeAccount["PHONE_NUMBER"] = "phone_number";
|
|
7
|
+
TypeAccount["USERNAME"] = "username";
|
|
8
|
+
TypeAccount["LINE"] = "line";
|
|
9
|
+
TypeAccount["LINE_OA"] = "line_oa";
|
|
10
|
+
})(TypeAccount || (TypeAccount = {}));
|
|
11
|
+
export var AccountProviders;
|
|
12
|
+
(function (AccountProviders) {
|
|
13
|
+
AccountProviders["EMAIL"] = "email";
|
|
14
|
+
AccountProviders["GOOGEL"] = "google";
|
|
15
|
+
})(AccountProviders || (AccountProviders = {}));
|
|
16
|
+
export var UserStatus;
|
|
17
|
+
(function (UserStatus) {
|
|
18
|
+
UserStatus["ACTIVE"] = "active";
|
|
19
|
+
UserStatus["INACTIVE"] = "inactive";
|
|
20
|
+
})(UserStatus || (UserStatus = {}));
|
|
3
21
|
class Auth {
|
|
4
22
|
userType;
|
|
5
23
|
authHost;
|
|
6
24
|
defaultCallback;
|
|
7
25
|
clientId;
|
|
8
26
|
clientSecret;
|
|
9
|
-
user;
|
|
10
27
|
queryString;
|
|
11
28
|
clientInit;
|
|
12
29
|
constructor() {
|
|
13
|
-
this.userType =
|
|
14
|
-
this.authHost =
|
|
15
|
-
this.clientId =
|
|
16
|
-
this.clientSecret =
|
|
17
|
-
this.defaultCallback =
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
this.clientInit = { logoutUrl: '', portalHomeUrl: '', isPortal: false };
|
|
30
|
+
this.userType = "officer";
|
|
31
|
+
this.authHost = "";
|
|
32
|
+
this.clientId = "";
|
|
33
|
+
this.clientSecret = "";
|
|
34
|
+
this.defaultCallback = "";
|
|
35
|
+
this.queryString = "";
|
|
36
|
+
this.clientInit = { logoutUrl: "", portalHomeUrl: "", isPortal: false };
|
|
21
37
|
}
|
|
22
38
|
isCitizen() {
|
|
23
|
-
return this.userType ===
|
|
39
|
+
return this.userType === "citizen";
|
|
24
40
|
}
|
|
25
41
|
getCode() {
|
|
26
42
|
const params = new URLSearchParams(window.location.search);
|
|
27
|
-
return params.get(CODE) ||
|
|
43
|
+
return params.get(CODE) || "";
|
|
28
44
|
}
|
|
29
45
|
getRedirectUri() {
|
|
30
46
|
const params = new URLSearchParams(window.location.search);
|
|
31
|
-
return params.get(REDIRECT_URI) ||
|
|
32
|
-
}
|
|
33
|
-
setUser(profile) {
|
|
34
|
-
this.user.userId = profile.user_id;
|
|
35
|
-
this.user.email = profile.user_email;
|
|
47
|
+
return params.get(REDIRECT_URI) || "";
|
|
36
48
|
}
|
|
37
49
|
removeUrlParam(key) {
|
|
38
50
|
const params = new URLSearchParams(window.location.search);
|
|
39
51
|
params.delete(key);
|
|
40
52
|
const { pathname } = window.location;
|
|
41
|
-
const replaceURL = params.toString()
|
|
42
|
-
|
|
53
|
+
const replaceURL = params.toString()
|
|
54
|
+
? `${pathname}?${params.toString()}`
|
|
55
|
+
: pathname;
|
|
56
|
+
window.history.replaceState({}, "", replaceURL);
|
|
43
57
|
}
|
|
44
58
|
doLogin(redirectUrl = this.defaultCallback) {
|
|
45
59
|
let url = new URL(redirectUrl, window.location.origin).toString();
|
|
@@ -91,7 +105,7 @@ class Auth {
|
|
|
91
105
|
user_type: this.userType,
|
|
92
106
|
});
|
|
93
107
|
const res = await this.getClientInit();
|
|
94
|
-
if (res.statusResponse.statusCode !=
|
|
108
|
+
if (res.statusResponse.statusCode != "200") {
|
|
95
109
|
return this.doLogin();
|
|
96
110
|
}
|
|
97
111
|
this.clientInit = res.data;
|
|
@@ -100,11 +114,11 @@ class Auth {
|
|
|
100
114
|
async setCookie(code) {
|
|
101
115
|
const codeParam = `${CODE}=${code}`;
|
|
102
116
|
await customFetch(`${this.authHost}/api/v1/oauth/cookies?${this.queryString}&${codeParam}`, {
|
|
103
|
-
method:
|
|
117
|
+
method: "POST",
|
|
104
118
|
body: JSON.stringify({ code }),
|
|
105
119
|
});
|
|
106
120
|
this.removeUrlParam(CODE);
|
|
107
|
-
const shouldDoLoginMethod = this.getParam(LOGIN_METHOD_REQUEST) ==
|
|
121
|
+
const shouldDoLoginMethod = this.getParam(LOGIN_METHOD_REQUEST) == "true";
|
|
108
122
|
if (shouldDoLoginMethod) {
|
|
109
123
|
await this.doLoginMethodReqeust();
|
|
110
124
|
}
|
|
@@ -133,7 +147,7 @@ class Auth {
|
|
|
133
147
|
}
|
|
134
148
|
async clearCookie() {
|
|
135
149
|
await customFetch(`${this.authHost}/api/v1/oauth/cookies?${this.queryString}`, {
|
|
136
|
-
method:
|
|
150
|
+
method: "DELETE",
|
|
137
151
|
});
|
|
138
152
|
}
|
|
139
153
|
async getProfile() {
|
|
@@ -141,11 +155,10 @@ class Auth {
|
|
|
141
155
|
const secretParam = `&${CLIENT_SECRET}=${this.clientSecret}`;
|
|
142
156
|
const result = await customFetch(`${this.authHost}/api/v1/ums/profile?${this.queryString}${secretParam}`);
|
|
143
157
|
const profile = result.data;
|
|
144
|
-
this.setUser(profile);
|
|
145
158
|
return profile;
|
|
146
159
|
}
|
|
147
160
|
catch (error) {
|
|
148
|
-
console.log(
|
|
161
|
+
console.log("error", error);
|
|
149
162
|
}
|
|
150
163
|
}
|
|
151
164
|
doPortal() {
|
|
@@ -156,7 +169,13 @@ class Auth {
|
|
|
156
169
|
}
|
|
157
170
|
verifyToken() {
|
|
158
171
|
return customFetch(`${this.authHost}/api/v1/oauth/verifyToken?${this.queryString}`, {
|
|
159
|
-
method:
|
|
172
|
+
method: "POST",
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
requestInviting(email) {
|
|
176
|
+
const query = `${this.queryString}&email=${email}`;
|
|
177
|
+
return customFetch(`${this.authHost}/api/v1/register/invite?${query}`, {
|
|
178
|
+
method: "GET",
|
|
160
179
|
});
|
|
161
180
|
}
|
|
162
181
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import BR from
|
|
1
|
+
import BR from "./auth";
|
|
2
2
|
export const initBedrockAuth = ({ authUri, clientId, clientSecret, callback, userType, }) => {
|
|
3
3
|
BR.init({
|
|
4
4
|
authHost: authUri,
|
|
5
5
|
clientId,
|
|
6
6
|
clientSecret,
|
|
7
|
-
userType: userType ??
|
|
7
|
+
userType: userType ?? "officer",
|
|
8
8
|
})
|
|
9
9
|
.then((data) => {
|
|
10
10
|
callback(data);
|
|
@@ -24,3 +24,4 @@ export const getCode = () => BR.getCode();
|
|
|
24
24
|
export const doPortal = () => BR.doPortal();
|
|
25
25
|
export const getRedirectUri = () => BR.getRedirectUri();
|
|
26
26
|
export const verifyToken = () => BR.verifyToken();
|
|
27
|
+
export const requestInviting = (email) => BR.requestInviting(email);
|
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;
|
|
@@ -17,8 +17,35 @@ export interface StatusResponse {
|
|
|
17
17
|
messageEN: string;
|
|
18
18
|
}
|
|
19
19
|
export interface AuthServiceResponse {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
id: string;
|
|
21
|
+
title: string;
|
|
22
|
+
firstName: string;
|
|
23
|
+
lastName: string;
|
|
24
|
+
phoneNumber: string;
|
|
25
|
+
picture: string | null;
|
|
26
|
+
status: UserStatus;
|
|
27
|
+
accounts: Accounts[];
|
|
28
|
+
}
|
|
29
|
+
export interface Accounts {
|
|
30
|
+
account: string;
|
|
31
|
+
provider: AccountProviders;
|
|
32
|
+
type: TypeAccount;
|
|
33
|
+
status: UserStatus;
|
|
34
|
+
}
|
|
35
|
+
export declare enum TypeAccount {
|
|
36
|
+
EMAIL = "email",
|
|
37
|
+
PHONE_NUMBER = "phone_number",
|
|
38
|
+
USERNAME = "username",
|
|
39
|
+
LINE = "line",
|
|
40
|
+
LINE_OA = "line_oa"
|
|
41
|
+
}
|
|
42
|
+
export declare enum AccountProviders {
|
|
43
|
+
EMAIL = "email",
|
|
44
|
+
GOOGEL = "google"
|
|
45
|
+
}
|
|
46
|
+
export declare enum UserStatus {
|
|
47
|
+
ACTIVE = "active",
|
|
48
|
+
INACTIVE = "inactive"
|
|
22
49
|
}
|
|
23
50
|
export interface AuthServiceRequest {
|
|
24
51
|
access_token: string;
|
|
@@ -43,14 +70,12 @@ declare class Auth {
|
|
|
43
70
|
private defaultCallback;
|
|
44
71
|
private clientId;
|
|
45
72
|
private clientSecret;
|
|
46
|
-
private user;
|
|
47
73
|
private queryString;
|
|
48
74
|
private clientInit;
|
|
49
75
|
constructor();
|
|
50
76
|
isCitizen(): boolean;
|
|
51
77
|
getCode(): string;
|
|
52
78
|
getRedirectUri(): string;
|
|
53
|
-
private setUser;
|
|
54
79
|
private removeUrlParam;
|
|
55
80
|
doLogin(redirectUrl?: string): void;
|
|
56
81
|
doLogout: () => Promise<void>;
|
|
@@ -66,6 +91,7 @@ declare class Auth {
|
|
|
66
91
|
getProfile(): Promise<AuthServiceResponse | undefined>;
|
|
67
92
|
doPortal(): Promise<void> | undefined;
|
|
68
93
|
verifyToken(): Promise<ResponseData<[]>>;
|
|
94
|
+
requestInviting(email: string): Promise<ResponseData<[]>>;
|
|
69
95
|
}
|
|
70
96
|
declare const bedRockAuth: Auth;
|
|
71
97
|
export default bedRockAuth;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../auth.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAM7C,UAAU,OAAO;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,cAAc,EAAE,cAAc,CAAC;IAC/B,IAAI,EAAE,CAAC,CAAC;CACT;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,EAAE,QAAQ,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,YAAY,iBAAiB;IAC7B,QAAQ,aAAa;IACrB,IAAI,SAAS;IACb,OAAO,YAAY;CACpB;AAED,oBAAY,gBAAgB;IAC1B,KAAK,UAAU;IACf,MAAM,WAAW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UserType } from
|
|
1
|
+
import { UserType } from "./auth";
|
|
2
2
|
export type AuthProps = {
|
|
3
3
|
userType?: UserType;
|
|
4
4
|
authUri: string;
|
|
@@ -17,4 +17,5 @@ export declare const getCode: () => string;
|
|
|
17
17
|
export declare const doPortal: () => Promise<void> | undefined;
|
|
18
18
|
export declare const getRedirectUri: () => string;
|
|
19
19
|
export declare const verifyToken: () => Promise<import("./auth").ResponseData<[]>>;
|
|
20
|
+
export declare const requestInviting: (email: string) => Promise<import("./auth").ResponseData<[]>>;
|
|
20
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../index.ts"],"names":[],"mappings":"AAAA,OAAW,EAAE,QAAQ,EAAE,MAAM,QAAQ,
|
|
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;AAElD,eAAO,MAAM,eAAe,UAAW,MAAM,+CAA8B,CAAC"}
|