cidaas-javascript-sdk 4.2.4 → 4.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -2
- package/README.md +9 -6
- package/dist/authentication/{index.d.ts → Authentication.d.ts} +2 -2
- package/dist/authentication/{index.js → Authentication.js} +2 -9
- package/dist/common/Common.model.d.ts +41 -0
- package/dist/common/Common.model.js +26 -0
- package/dist/{web-auth → common}/Helper.d.ts +6 -6
- package/dist/{web-auth → common}/Helper.js +10 -10
- package/dist/common/JwtHelper.d.ts +8 -0
- package/dist/{web-auth → common}/JwtHelper.js +8 -8
- package/dist/common/User.model.d.ts +134 -0
- package/dist/common/User.model.js +2 -0
- package/dist/consent-service/ConsentService.d.ts +97 -0
- package/dist/consent-service/ConsentService.js +127 -0
- package/dist/consent-service/ConsentService.model.d.ts +102 -0
- package/dist/consent-service/ConsentService.model.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/login-service/LoginService.d.ts +143 -0
- package/dist/login-service/LoginService.js +247 -0
- package/dist/login-service/LoginService.model.d.ts +142 -0
- package/dist/login-service/LoginService.model.js +13 -0
- package/dist/token-service/TokenService.d.ts +139 -0
- package/dist/token-service/TokenService.js +242 -0
- package/dist/token-service/TokenService.model.d.ts +149 -0
- package/dist/token-service/TokenService.model.js +43 -0
- package/dist/user-service/UserService.d.ts +317 -0
- package/dist/user-service/UserService.js +451 -0
- package/dist/user-service/UserService.model.d.ts +142 -0
- package/dist/user-service/UserService.model.js +10 -0
- package/dist/verification-service/VerificationService.d.ts +219 -0
- package/dist/verification-service/VerificationService.js +288 -0
- package/dist/verification-service/VerificationService.model.d.ts +158 -0
- package/dist/verification-service/VerificationService.model.js +2 -0
- package/dist/web-auth/WebAuth.d.ts +138 -178
- package/dist/web-auth/WebAuth.js +183 -177
- package/dist/web-auth/webauth.model.d.ts +66 -0
- package/dist/web-auth/webauth.model.js +2 -0
- package/package.json +2 -2
- package/dist/web-auth/ConsentService.d.ts +0 -123
- package/dist/web-auth/ConsentService.js +0 -136
- package/dist/web-auth/Entities.d.ts +0 -516
- package/dist/web-auth/Entities.js +0 -69
- package/dist/web-auth/JwtHelper.d.ts +0 -7
- package/dist/web-auth/LoginService.d.ts +0 -165
- package/dist/web-auth/LoginService.js +0 -246
- package/dist/web-auth/TokenService.d.ts +0 -143
- package/dist/web-auth/TokenService.js +0 -249
- package/dist/web-auth/UserService.d.ts +0 -345
- package/dist/web-auth/UserService.js +0 -471
- package/dist/web-auth/VerificationService.d.ts +0 -224
- package/dist/web-auth/VerificationService.js +0 -278
- /package/dist/authentication/{authentication.model.d.ts → Authentication.model.d.ts} +0 -0
- /package/dist/authentication/{authentication.model.js → Authentication.model.js} +0 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { LoginPrecheckRequest, VerificationType } from "../common/Common.model";
|
|
2
|
+
export interface LoginWithCredentialsRequest {
|
|
3
|
+
/** User identifier used to login e.g. username, email or mobile number */
|
|
4
|
+
username: string;
|
|
5
|
+
/** Password required to login */
|
|
6
|
+
password: string;
|
|
7
|
+
/** Request id returned from the authorization call */
|
|
8
|
+
requestId: string;
|
|
9
|
+
/**
|
|
10
|
+
* Type of username used in login
|
|
11
|
+
* BREAKING TODO: change type to UsernameType only in next major version
|
|
12
|
+
* */
|
|
13
|
+
username_type?: UsernameType | string;
|
|
14
|
+
/** Field identifier to tell service, where to look for in case of custom username type */
|
|
15
|
+
field_key?: string;
|
|
16
|
+
/** Login provider configured in cidaas admin ui */
|
|
17
|
+
provider?: string;
|
|
18
|
+
/** DEPRECATED: Captcha string for captcha check */
|
|
19
|
+
captcha?: string;
|
|
20
|
+
/** DEPRECATED: Needed in case bot captcha check is activated */
|
|
21
|
+
bot_captcha_response?: string;
|
|
22
|
+
/** DEPRECATED: Token for validating csrf */
|
|
23
|
+
csrf_token?: string;
|
|
24
|
+
/** Device capacity */
|
|
25
|
+
dc?: string;
|
|
26
|
+
/** Device finger print */
|
|
27
|
+
device_fp?: string;
|
|
28
|
+
/** Id of captcha created in cidaas admin ui */
|
|
29
|
+
captcha_ref?: string;
|
|
30
|
+
/** Response language, which is configured in cidaas admin ui */
|
|
31
|
+
locale?: string;
|
|
32
|
+
/** DEPRECATED: Duplicate parameter, will be removed in next major release version */
|
|
33
|
+
rememberMe?: boolean;
|
|
34
|
+
/** Remember me flag to keep user signed in */
|
|
35
|
+
remember_me?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** Type of username used in login */
|
|
38
|
+
export declare enum UsernameType {
|
|
39
|
+
Email = "email",
|
|
40
|
+
Mobile = "mobile",
|
|
41
|
+
UserName = "user_name",
|
|
42
|
+
Sub = "sub",
|
|
43
|
+
IdentityId = "identityid",
|
|
44
|
+
Custom = "custom"
|
|
45
|
+
}
|
|
46
|
+
export interface SocialProviderPathParameter {
|
|
47
|
+
/** Request id returned from the authorization call */
|
|
48
|
+
requestId: string;
|
|
49
|
+
/** Social login provider configured in cidaas admin ui */
|
|
50
|
+
provider: string;
|
|
51
|
+
}
|
|
52
|
+
export interface SocialProviderQueryParameter {
|
|
53
|
+
/** Device capacity */
|
|
54
|
+
dc?: string;
|
|
55
|
+
/** Device finger print */
|
|
56
|
+
device_fp?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface PasswordlessLoginRequest {
|
|
59
|
+
/** Request id returned from the authorization call */
|
|
60
|
+
requestId: string;
|
|
61
|
+
/** Status id returned from MFA authentication */
|
|
62
|
+
status_id: string;
|
|
63
|
+
/**
|
|
64
|
+
* Type of verification to be used to authenticate user
|
|
65
|
+
* BREAKING TODO: change type to VerificationType only in next major version
|
|
66
|
+
* */
|
|
67
|
+
verificationType: VerificationType | string;
|
|
68
|
+
/**
|
|
69
|
+
* Masked sub (id of user), who will accept the consent.
|
|
70
|
+
* Either sub or q have to be provided, depends on what is given from the query parameter.
|
|
71
|
+
* */
|
|
72
|
+
sub?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Masked sub (id of user), who will accept the consent.
|
|
75
|
+
* Either sub or q have to be provided, depends on what is given from the query parameter.
|
|
76
|
+
* */
|
|
77
|
+
q?: string;
|
|
78
|
+
}
|
|
79
|
+
/** DEPRECATED: MfaContinue should only need LoginPrecheckRequest. The change will be implemented in the next major version */
|
|
80
|
+
export interface MfaContinueRequest extends LoginPrecheckRequest {
|
|
81
|
+
q?: string;
|
|
82
|
+
sub?: string;
|
|
83
|
+
requestId?: string;
|
|
84
|
+
status_id?: string;
|
|
85
|
+
verificationType?: string;
|
|
86
|
+
deviceInfo?: DeviceInfo;
|
|
87
|
+
device_fp?: string;
|
|
88
|
+
}
|
|
89
|
+
/** DEPRECATED: DeviceInfo is only used in MfaContinueRequest, which will be removed in the next major version */
|
|
90
|
+
export interface DeviceInfo {
|
|
91
|
+
userAgent?: string;
|
|
92
|
+
ipAddress?: string;
|
|
93
|
+
lat?: string;
|
|
94
|
+
lon?: string;
|
|
95
|
+
deviceId?: string;
|
|
96
|
+
usedTime?: Date;
|
|
97
|
+
purpose?: string;
|
|
98
|
+
requestId?: string;
|
|
99
|
+
sub?: string;
|
|
100
|
+
pushNotificationId?: string;
|
|
101
|
+
deviceMake?: string;
|
|
102
|
+
deviceModel?: string;
|
|
103
|
+
deviceType?: string;
|
|
104
|
+
}
|
|
105
|
+
export interface FirstTimeChangePasswordRequest {
|
|
106
|
+
/** Id of "force change password setting" returned from the login call, which redirect to change password page */
|
|
107
|
+
loginSettingsId: string;
|
|
108
|
+
/** Old password to be changed */
|
|
109
|
+
old_password: string;
|
|
110
|
+
/** New password to replaced old password */
|
|
111
|
+
new_password: string;
|
|
112
|
+
/** Needed to confirm new password */
|
|
113
|
+
confirm_password: string;
|
|
114
|
+
sub?: string;
|
|
115
|
+
identityId?: string;
|
|
116
|
+
accessToken?: string;
|
|
117
|
+
client_id?: string;
|
|
118
|
+
}
|
|
119
|
+
export interface ProgressiveRegistrationHeader {
|
|
120
|
+
/** Request id returned from the authorization call */
|
|
121
|
+
requestId: string;
|
|
122
|
+
/** Identifier generated after successful authentication but unfulfilled prechecks */
|
|
123
|
+
trackId: string;
|
|
124
|
+
/** Response language, which is configured in cidaas admin ui */
|
|
125
|
+
acceptlanguage?: string;
|
|
126
|
+
/** Latitude is the string location parameter sent in the headers */
|
|
127
|
+
lat?: string;
|
|
128
|
+
/** Longitude is the string location parameter sent in the headers */
|
|
129
|
+
lon?: string;
|
|
130
|
+
}
|
|
131
|
+
export interface LoginAfterRegisterRequest {
|
|
132
|
+
/** Deprecated: will be removed in the next major release */
|
|
133
|
+
device_id?: string;
|
|
134
|
+
/** Device capacity */
|
|
135
|
+
dc?: string;
|
|
136
|
+
/** If true, will keep user logged in */
|
|
137
|
+
rememberMe?: boolean;
|
|
138
|
+
/** Identifier generated after successful registration */
|
|
139
|
+
trackId?: string;
|
|
140
|
+
/** Device fingerprint */
|
|
141
|
+
device_fp?: string;
|
|
142
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UsernameType = void 0;
|
|
4
|
+
/** Type of username used in login */
|
|
5
|
+
var UsernameType;
|
|
6
|
+
(function (UsernameType) {
|
|
7
|
+
UsernameType["Email"] = "email";
|
|
8
|
+
UsernameType["Mobile"] = "mobile";
|
|
9
|
+
UsernameType["UserName"] = "user_name";
|
|
10
|
+
UsernameType["Sub"] = "sub";
|
|
11
|
+
UsernameType["IdentityId"] = "identityid";
|
|
12
|
+
UsernameType["Custom"] = "custom";
|
|
13
|
+
})(UsernameType = exports.UsernameType || (exports.UsernameType = {}));
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { GetAccessTokenRequest, RenewTokenRequest, TokenIntrospectionRequest } from "./TokenService.model";
|
|
2
|
+
import { HTTPRequestHeader, LoginPrecheckRequest } from "../common/Common.model";
|
|
3
|
+
/**
|
|
4
|
+
* To get a new token with the grant type refresh_token, call **renewToken()**.
|
|
5
|
+
* The refresh token to create a new token. The refresh token is received while creating an access token using the token endpoint and later can be used to fetch a new token without using credentials
|
|
6
|
+
* @example
|
|
7
|
+
* ```js
|
|
8
|
+
* const options = {
|
|
9
|
+
* refresh_token: "your refresh token",
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* cidaas.renewToken(options)
|
|
13
|
+
* .then(function (response) {
|
|
14
|
+
* // type your code here
|
|
15
|
+
* })
|
|
16
|
+
* .catch(function (ex) {
|
|
17
|
+
* // your failure code here
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function renewToken(options: RenewTokenRequest): Promise<any>;
|
|
22
|
+
/**
|
|
23
|
+
* To get a new token with the grant type authorization_code, call **getAccessToken()** with code to create a new token.
|
|
24
|
+
* Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/4ff850f48629a-generate-token for more details.
|
|
25
|
+
* @example
|
|
26
|
+
* ```js
|
|
27
|
+
* const options = {
|
|
28
|
+
* code: "your code to be exchanged with access token",
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* cidaas.getAccessToken(options)
|
|
32
|
+
* .then(function (response) {
|
|
33
|
+
* // type your code here
|
|
34
|
+
* })
|
|
35
|
+
* .catch(function (ex) {
|
|
36
|
+
* // your failure code here
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function getAccessToken(options: GetAccessTokenRequest): Promise<any>;
|
|
41
|
+
/**
|
|
42
|
+
* To validate an access token, call **validateAccessToken()**.
|
|
43
|
+
* Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/26ff31e2937f1-introspect-with-bearer-token for more details.
|
|
44
|
+
* @example
|
|
45
|
+
* ```js
|
|
46
|
+
* const options = {
|
|
47
|
+
* token: "your access token",
|
|
48
|
+
* token_type_hint: "accepted token type hints are access_token, id_token, refresh_token, sso",
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* cidaas.validateAccessToken(options)
|
|
52
|
+
* .then(function (response) {
|
|
53
|
+
* // type your code here
|
|
54
|
+
* })
|
|
55
|
+
* .catch(function (ex) {
|
|
56
|
+
* // your failure code here
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function validateAccessToken(options: TokenIntrospectionRequest): Promise<any>;
|
|
61
|
+
/**
|
|
62
|
+
* To get precheck result after login, call **loginPrecheck()**. If there is missing information, user will be redirected to either accepting consent, changing password, continuing MFA process, or do progressive registration
|
|
63
|
+
* Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/aappczju1t3uh-precheck-information for more details.
|
|
64
|
+
* @example
|
|
65
|
+
* ```js
|
|
66
|
+
* const options = {
|
|
67
|
+
* trackId: "your track id from login",
|
|
68
|
+
* locale: "your preferred locale. DEPRECATED as it is not supported anymore. Will be removed in next major release",
|
|
69
|
+
* }
|
|
70
|
+
*
|
|
71
|
+
* cidaas.loginPrecheck(options)
|
|
72
|
+
* .then(function (response) {
|
|
73
|
+
* // type your code here
|
|
74
|
+
* })
|
|
75
|
+
* .catch(function (ex) {
|
|
76
|
+
* // your failure code here
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare function loginPrecheck(options: LoginPrecheckRequest, headers?: HTTPRequestHeader): Promise<any>;
|
|
81
|
+
/**
|
|
82
|
+
* To get the missing fields after login, call **getMissingFields()**.
|
|
83
|
+
* Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/aappczju1t3uh-precheck-information for more details.
|
|
84
|
+
* @example
|
|
85
|
+
* ```js
|
|
86
|
+
* const trackId = "your track id from login";
|
|
87
|
+
* cidaas.getMissingFields(trackId)
|
|
88
|
+
* .then(function (response) {
|
|
89
|
+
* // type your code here
|
|
90
|
+
* })
|
|
91
|
+
* .catch(function (ex) {
|
|
92
|
+
* // your failure code here
|
|
93
|
+
* });
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare function getMissingFields(trackId: string, headers?: HTTPRequestHeader): Promise<any>;
|
|
97
|
+
/**
|
|
98
|
+
* To initiate device code, call **initiateDeviceCode()**.
|
|
99
|
+
* Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/b6d284f55be5e-authorization-request for more details.
|
|
100
|
+
* @example
|
|
101
|
+
* ```js
|
|
102
|
+
* const clientId = "your client id";
|
|
103
|
+
* cidaas.initiateDeviceCode(clientId)
|
|
104
|
+
* .then(function (response) {
|
|
105
|
+
* // type your code here
|
|
106
|
+
* })
|
|
107
|
+
* .catch(function (ex) {
|
|
108
|
+
* // your failure code here
|
|
109
|
+
* });
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare function initiateDeviceCode(clientId?: string): Promise<any>;
|
|
113
|
+
/**
|
|
114
|
+
* To verify device code, call **deviceCodeVerify()**.
|
|
115
|
+
* @example
|
|
116
|
+
* ```js
|
|
117
|
+
* const code = "your code which has been send after initiateDeviceCode()";
|
|
118
|
+
* cidaas.deviceCodeVerify(code)
|
|
119
|
+
* .then(function (response) {
|
|
120
|
+
* // type your code here
|
|
121
|
+
* })
|
|
122
|
+
* .catch(function (ex) {
|
|
123
|
+
* // your failure code here
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function deviceCodeVerify(code: string): void;
|
|
128
|
+
/**
|
|
129
|
+
* To check access token without having to call cidaas api, call **offlineTokenCheck()**. THe function will return true if the token is valid & false if the token is invalid.
|
|
130
|
+
* @example
|
|
131
|
+
* ```js
|
|
132
|
+
* cidaas.offlineTokenCheck('your access token');
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare function offlineTokenCheck(accessToken: string): {
|
|
136
|
+
isExpiryDateValid: boolean;
|
|
137
|
+
isScopesValid: boolean;
|
|
138
|
+
isIssuerValid: boolean;
|
|
139
|
+
};
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.offlineTokenCheck = exports.deviceCodeVerify = exports.initiateDeviceCode = exports.getMissingFields = exports.loginPrecheck = exports.validateAccessToken = exports.getAccessToken = exports.renewToken = void 0;
|
|
13
|
+
const TokenService_model_1 = require("./TokenService.model");
|
|
14
|
+
const Helper_1 = require("../common/Helper");
|
|
15
|
+
const JwtHelper_1 = require("../common/JwtHelper");
|
|
16
|
+
/**
|
|
17
|
+
* To get a new token with the grant type refresh_token, call **renewToken()**.
|
|
18
|
+
* The refresh token to create a new token. The refresh token is received while creating an access token using the token endpoint and later can be used to fetch a new token without using credentials
|
|
19
|
+
* @example
|
|
20
|
+
* ```js
|
|
21
|
+
* const options = {
|
|
22
|
+
* refresh_token: "your refresh token",
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* cidaas.renewToken(options)
|
|
26
|
+
* .then(function (response) {
|
|
27
|
+
* // type your code here
|
|
28
|
+
* })
|
|
29
|
+
* .catch(function (ex) {
|
|
30
|
+
* // your failure code here
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
function renewToken(options) {
|
|
35
|
+
if (!options.refresh_token) {
|
|
36
|
+
throw new Helper_1.CustomException("refresh_token cannot be empty", 417);
|
|
37
|
+
}
|
|
38
|
+
options.client_id = window.webAuthSettings.client_id;
|
|
39
|
+
options.grant_type = TokenService_model_1.GrantType.RefreshToken;
|
|
40
|
+
const _serviceURL = window.webAuthSettings.authority + "/token-srv/token";
|
|
41
|
+
return Helper_1.Helper.createHttpPromise(options, _serviceURL, undefined, "POST");
|
|
42
|
+
}
|
|
43
|
+
exports.renewToken = renewToken;
|
|
44
|
+
/**
|
|
45
|
+
* To get a new token with the grant type authorization_code, call **getAccessToken()** with code to create a new token.
|
|
46
|
+
* Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/4ff850f48629a-generate-token for more details.
|
|
47
|
+
* @example
|
|
48
|
+
* ```js
|
|
49
|
+
* const options = {
|
|
50
|
+
* code: "your code to be exchanged with access token",
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* cidaas.getAccessToken(options)
|
|
54
|
+
* .then(function (response) {
|
|
55
|
+
* // type your code here
|
|
56
|
+
* })
|
|
57
|
+
* .catch(function (ex) {
|
|
58
|
+
* // your failure code here
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
function getAccessToken(options) {
|
|
63
|
+
var _a;
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
if (!options.code) {
|
|
66
|
+
throw new Helper_1.CustomException("code cannot be empty", 417);
|
|
67
|
+
}
|
|
68
|
+
options.client_id = window.webAuthSettings.client_id;
|
|
69
|
+
options.redirect_uri = window.webAuthSettings.redirect_uri;
|
|
70
|
+
options.grant_type = TokenService_model_1.GrantType.AuthorizationCode;
|
|
71
|
+
if (!window.webAuthSettings.disablePKCE) {
|
|
72
|
+
const signInRequest = yield window.usermanager.getClient().createSigninRequest(window.webAuthSettings);
|
|
73
|
+
options.code_verifier = (_a = signInRequest.state) === null || _a === void 0 ? void 0 : _a.code_verifier;
|
|
74
|
+
}
|
|
75
|
+
const _serviceURL = window.webAuthSettings.authority + "/token-srv/token";
|
|
76
|
+
return Helper_1.Helper.createHttpPromise(options, _serviceURL, undefined, "POST");
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
exports.getAccessToken = getAccessToken;
|
|
80
|
+
/**
|
|
81
|
+
* To validate an access token, call **validateAccessToken()**.
|
|
82
|
+
* Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/26ff31e2937f1-introspect-with-bearer-token for more details.
|
|
83
|
+
* @example
|
|
84
|
+
* ```js
|
|
85
|
+
* const options = {
|
|
86
|
+
* token: "your access token",
|
|
87
|
+
* token_type_hint: "accepted token type hints are access_token, id_token, refresh_token, sso",
|
|
88
|
+
* }
|
|
89
|
+
*
|
|
90
|
+
* cidaas.validateAccessToken(options)
|
|
91
|
+
* .then(function (response) {
|
|
92
|
+
* // type your code here
|
|
93
|
+
* })
|
|
94
|
+
* .catch(function (ex) {
|
|
95
|
+
* // your failure code here
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
function validateAccessToken(options) {
|
|
100
|
+
if (!options.token) {
|
|
101
|
+
throw new Helper_1.CustomException("token cannot be empty", 417);
|
|
102
|
+
}
|
|
103
|
+
const _serviceURL = window.webAuthSettings.authority + "/token-srv/introspect";
|
|
104
|
+
return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST", options.token);
|
|
105
|
+
}
|
|
106
|
+
exports.validateAccessToken = validateAccessToken;
|
|
107
|
+
/**
|
|
108
|
+
* To get precheck result after login, call **loginPrecheck()**. If there is missing information, user will be redirected to either accepting consent, changing password, continuing MFA process, or do progressive registration
|
|
109
|
+
* Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/aappczju1t3uh-precheck-information for more details.
|
|
110
|
+
* @example
|
|
111
|
+
* ```js
|
|
112
|
+
* const options = {
|
|
113
|
+
* trackId: "your track id from login",
|
|
114
|
+
* locale: "your preferred locale. DEPRECATED as it is not supported anymore. Will be removed in next major release",
|
|
115
|
+
* }
|
|
116
|
+
*
|
|
117
|
+
* cidaas.loginPrecheck(options)
|
|
118
|
+
* .then(function (response) {
|
|
119
|
+
* // type your code here
|
|
120
|
+
* })
|
|
121
|
+
* .catch(function (ex) {
|
|
122
|
+
* // your failure code here
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
function loginPrecheck(options, headers) {
|
|
127
|
+
const _serviceURL = window.webAuthSettings.authority + "/token-srv/prelogin/metadata/" + options.track_id;
|
|
128
|
+
return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, false, "GET", undefined, headers);
|
|
129
|
+
}
|
|
130
|
+
exports.loginPrecheck = loginPrecheck;
|
|
131
|
+
/**
|
|
132
|
+
* To get the missing fields after login, call **getMissingFields()**.
|
|
133
|
+
* Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/aappczju1t3uh-precheck-information for more details.
|
|
134
|
+
* @example
|
|
135
|
+
* ```js
|
|
136
|
+
* const trackId = "your track id from login";
|
|
137
|
+
* cidaas.getMissingFields(trackId)
|
|
138
|
+
* .then(function (response) {
|
|
139
|
+
* // type your code here
|
|
140
|
+
* })
|
|
141
|
+
* .catch(function (ex) {
|
|
142
|
+
* // your failure code here
|
|
143
|
+
* });
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
function getMissingFields(trackId, headers) {
|
|
147
|
+
const _serviceURL = window.webAuthSettings.authority + "/token-srv/prelogin/metadata/" + trackId;
|
|
148
|
+
return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, false, "GET", undefined, headers);
|
|
149
|
+
}
|
|
150
|
+
exports.getMissingFields = getMissingFields;
|
|
151
|
+
/**
|
|
152
|
+
* To initiate device code, call **initiateDeviceCode()**.
|
|
153
|
+
* Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/b6d284f55be5e-authorization-request for more details.
|
|
154
|
+
* @example
|
|
155
|
+
* ```js
|
|
156
|
+
* const clientId = "your client id";
|
|
157
|
+
* cidaas.initiateDeviceCode(clientId)
|
|
158
|
+
* .then(function (response) {
|
|
159
|
+
* // type your code here
|
|
160
|
+
* })
|
|
161
|
+
* .catch(function (ex) {
|
|
162
|
+
* // your failure code here
|
|
163
|
+
* });
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
function initiateDeviceCode(clientId) {
|
|
167
|
+
const clientid = clientId !== null && clientId !== void 0 ? clientId : window.webAuthSettings.client_id;
|
|
168
|
+
const _serviceURL = `${window.webAuthSettings.authority}/authz-srv/device/authz?client_id=${clientid}`;
|
|
169
|
+
return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, false, "GET");
|
|
170
|
+
}
|
|
171
|
+
exports.initiateDeviceCode = initiateDeviceCode;
|
|
172
|
+
/**
|
|
173
|
+
* To verify device code, call **deviceCodeVerify()**.
|
|
174
|
+
* @example
|
|
175
|
+
* ```js
|
|
176
|
+
* const code = "your code which has been send after initiateDeviceCode()";
|
|
177
|
+
* cidaas.deviceCodeVerify(code)
|
|
178
|
+
* .then(function (response) {
|
|
179
|
+
* // type your code here
|
|
180
|
+
* })
|
|
181
|
+
* .catch(function (ex) {
|
|
182
|
+
* // your failure code here
|
|
183
|
+
* });
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
function deviceCodeVerify(code) {
|
|
187
|
+
const params = `user_code=${encodeURI(code)}`;
|
|
188
|
+
const url = `${window.webAuthSettings.authority}/token-srv/device/verify?${params}`;
|
|
189
|
+
try {
|
|
190
|
+
const options = {
|
|
191
|
+
user_code: encodeURI(code)
|
|
192
|
+
};
|
|
193
|
+
const form = Helper_1.Helper.createForm(url, options, 'GET');
|
|
194
|
+
document.body.appendChild(form);
|
|
195
|
+
form.submit();
|
|
196
|
+
}
|
|
197
|
+
catch (ex) {
|
|
198
|
+
throw new Error(String(ex));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.deviceCodeVerify = deviceCodeVerify;
|
|
202
|
+
/**
|
|
203
|
+
* To check access token without having to call cidaas api, call **offlineTokenCheck()**. THe function will return true if the token is valid & false if the token is invalid.
|
|
204
|
+
* @example
|
|
205
|
+
* ```js
|
|
206
|
+
* cidaas.offlineTokenCheck('your access token');
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
function offlineTokenCheck(accessToken) {
|
|
210
|
+
var _a, _b;
|
|
211
|
+
const result = {
|
|
212
|
+
isExpiryDateValid: false,
|
|
213
|
+
isScopesValid: false,
|
|
214
|
+
isIssuerValid: false,
|
|
215
|
+
};
|
|
216
|
+
const accessTokenHeaderAsJson = JwtHelper_1.JwtHelper.decodeTokenHeader(accessToken);
|
|
217
|
+
const accessTokenAsJson = JwtHelper_1.JwtHelper.decodeToken(accessToken);
|
|
218
|
+
if (!accessTokenAsJson || !accessTokenHeaderAsJson) {
|
|
219
|
+
return result;
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
if (accessTokenAsJson.exp) {
|
|
223
|
+
const expirationDate = new Date(0);
|
|
224
|
+
expirationDate.setUTCSeconds(accessTokenAsJson.exp);
|
|
225
|
+
result.isExpiryDateValid = expirationDate.valueOf() > new Date().valueOf();
|
|
226
|
+
}
|
|
227
|
+
const accessTokenScopes = accessTokenAsJson.scopes;
|
|
228
|
+
const webAuthSettingScopes = (_b = (_a = window.webAuthSettings) === null || _a === void 0 ? void 0 : _a.scope) === null || _b === void 0 ? void 0 : _b.split(' ');
|
|
229
|
+
if ((accessTokenScopes === null || accessTokenScopes === void 0 ? void 0 : accessTokenScopes.length) === (webAuthSettingScopes === null || webAuthSettingScopes === void 0 ? void 0 : webAuthSettingScopes.length)) {
|
|
230
|
+
webAuthSettingScopes.forEach(webAuthSettingScope => {
|
|
231
|
+
const i = accessTokenScopes.indexOf(webAuthSettingScope);
|
|
232
|
+
if (i > -1) {
|
|
233
|
+
accessTokenScopes.splice(i, 1);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
result.isScopesValid = accessTokenScopes.length === 0;
|
|
237
|
+
}
|
|
238
|
+
result.isIssuerValid = accessTokenAsJson.iss === window.webAuthSettings.authority;
|
|
239
|
+
}
|
|
240
|
+
return result;
|
|
241
|
+
}
|
|
242
|
+
exports.offlineTokenCheck = offlineTokenCheck;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
export interface TokenHeader {
|
|
2
|
+
/** Algorithm, which is used to secure token */
|
|
3
|
+
alg: string;
|
|
4
|
+
/** Key identifier to verify token signature */
|
|
5
|
+
kid: string;
|
|
6
|
+
}
|
|
7
|
+
export interface TokenClaim {
|
|
8
|
+
/** Issuer identifier */
|
|
9
|
+
iss: string;
|
|
10
|
+
/** Subject (User) identifier */
|
|
11
|
+
sub: string;
|
|
12
|
+
/** Client id, used during authentication or token generation */
|
|
13
|
+
aud: string;
|
|
14
|
+
/** Expiration time of token */
|
|
15
|
+
exp: number;
|
|
16
|
+
/** Time when token was generated */
|
|
17
|
+
iat: number;
|
|
18
|
+
/** A unique identifier for the token, which can be used to prevent reuse of the token */
|
|
19
|
+
jti: string;
|
|
20
|
+
/** Time when active authentication by user was done */
|
|
21
|
+
auth_time?: number;
|
|
22
|
+
/** String value used to associate a client session with an id token, and to mitigate replay attacks */
|
|
23
|
+
nonce?: string;
|
|
24
|
+
/** String specifying an Authentication Context Class Reference value */
|
|
25
|
+
acr?: string;
|
|
26
|
+
/** Authentication Methods References. JSON array of strings that are identifiers for authentication methods used in the authentication */
|
|
27
|
+
amr?: string[];
|
|
28
|
+
/** Authorized party. The party to which the ID Token was issued */
|
|
29
|
+
azp?: string;
|
|
30
|
+
/** Access token hash value */
|
|
31
|
+
at_hash?: string;
|
|
32
|
+
/** Code hash value */
|
|
33
|
+
c_hash?: string;
|
|
34
|
+
/** List of user roles */
|
|
35
|
+
roles?: string[];
|
|
36
|
+
/** List of scopes requested */
|
|
37
|
+
scopes?: string[];
|
|
38
|
+
/** List of user group */
|
|
39
|
+
groups?: Group[];
|
|
40
|
+
/** Session identifier */
|
|
41
|
+
sid?: string;
|
|
42
|
+
/** Identity subject. Identity id of the user */
|
|
43
|
+
isub?: string;
|
|
44
|
+
/** Provider user identifier */
|
|
45
|
+
psub?: string;
|
|
46
|
+
/** Not before */
|
|
47
|
+
nbf?: number;
|
|
48
|
+
/** User agent hash */
|
|
49
|
+
ua_hash?: string;
|
|
50
|
+
/** List of unaccepted consents */
|
|
51
|
+
consents?: Consent[];
|
|
52
|
+
/** DEPRECATED: replaced with aud claim */
|
|
53
|
+
clientid?: string;
|
|
54
|
+
/** DEPRECATED: replaced with scopes claim */
|
|
55
|
+
scope?: string;
|
|
56
|
+
/** DEPRECATED: replaced with roles claim */
|
|
57
|
+
role?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface Group {
|
|
60
|
+
/** Unique identifier for the group */
|
|
61
|
+
groupId: string;
|
|
62
|
+
/** List of group roles */
|
|
63
|
+
roles: string[];
|
|
64
|
+
}
|
|
65
|
+
export interface Consent {
|
|
66
|
+
/** Unique identifier for the consent */
|
|
67
|
+
consent_id: string;
|
|
68
|
+
/** Unique identifier for one particular consent version */
|
|
69
|
+
consent_version_id: string;
|
|
70
|
+
/** Consent Status whether it has been accepted */
|
|
71
|
+
accepted: boolean;
|
|
72
|
+
/** Time when the consent is created */
|
|
73
|
+
creation_time: string;
|
|
74
|
+
}
|
|
75
|
+
export interface RenewTokenRequest {
|
|
76
|
+
/** One time valid code that is used for issuing a new token */
|
|
77
|
+
refresh_token: string;
|
|
78
|
+
/** Unique identifier of client app, can be found in app setting under admin ui */
|
|
79
|
+
client_id?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Type of grant used in token request
|
|
82
|
+
* BREAKING TODO: change type to GrantType only in next major version
|
|
83
|
+
*/
|
|
84
|
+
grant_type?: GrantType | string;
|
|
85
|
+
}
|
|
86
|
+
/** Type of grant used in token request */
|
|
87
|
+
export declare enum GrantType {
|
|
88
|
+
AuthorizationCode = "authorization_code",
|
|
89
|
+
Implicit = "implicit",
|
|
90
|
+
RefreshToken = "refresh_token",
|
|
91
|
+
Password = "password",
|
|
92
|
+
ClientCredentials = "client_credentials",
|
|
93
|
+
Internal = "internal",
|
|
94
|
+
DeviceCode = "urn:ietf:params:oauth:grant-type:device_code"
|
|
95
|
+
}
|
|
96
|
+
export interface GetAccessTokenRequest {
|
|
97
|
+
/** The code which you receive while using authorization code flow */
|
|
98
|
+
code: string;
|
|
99
|
+
/** When we choose PKCE method to generate token, we need to pass code_verifier which is a cryptographically random string */
|
|
100
|
+
code_verifier?: string;
|
|
101
|
+
/** Unique identifier of client app, can be found in app setting under admin ui */
|
|
102
|
+
client_id?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Type of grant used in token request
|
|
105
|
+
* BREAKING TODO: change type to GrantType only in next major version
|
|
106
|
+
* */
|
|
107
|
+
grant_type?: GrantType | string;
|
|
108
|
+
/** Specify the url where the user needs to be redirected after successful login */
|
|
109
|
+
redirect_uri?: string;
|
|
110
|
+
}
|
|
111
|
+
export declare class TokenIntrospectionRequest {
|
|
112
|
+
/** access token to be inspected */
|
|
113
|
+
token: string;
|
|
114
|
+
/**
|
|
115
|
+
* Optional hint about the type of the submitted token.
|
|
116
|
+
* BREAKING TODO: change type to TokenTypeHint only in next major version
|
|
117
|
+
* */
|
|
118
|
+
token_type_hint?: TokenTypeHint | string;
|
|
119
|
+
/** List of roles to match */
|
|
120
|
+
roles?: string[];
|
|
121
|
+
/** List of scopes to match */
|
|
122
|
+
scopes?: string[];
|
|
123
|
+
/** List of groups to match */
|
|
124
|
+
groups?: GroupAllowed[];
|
|
125
|
+
/** If true, all roles have to be included. If false, only 1 role from the list is needed */
|
|
126
|
+
strictRoleValidation?: boolean;
|
|
127
|
+
/** If true, all group have to be included. If false, only 1 group from the list is needed */
|
|
128
|
+
strictGroupValidation?: boolean;
|
|
129
|
+
/** If true, all scopes have to be included. If false, only 1 scope from the list is needed */
|
|
130
|
+
strictScopeValidation?: boolean;
|
|
131
|
+
/** If true, all defined roles and/or groups and/or scopes validation has to be succesful. If false, only 1 of them is needed */
|
|
132
|
+
strictValidation?: boolean;
|
|
133
|
+
}
|
|
134
|
+
/** Optional hint about the type of the submitted token. */
|
|
135
|
+
export declare enum TokenTypeHint {
|
|
136
|
+
AccessToken = "access_token",
|
|
137
|
+
RefreshToken = "refresh_token",
|
|
138
|
+
IdToken = "id_token",
|
|
139
|
+
Sid = "sid",
|
|
140
|
+
Sso = "sso"
|
|
141
|
+
}
|
|
142
|
+
export declare class GroupAllowed {
|
|
143
|
+
/** Unique group id */
|
|
144
|
+
id: string;
|
|
145
|
+
/** List of grouproles to match */
|
|
146
|
+
roles: string[];
|
|
147
|
+
/** If true, all roles have to be included. If false, only 1 role from the list is needed */
|
|
148
|
+
strictRoleValidation: boolean;
|
|
149
|
+
}
|