@livechat/accounts-sdk 2.2.3 → 2.2.4-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accounts-sdk.js +30 -7
- package/dist/accounts-sdk.js.map +1 -1
- package/dist/accounts-sdk.min.js +1 -1
- package/dist/accounts-sdk.min.js.map +1 -1
- package/dist/index.cjs.js +31 -7
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +31 -7
- package/dist/index.esm.js.map +1 -1
- package/package.json +22 -4
- package/readme.md +14 -157
package/dist/accounts-sdk.js
CHANGED
|
@@ -4007,6 +4007,25 @@
|
|
|
4007
4007
|
string: string
|
|
4008
4008
|
};
|
|
4009
4009
|
|
|
4010
|
+
/**
|
|
4011
|
+
* Normalize PKCE options, support deprecated code_challange_method option
|
|
4012
|
+
* @param {object|undefined} pkce PKCE options
|
|
4013
|
+
* @returns {object|undefined} normalized PKCE options
|
|
4014
|
+
*/
|
|
4015
|
+
function normalizePkce(pkce) {
|
|
4016
|
+
if (!pkce || pkce.code_challange_method === undefined) {
|
|
4017
|
+
return pkce;
|
|
4018
|
+
}
|
|
4019
|
+
const normalized = Object.assign({}, pkce);
|
|
4020
|
+
// eslint-disable-next-line max-len
|
|
4021
|
+
console.warn('[accounts-sdk] pkce.code_challange_method is deprecated and will be removed in v3.0.0. Use code_challenge_method instead.');
|
|
4022
|
+
if (normalized.code_challenge_method === undefined) {
|
|
4023
|
+
normalized.code_challenge_method = normalized.code_challange_method;
|
|
4024
|
+
}
|
|
4025
|
+
delete normalized.code_challange_method;
|
|
4026
|
+
return normalized;
|
|
4027
|
+
}
|
|
4028
|
+
|
|
4010
4029
|
/**
|
|
4011
4030
|
* Accounts SDK main class
|
|
4012
4031
|
*/
|
|
@@ -4037,7 +4056,8 @@
|
|
|
4037
4056
|
* @param {string} [options.pkce.code_verifier] override auto generated code verifier
|
|
4038
4057
|
* @param {number} [options.pkce.code_verifier_length] code verifier length, between 43 and 128 characters
|
|
4039
4058
|
* https://tools.ietf.org/html/rfc7636#section-4.1 (default: `128`)
|
|
4040
|
-
* @param {string} [options.pkce.
|
|
4059
|
+
* @param {string} [options.pkce.code_challenge_method] code challenge method, use `S256` or `plain` (default: `S256`)
|
|
4060
|
+
* @param {string} [options.pkce.code_challange_method] **Deprecated.** Use `code_challenge_method` instead.
|
|
4041
4061
|
*/
|
|
4042
4062
|
constructor() {
|
|
4043
4063
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -4068,10 +4088,11 @@
|
|
|
4068
4088
|
pkce: {
|
|
4069
4089
|
enabled: true,
|
|
4070
4090
|
code_verifier_length: 128,
|
|
4071
|
-
|
|
4091
|
+
code_challenge_method: 'S256'
|
|
4072
4092
|
}
|
|
4073
4093
|
};
|
|
4074
4094
|
this.options = Object.assign({}, defaultOptions, options);
|
|
4095
|
+
this.options.pkce = normalizePkce(this.options.pkce);
|
|
4075
4096
|
this.transaction = new Transaction(this.options);
|
|
4076
4097
|
this.redirectUriParamsPersister = new RedirectUriParamsPersister(this.options);
|
|
4077
4098
|
}
|
|
@@ -4119,6 +4140,7 @@
|
|
|
4119
4140
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
4120
4141
|
let flow = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
4121
4142
|
const localOptions = Object.assign({}, this.options, options);
|
|
4143
|
+
localOptions.pkce = normalizePkce(localOptions.pkce);
|
|
4122
4144
|
if (!localOptions.state) {
|
|
4123
4145
|
localOptions.state = random.string(localOptions.key_length);
|
|
4124
4146
|
}
|
|
@@ -4145,14 +4167,15 @@
|
|
|
4145
4167
|
}
|
|
4146
4168
|
if (localOptions.response_type === 'code' && localOptions.pkce.enabled) {
|
|
4147
4169
|
const codeVerifier = localOptions.pkce.code_verifier || random.string(localOptions.pkce.code_verifier_length);
|
|
4148
|
-
switch (localOptions.pkce.
|
|
4170
|
+
switch (localOptions.pkce.code_challenge_method) {
|
|
4149
4171
|
case 'S256':
|
|
4150
4172
|
{
|
|
4151
|
-
const
|
|
4173
|
+
const hashBits = sjcl.hash.sha256.hash(codeVerifier);
|
|
4174
|
+
const hashBytes = hashBits.reduce((s, w) => s + String.fromCharCode(w >>> 24 & 0xff, w >>> 16 & 0xff, w >>> 8 & 0xff, w & 0xff), '');
|
|
4152
4175
|
Object.assign(params, {
|
|
4153
4176
|
code_verifier: codeVerifier,
|
|
4154
|
-
code_challenge: encoding.base64URLEncode(
|
|
4155
|
-
code_challenge_method: localOptions.pkce.
|
|
4177
|
+
code_challenge: encoding.base64URLEncode(hashBytes),
|
|
4178
|
+
code_challenge_method: localOptions.pkce.code_challenge_method
|
|
4156
4179
|
});
|
|
4157
4180
|
break;
|
|
4158
4181
|
}
|
|
@@ -4160,7 +4183,7 @@
|
|
|
4160
4183
|
Object.assign(params, {
|
|
4161
4184
|
code_verifier: codeVerifier,
|
|
4162
4185
|
code_challenge: codeVerifier,
|
|
4163
|
-
code_challenge_method: localOptions.pkce.
|
|
4186
|
+
code_challenge_method: localOptions.pkce.code_challenge_method
|
|
4164
4187
|
});
|
|
4165
4188
|
}
|
|
4166
4189
|
}
|