rest-client-sdk 7.4.0 → 7.5.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/README.md CHANGED
@@ -106,6 +106,27 @@ browser environment and
106
106
  [React Native AsyncStorage](https://facebook.github.io/react-native/docs/asyncstorage.html)
107
107
  for React Native.
108
108
 
109
+ ##### Authorization code flow with PKCE
110
+
111
+ `AuthorizationCodeFlowTokenGenerator` supports [PKCE](https://datatracker.ietf.org/doc/html/rfc7636). The SDK does not generate the `code_verifier` nor the `code_challenge`: generate them before redirecting to the authorize endpoint, then pass the verifier with the received `code`. `clientSecret` is optional, omit it for a public client.
112
+
113
+ ```js
114
+ import {
115
+ AuthorizationCodeFlowTokenGenerator,
116
+ TokenStorage,
117
+ } from 'rest-client-sdk';
118
+
119
+ const tokenGenerator = new AuthorizationCodeFlowTokenGenerator({
120
+ path: 'oauth.me/token',
121
+ scheme: 'https',
122
+ clientId: 'my-client-id',
123
+ redirectUri: 'https://my.app/callback',
124
+ });
125
+ const tokenStorage = new TokenStorage(tokenGenerator, storage);
126
+
127
+ await tokenStorage.generateToken({ code, codeVerifier });
128
+ ```
129
+
109
130
  #### Configure the SDK
110
131
 
111
132
  ```js
package/dist/index.cjs CHANGED
@@ -1936,14 +1936,15 @@
1936
1936
  headers: {
1937
1937
  'Content-Type': 'application/x-www-form-urlencoded'
1938
1938
  },
1939
- body: new URLSearchParams({
1939
+ body: new URLSearchParams(_objectSpread2(_objectSpread2({
1940
1940
  grant_type: 'authorization_code',
1941
- client_id: this.tokenGeneratorConfig.clientId,
1942
- client_secret: this.tokenGeneratorConfig.clientSecret,
1943
- // TODO : secure this ?
1941
+ client_id: this.tokenGeneratorConfig.clientId
1942
+ }, this._clientSecretParameter()), {}, {
1944
1943
  redirect_uri: this.tokenGeneratorConfig.redirectUri,
1945
1944
  code: parameters.code
1946
- }).toString()
1945
+ }, parameters.codeVerifier ? {
1946
+ code_verifier: parameters.codeVerifier
1947
+ } : {})).toString()
1947
1948
  };
1948
1949
  if (this.logger) {
1949
1950
  this.logger.logRequest(_objectSpread2({
@@ -1972,12 +1973,12 @@
1972
1973
  headers: {
1973
1974
  'Content-Type': 'application/x-www-form-urlencoded'
1974
1975
  },
1975
- body: new URLSearchParams({
1976
+ body: new URLSearchParams(_objectSpread2(_objectSpread2({
1976
1977
  grant_type: 'refresh_token',
1977
- client_id: this.tokenGeneratorConfig.clientId,
1978
- client_secret: this.tokenGeneratorConfig.clientSecret,
1978
+ client_id: this.tokenGeneratorConfig.clientId
1979
+ }, this._clientSecretParameter()), {}, {
1979
1980
  refresh_token: oldAccessToken.refresh_token
1980
- }).toString()
1981
+ })).toString()
1981
1982
  };
1982
1983
  if (this.logger) {
1983
1984
  this.logger.logRequest(_objectSpread2({
@@ -1995,13 +1996,21 @@
1995
1996
  if (!(config.path && config.scheme)) {
1996
1997
  throw new RangeError('TokenGenerator config is not valid, it should contain a "path", a "scheme" parameter');
1997
1998
  }
1998
- if (!(config.clientId && config.clientSecret)) {
1999
- throw new RangeError('TokenGenerator config is not valid, it should contain a "clientId", a "clientSecret" parameter');
1999
+ if (!config.clientId) {
2000
+ throw new RangeError('TokenGenerator config is not valid, it should contain a "clientId" parameter');
2000
2001
  }
2001
2002
  if (!config.redirectUri) {
2002
2003
  throw new RangeError('TokenGenerator config is not valid, it should contain a "redirectUri" parameter');
2003
2004
  }
2004
2005
  }
2006
+ }, {
2007
+ key: "_clientSecretParameter",
2008
+ value: function _clientSecretParameter() {
2009
+ var clientSecret = this.tokenGeneratorConfig.clientSecret;
2010
+ return clientSecret ? {
2011
+ client_secret: clientSecret
2012
+ } : {};
2013
+ }
2005
2014
  }, {
2006
2015
  key: "_checkGenerateParameters",
2007
2016
  value: function _checkGenerateParameters(parameters) {