@looker/sdk-rtl 21.3.1 → 21.3.2

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 CHANGED
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ### [21.3.1](https://www.github.com/looker-open-source/sdk-codegen/compare/sdk-rtl-v21.2.0...sdk-rtl-v21.3.1) (2022-01-27)
9
+
10
+
11
+ ### Features
12
+
13
+ * add http method to IRawResponse ([#925](https://www.github.com/looker-open-source/sdk-codegen/issues/925)) ([25cef47](https://www.github.com/looker-open-source/sdk-codegen/commit/25cef47fa61a5f15565560b48f5e0c45a0cd9b44))
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * rtl IError type ([#928](https://www.github.com/looker-open-source/sdk-codegen/issues/928)) ([7d8f906](https://www.github.com/looker-open-source/sdk-codegen/commit/7d8f906f4b10b5e915df292fcf30d1eb456c3463))
19
+ * **sdk-rtl/src/delimArray:** Fixed issue with single element number array ([#927](https://www.github.com/looker-open-source/sdk-codegen/issues/927)) ([6e94d73](https://www.github.com/looker-open-source/sdk-codegen/commit/6e94d73f88fb6c2f3138818967f4e8cb49ff89e6))
20
+
8
21
  ### [21.3.1](https://www.github.com/looker-open-source/sdk-codegen/compare/sdk-rtl-v21.3.0...sdk-rtl-v21.3.1) (2021-12-20)
9
22
 
10
23
 
package/lib/delimArray.js CHANGED
@@ -12,7 +12,7 @@ class DelimArray extends Array {
12
12
  var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ',';
13
13
  var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
14
14
  var suffix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
15
- super(...(items || []));
15
+ super();
16
16
  this.separator = separator;
17
17
  this.prefix = prefix;
18
18
  this.suffix = suffix;
@@ -20,6 +20,8 @@ class DelimArray extends Array {
20
20
  _defineProperty(this, "toString", () => {
21
21
  return "".concat(this.prefix).concat(this.join(this.separator)).concat(this.suffix);
22
22
  });
23
+
24
+ this.push(...(items || []));
23
25
  }
24
26
 
25
27
  static create() {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/delimArray.ts"],"names":["DelimArray","Array","constructor","items","separator","prefix","suffix","join","create","Object","prototype"],"mappings":";;;;;;;;;AA0BO,MAAMA,UAAN,SAA4BC,KAA5B,CAAqC;AAC1CC,EAAAA,WAAW,CACTC,KADS,EAKT;AAAA,QAHOC,SAGP,uEAH2B,GAG3B;AAAA,QAFOC,MAEP,uEAFwB,EAExB;AAAA,QADOC,MACP,uEADwB,EACxB;AACA,UAAM,IAAIH,KAAK,IAAI,EAAb,CAAN;AADA,SAHOC,SAGP,GAHOA,SAGP;AAAA,SAFOC,MAEP,GAFOA,MAEP;AAAA,SADOC,MACP,GADOA,MACP;;AAAA,sCAYgB,MAAc;AAC9B,uBAAU,KAAKD,MAAf,SAAwB,KAAKE,IAAL,CAAU,KAAKH,SAAf,CAAxB,SAAoD,KAAKE,MAAzD;AACD,KAdC;AAED;;AAEY,SAANE,MAAM,GAAqB;AAChC,WAAOC,MAAM,CAACD,MAAP,CAAcR,UAAU,CAACU,SAAzB,CAAP;AACD;;AAZyC","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nexport class DelimArray<T> extends Array<T> {\n constructor(\n items?: Array<T>,\n public separator: string = ',',\n public prefix: string = '',\n public suffix: string = ''\n ) {\n super(...(items || []))\n }\n\n static create<T>(): DelimArray<T> {\n return Object.create(DelimArray.prototype)\n }\n\n /**\n * Override of Array<T> toString so custom separators can be used\n * @returns {string} Delimited version of array\n */\n public toString = (): string => {\n return `${this.prefix}${this.join(this.separator)}${this.suffix}`\n }\n}\n"],"file":"delimArray.js"}
1
+ {"version":3,"sources":["../src/delimArray.ts"],"names":["DelimArray","Array","constructor","items","separator","prefix","suffix","join","push","create","Object","prototype"],"mappings":";;;;;;;;;AA0BO,MAAMA,UAAN,SAA4BC,KAA5B,CAAqC;AAC1CC,EAAAA,WAAW,CACTC,KADS,EAKT;AAAA,QAHOC,SAGP,uEAH2B,GAG3B;AAAA,QAFOC,MAEP,uEAFwB,EAExB;AAAA,QADOC,MACP,uEADwB,EACxB;AACA;AADA,SAHOF,SAGP,GAHOA,SAGP;AAAA,SAFOC,MAEP,GAFOA,MAEP;AAAA,SADOC,MACP,GADOA,MACP;;AAAA,sCAagB,MAAc;AAC9B,uBAAU,KAAKD,MAAf,SAAwB,KAAKE,IAAL,CAAU,KAAKH,SAAf,CAAxB,SAAoD,KAAKE,MAAzD;AACD,KAfC;;AAEA,SAAKE,IAAL,CAAU,IAAIL,KAAK,IAAI,EAAb,CAAV;AACD;;AAEY,SAANM,MAAM,GAAqB;AAChC,WAAOC,MAAM,CAACD,MAAP,CAAcT,UAAU,CAACW,SAAzB,CAAP;AACD;;AAbyC","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nexport class DelimArray<T> extends Array<T> {\n constructor(\n items?: Array<T>,\n public separator: string = ',',\n public prefix: string = '',\n public suffix: string = ''\n ) {\n super()\n this.push(...(items || []))\n }\n\n static create<T>(): DelimArray<T> {\n return Object.create(DelimArray.prototype)\n }\n\n /**\n * Override of Array<T> toString so custom separators can be used\n * @returns {string} Delimited version of array\n */\n public toString = (): string => {\n return `${this.prefix}${this.join(this.separator)}${this.suffix}`\n }\n}\n"],"file":"delimArray.js"}
@@ -5,7 +5,7 @@ export class DelimArray extends Array {
5
5
  var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ',';
6
6
  var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
7
7
  var suffix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
8
- super(...(items || []));
8
+ super();
9
9
  this.separator = separator;
10
10
  this.prefix = prefix;
11
11
  this.suffix = suffix;
@@ -13,6 +13,8 @@ export class DelimArray extends Array {
13
13
  _defineProperty(this, "toString", () => {
14
14
  return "".concat(this.prefix).concat(this.join(this.separator)).concat(this.suffix);
15
15
  });
16
+
17
+ this.push(...(items || []));
16
18
  }
17
19
 
18
20
  static create() {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/delimArray.ts"],"names":["DelimArray","Array","constructor","items","separator","prefix","suffix","join","create","Object","prototype"],"mappings":";;AA0BA,OAAO,MAAMA,UAAN,SAA4BC,KAA5B,CAAqC;AAC1CC,EAAAA,WAAW,CACTC,KADS,EAKT;AAAA,QAHOC,SAGP,uEAH2B,GAG3B;AAAA,QAFOC,MAEP,uEAFwB,EAExB;AAAA,QADOC,MACP,uEADwB,EACxB;AACA,UAAM,IAAIH,KAAK,IAAI,EAAb,CAAN;AADA,SAHOC,SAGP,GAHOA,SAGP;AAAA,SAFOC,MAEP,GAFOA,MAEP;AAAA,SADOC,MACP,GADOA,MACP;;AAAA,sCAYgB,MAAc;AAC9B,uBAAU,KAAKD,MAAf,SAAwB,KAAKE,IAAL,CAAU,KAAKH,SAAf,CAAxB,SAAoD,KAAKE,MAAzD;AACD,KAdC;AAED;;AAEY,SAANE,MAAM,GAAqB;AAChC,WAAOC,MAAM,CAACD,MAAP,CAAcR,UAAU,CAACU,SAAzB,CAAP;AACD;;AAZyC","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nexport class DelimArray<T> extends Array<T> {\n constructor(\n items?: Array<T>,\n public separator: string = ',',\n public prefix: string = '',\n public suffix: string = ''\n ) {\n super(...(items || []))\n }\n\n static create<T>(): DelimArray<T> {\n return Object.create(DelimArray.prototype)\n }\n\n /**\n * Override of Array<T> toString so custom separators can be used\n * @returns {string} Delimited version of array\n */\n public toString = (): string => {\n return `${this.prefix}${this.join(this.separator)}${this.suffix}`\n }\n}\n"],"file":"delimArray.js"}
1
+ {"version":3,"sources":["../../src/delimArray.ts"],"names":["DelimArray","Array","constructor","items","separator","prefix","suffix","join","push","create","Object","prototype"],"mappings":";;AA0BA,OAAO,MAAMA,UAAN,SAA4BC,KAA5B,CAAqC;AAC1CC,EAAAA,WAAW,CACTC,KADS,EAKT;AAAA,QAHOC,SAGP,uEAH2B,GAG3B;AAAA,QAFOC,MAEP,uEAFwB,EAExB;AAAA,QADOC,MACP,uEADwB,EACxB;AACA;AADA,SAHOF,SAGP,GAHOA,SAGP;AAAA,SAFOC,MAEP,GAFOA,MAEP;AAAA,SADOC,MACP,GADOA,MACP;;AAAA,sCAagB,MAAc;AAC9B,uBAAU,KAAKD,MAAf,SAAwB,KAAKE,IAAL,CAAU,KAAKH,SAAf,CAAxB,SAAoD,KAAKE,MAAzD;AACD,KAfC;;AAEA,SAAKE,IAAL,CAAU,IAAIL,KAAK,IAAI,EAAb,CAAV;AACD;;AAEY,SAANM,MAAM,GAAqB;AAChC,WAAOC,MAAM,CAACD,MAAP,CAAcT,UAAU,CAACW,SAAzB,CAAP;AACD;;AAbyC","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nexport class DelimArray<T> extends Array<T> {\n constructor(\n items?: Array<T>,\n public separator: string = ',',\n public prefix: string = '',\n public suffix: string = ''\n ) {\n super()\n this.push(...(items || []))\n }\n\n static create<T>(): DelimArray<T> {\n return Object.create(DelimArray.prototype)\n }\n\n /**\n * Override of Array<T> toString so custom separators can be used\n * @returns {string} Delimited version of array\n */\n public toString = (): string => {\n return `${this.prefix}${this.join(this.separator)}${this.suffix}`\n }\n}\n"],"file":"delimArray.js"}
@@ -19,6 +19,8 @@ export class OAuthSession extends AuthSession {
19
19
 
20
20
  _defineProperty(this, "crypto", void 0);
21
21
 
22
+ _defineProperty(this, "reentry", false);
23
+
22
24
  this.crypto = services.crypto;
23
25
  var keys = ['client_id', 'redirect_uri', 'base_url', 'looker_url'];
24
26
 
@@ -87,12 +89,13 @@ export class OAuthSession extends AuthSession {
87
89
 
88
90
  return _asyncToGenerator(function* () {
89
91
  if (!_this2.isAuthenticated()) {
90
- if (!_this2.returnUrl) {
92
+ if (_this2.reentry) {} else if (!_this2.returnUrl) {
91
93
  var authUrl = yield _this2.createAuthCodeRequestUrl('cors_api', agentPrefix);
92
94
  var returnTo = window.location.pathname + window.location.search;
93
95
  _this2.returnUrl = returnTo;
94
96
  window.location.href = authUrl;
95
97
  } else {
98
+ _this2.reentry = true;
96
99
  _this2.returnUrl = null;
97
100
 
98
101
  if (!_this2.code_verifier) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/oauthSession.ts"],"names":["AuthSession","agentPrefix","sdkError","AuthToken","OAuthSession","constructor","services","settings","transport","crypto","keys","config","readConfig","forEach","key","value","message","authenticate","props","token","getToken","access_token","headers","Authorization","code_verifier","sessionStorage","getItem","codeVerifierKey","removeItem","setItem","returnUrl","returnUrlKey","clearStorage","login","_sudoId","isAuthenticated","authUrl","createAuthCodeRequestUrl","returnTo","window","location","pathname","search","href","Promise","reject","Error","params","URLSearchParams","code","get","redeemAuthCode","activeToken","requestToken","body","url","URL","base_url","ok","request","toString","undefined","setToken","scope","state","secureRandom","code_challenge","sha256Hash","client_id","code_challenge_method","redirect_uri","response_type","looker_url","redeemAuthCodeBody","authCode","codeVerifier","verifier","grant_type","refresh_token","isActive","logout","init"],"mappings":";;;;;;;;;;AA2BA,SAASA,WAAT,QAA4B,eAA5B;AAEA,SAASC,WAAT,EAAsBC,QAAtB,QAAsC,aAAtC;AACA,SAASC,SAAT,QAA0B,aAA1B;AAmBA,OAAO,MAAMC,YAAN,SAA2BJ,WAA3B,CAAuC;AAM5CK,EAAAA,WAAW,CAACC,QAAD,EAA8B;AACvC,UAAMA,QAAQ,CAACC,QAAf,EAAyBD,QAAQ,CAACE,SAAlC;;AADuC,yCAL3B,IAAIL,SAAJ,EAK2B;;AAAA;;AAGvC,SAAKM,MAAL,GAAcH,QAAQ,CAACG,MAAvB;AAEA,QAA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,CAACyD,SADI;AAEtBS,YAAAA,UAAU,EAAE,eAFU;AAGtBP,YAAAA,YAAY,EAAE3D,MAAM,CAAC2D,YAHC;AAItBQ,YAAAA,aAAa,EAAE,MAAI,CAAC1B,WAAL,CAAiB0B;AAJV,WAAlB,CAAN;AAMD;AACF;;AACD,aAAO,MAAI,CAAC1B,WAAZ;AAZe;AAahB;;AAEDjB,EAAAA,eAAe,GAAY;AACzB,WAAO,KAAKiB,WAAL,CAAiB2B,QAAjB,EAAP;AACD;;AAEKC,EAAAA,MAAM,GAAG;AAAA;;AAAA;AACb,UAAI,MAAI,CAAC5B,WAAL,CAAiB/B,YAArB,EAAmC;AACjC,cAAM,MAAI,CAACqC,EAAL,CACJ,MAAI,CAAClD,SAAL,CAAemD,OAAf,CACE,QADF,iBAGEE,SAHF,EAIEA,SAJF,EAKGoB,IAAD,IAAyB;AACvBA,UAAAA,IAAI,CAAC3D,OAAL,CAAaC,aAAb,oBAAuC,MAAI,CAAC6B,WAAL,CAAiB/B,YAAxD;AACA,iBAAO4D,IAAP;AACD,SARH,CADI,CAAN;AAcA,QAAA,MAAI,CAAC7B,WAAL,GAAmB,IAAIjD,SAAJ,EAAnB;;AACA,QAAA,MAAI,CAAC6B,YAAL;;AACA,eAAO,IAAP;AACD;;AACD,aAAO,KAAP;AApBa;AAqBd;;AAzP2C;;gBAAjC5B,Y,qBAG+B,4B;;gBAH/BA,Y,kBAI2B,yB","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport type { IAccessToken, IError } from './authSession'\nimport { AuthSession } from './authSession'\nimport type { IRequestProps } from './transport'\nimport { agentPrefix, sdkError } from './transport'\nimport { AuthToken } from './authToken'\nimport type { ICryptoHash } from './cryptoHash'\nimport type { IPlatformServices } from './platformServices'\n\ninterface IAuthCodeGrantTypeParams {\n grant_type: 'authorization_code'\n code: string\n code_verifier: string\n client_id: string\n redirect_uri: string\n}\n\ninterface IRefreshTokenGrantTypeParams {\n grant_type: 'refresh_token'\n refresh_token: string\n client_id: string\n redirect_uri: string\n}\n\nexport class OAuthSession extends AuthSession {\n activeToken = new AuthToken()\n crypto: ICryptoHash\n private static readonly codeVerifierKey = 'looker_oauth_code_verifier'\n public static readonly returnUrlKey = 'looker_oauth_return_url'\n\n constructor(services: IPlatformServices) {\n super(services.settings, services.transport)\n\n this.crypto = services.crypto\n\n const keys: string[] = [\n 'client_id',\n 'redirect_uri',\n 'base_url',\n 'looker_url',\n ]\n const config = { ...this.settings, ...this.settings.readConfig() }\n\n keys.forEach((key) => {\n const value = config[key]\n if (!value) {\n throw sdkError({\n message: `Missing required configuration setting: '${key}'`,\n })\n }\n })\n }\n\n /**\n * merge the dynamically defined configuration values with the initial settings\n */\n readConfig() {\n return { ...this.settings, ...this.settings.readConfig() }\n }\n\n /**\n * Apply current auth token credentials to an HTTP request\n * @param props request properties to update\n * @returns updated request properties with auth information added\n */\n async authenticate(props: IRequestProps): Promise<IRequestProps> {\n const token = await this.getToken()\n if (token.access_token) {\n props.headers.Authorization = `Bearer ${token.access_token}`\n }\n return props\n }\n\n /**\n * Gets session storage for OAuth code verification\n * @returns saved code verifier\n */\n get code_verifier() {\n return sessionStorage.getItem(OAuthSession.codeVerifierKey)\n }\n\n /**\n * Sets session storage for OAuth code verification\n */\n set code_verifier(value: string | null) {\n if (value === null) {\n // only clear code_verifier if it's `null`\n sessionStorage.removeItem(OAuthSession.codeVerifierKey)\n } else {\n sessionStorage.setItem(OAuthSession.codeVerifierKey, value)\n }\n }\n\n /**\n * URL to return to after login process completes\n * @returns the URL that started the OAuth login process\n */\n get returnUrl() {\n return sessionStorage.getItem(OAuthSession.returnUrlKey)\n }\n\n /**\n * Sets the return URL for successful OAuth login\n */\n set returnUrl(value: string | null) {\n if (!value) {\n sessionStorage.removeItem(OAuthSession.returnUrlKey)\n } else {\n sessionStorage.setItem(OAuthSession.returnUrlKey, value)\n }\n }\n\n /**\n * Clears all Looker SDK OAuth-related session storage\n */\n clearStorage() {\n sessionStorage.removeItem(OAuthSession.codeVerifierKey)\n sessionStorage.removeItem(OAuthSession.returnUrlKey)\n }\n\n async login(_sudoId?: string | number): Promise<any> {\n if (!this.isAuthenticated()) {\n if (!this.returnUrl) {\n // OAuth has not been initiated\n const authUrl = await this.createAuthCodeRequestUrl(\n 'cors_api',\n agentPrefix\n )\n const returnTo = window.location.pathname + window.location.search\n this.returnUrl = returnTo\n // Save the current URL so redirected successful OAuth login can restore it\n window.location.href = authUrl\n } else {\n // If return URL is stored, we must be coming back from an OAuth request\n // so release the stored return url at the start of the redemption\n this.returnUrl = null\n if (!this.code_verifier) {\n return Promise.reject(\n new Error('OAuth failed: expected code_verifier to be stored')\n )\n }\n const params = new URLSearchParams(window.location.search)\n const code = params.get('code')\n if (!code) {\n return Promise.reject(\n new Error(\n `OAuth failed: no OAuth code parameter found in ${\n window.location.pathname + window.location.search\n }`\n )\n )\n }\n await this.redeemAuthCode(code)\n }\n return await this.getToken()\n }\n return this.activeToken\n }\n\n private async requestToken(\n body: IAuthCodeGrantTypeParams | IRefreshTokenGrantTypeParams\n ) {\n const config = this.readConfig()\n const url = new URL(config.base_url)\n // replace the entire path of the base_url because this\n // auth endpoint is independent of API version\n url.pathname = '/api/token'\n const token = await this.ok(\n this.transport.request<IAccessToken, IError>(\n 'POST',\n url.toString(),\n undefined,\n body\n )\n )\n\n return this.activeToken.setToken(token)\n }\n\n /*\n Generate an OAuth2 authCode request URL\n */\n async createAuthCodeRequestUrl(\n scope: string,\n state: string\n ): Promise<string> {\n // TODO: remove this comment when we remove hex backwards compatibility\n // in Looker API. For now it must not be 2^n so that Looker correctly\n // treats it as base64 encoded\n this.code_verifier = this.crypto.secureRandom(33)\n const code_challenge = await this.crypto.sha256Hash(this.code_verifier)\n const config = this.readConfig()\n const params: Record<string, string> = {\n client_id: config.client_id,\n code_challenge: code_challenge,\n code_challenge_method: 'S256',\n redirect_uri: config.redirect_uri,\n response_type: 'code',\n scope: scope,\n state: state,\n }\n const url = new URL(config.looker_url)\n url.pathname = '/auth'\n url.search = new URLSearchParams(params).toString()\n return url.toString()\n }\n\n redeemAuthCodeBody(authCode: string, codeVerifier?: string) {\n const verifier = codeVerifier || this.code_verifier || ''\n const config = this.readConfig()\n return {\n client_id: config.client_id,\n code: authCode,\n code_verifier: verifier,\n grant_type: 'authorization_code',\n redirect_uri: config.redirect_uri,\n } as IAuthCodeGrantTypeParams\n }\n\n /**\n * Convert an authCode received from server into an active auth token\n * The app is responsible for obtaining the authCode via interactive user login\n * via /auth front-end endpoint and URL redirect. When the authCode is received\n * by url redirect to an app route, pass the authCode into this function to\n * get an access_token and refresh_token.\n * @param {string} authCode\n * @param {string} codeVerifier\n * @returns {Promise<AuthToken>}\n */\n async redeemAuthCode(authCode: string, codeVerifier?: string) {\n return this.requestToken(this.redeemAuthCodeBody(authCode, codeVerifier))\n }\n\n async getToken() {\n if (!this.isAuthenticated()) {\n if (this.activeToken.refresh_token) {\n const config = this.readConfig()\n await this.requestToken({\n client_id: config.client_id,\n grant_type: 'refresh_token',\n redirect_uri: config.redirect_uri,\n refresh_token: this.activeToken.refresh_token,\n })\n }\n }\n return this.activeToken\n }\n\n isAuthenticated(): boolean {\n return this.activeToken.isActive()\n }\n\n async logout() {\n if (this.activeToken.access_token) {\n await this.ok(\n this.transport.request<IAccessToken, IError>(\n 'DELETE',\n `/api/logout`,\n undefined,\n undefined,\n (init: IRequestProps) => {\n init.headers.Authorization = `Bearer ${this.activeToken.access_token}`\n return init\n }\n )\n )\n\n // logout destroys the access_token AND the refresh_token\n this.activeToken = new AuthToken()\n this.clearStorage()\n return true\n }\n return false\n }\n}\n"],"file":"oauthSession.js"}
1
+ {"version":3,"sources":["../../src/oauthSession.ts"],"names":["AuthSession","agentPrefix","sdkError","AuthToken","OAuthSession","constructor","services","settings","transport","crypto","keys","config","readConfig","forEach","key","value","message","authenticate","props","token","getToken","access_token","headers","Authorization","code_verifier","sessionStorage","getItem","codeVerifierKey","removeItem","setItem","returnUrl","returnUrlKey","clearStorage","login","_sudoId","isAuthenticated","reentry","authUrl","createAuthCodeRequestUrl","returnTo","window","location","pathname","search","href","Promise","reject","Error","params","URLSearchParams","code","get","redeemAuthCode","activeToken","requestToken","body","url","URL","base_url","ok","request","toString","undefined","setToken","scope","state","secureRandom","code_challenge","sha256Hash","client_id","code_challenge_method","redirect_uri","response_type","looker_url","redeemAuthCodeBody","authCode","codeVerifier","verifier","grant_type","refresh_token","isActive","logout","init"],"mappings":";;;;;;;;;;AA2BA,SAASA,WAAT,QAA4B,eAA5B;AAEA,SAASC,WAAT,EAAsBC,QAAtB,QAAsC,aAAtC;AACA,SAASC,SAAT,QAA0B,aAA1B;AAmBA,OAAO,MAAMC,YAAN,SAA2BJ,WAA3B,CAAuC;AAO5CK,EAAAA,WAAW,CAACC,QAAD,EAA8B;AACvC,UAAMA,QAAQ,CAACC,QAAf,EAAyBD,QAAQ,CAACE,SAAlC;;AADuC,yCAN3B,IAAIL,SAAJ,EAM2B;;AAAA;;AA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B,YAAI,MAAI,CAACkB,WAAL,CAAiB0B,aAArB,EAAoC;AAClC,cAAMpE,MAAM,GAAG,MAAI,CAACC,UAAL,EAAf;;AACA,gBAAM,MAAI,CAAC0C,YAAL,CAAkB;AACtBe,YAAAA,SAAS,EAAE1D,MAAM,CAAC0D,SADI;AAEtBS,YAAAA,UAAU,EAAE,eAFU;AAGtBP,YAAAA,YAAY,EAAE5D,MAAM,CAAC4D,YAHC;AAItBQ,YAAAA,aAAa,EAAE,MAAI,CAAC1B,WAAL,CAAiB0B;AAJV,WAAlB,CAAN;AAMD;AACF;;AACD,aAAO,MAAI,CAAC1B,WAAZ;AAZe;AAahB;;AAEDlB,EAAAA,eAAe,GAAY;AACzB,WAAO,KAAKkB,WAAL,CAAiB2B,QAAjB,EAAP;AACD;;AAEKC,EAAAA,MAAM,GAAG;AAAA;;AAAA;AACb,UAAI,MAAI,CAAC5B,WAAL,CAAiBhC,YAArB,EAAmC;AACjC,cAAM,MAAI,CAACsC,EAAL,CACJ,MAAI,CAACnD,SAAL,CAAeoD,OAAf,CACE,QADF,iBAGEE,SAHF,EAIEA,SAJF,EAKGoB,IAAD,IAAyB;AACvBA,UAAAA,IAAI,CAAC5D,OAAL,CAAaC,aAAb,oBAAuC,MAAI,CAAC8B,WAAL,CAAiBhC,YAAxD;AACA,iBAAO6D,IAAP;AACD,SARH,CADI,CAAN;AAcA,QAAA,MAAI,CAAC7B,WAAL,GAAmB,IAAIlD,SAAJ,EAAnB;;AACA,QAAA,MAAI,CAAC6B,YAAL;;AACA,eAAO,IAAP;AACD;;AACD,aAAO,KAAP;AApBa;AAqBd;;AA7P2C;;gBAAjC5B,Y,qBAI+B,4B;;gBAJ/BA,Y,kBAK2B,yB","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport type { IAccessToken, IError } from './authSession'\nimport { AuthSession } from './authSession'\nimport type { IRequestProps } from './transport'\nimport { agentPrefix, sdkError } from './transport'\nimport { AuthToken } from './authToken'\nimport type { ICryptoHash } from './cryptoHash'\nimport type { IPlatformServices } from './platformServices'\n\ninterface IAuthCodeGrantTypeParams {\n grant_type: 'authorization_code'\n code: string\n code_verifier: string\n client_id: string\n redirect_uri: string\n}\n\ninterface IRefreshTokenGrantTypeParams {\n grant_type: 'refresh_token'\n refresh_token: string\n client_id: string\n redirect_uri: string\n}\n\nexport class OAuthSession extends AuthSession {\n activeToken = new AuthToken()\n crypto: ICryptoHash\n reentry = false\n private static readonly codeVerifierKey = 'looker_oauth_code_verifier'\n public static readonly returnUrlKey = 'looker_oauth_return_url'\n\n constructor(services: IPlatformServices) {\n super(services.settings, services.transport)\n\n this.crypto = services.crypto\n\n const keys: string[] = [\n 'client_id',\n 'redirect_uri',\n 'base_url',\n 'looker_url',\n ]\n const config = { ...this.settings, ...this.settings.readConfig() }\n\n keys.forEach((key) => {\n const value = config[key]\n if (!value) {\n throw sdkError({\n message: `Missing required configuration setting: '${key}'`,\n })\n }\n })\n }\n\n /**\n * merge the dynamically defined configuration values with the initial settings\n */\n readConfig() {\n return { ...this.settings, ...this.settings.readConfig() }\n }\n\n /**\n * Apply current auth token credentials to an HTTP request\n * @param props request properties to update\n * @returns updated request properties with auth information added\n */\n async authenticate(props: IRequestProps): Promise<IRequestProps> {\n const token = await this.getToken()\n if (token.access_token) {\n props.headers.Authorization = `Bearer ${token.access_token}`\n }\n return props\n }\n\n /**\n * Gets session storage for OAuth code verification\n * @returns saved code verifier\n */\n get code_verifier() {\n return sessionStorage.getItem(OAuthSession.codeVerifierKey)\n }\n\n /**\n * Sets session storage for OAuth code verification\n */\n set code_verifier(value: string | null) {\n if (value === null) {\n // only clear code_verifier if it's `null`\n sessionStorage.removeItem(OAuthSession.codeVerifierKey)\n } else {\n sessionStorage.setItem(OAuthSession.codeVerifierKey, value)\n }\n }\n\n /**\n * URL to return to after login process completes\n * @returns the URL that started the OAuth login process\n */\n get returnUrl() {\n return sessionStorage.getItem(OAuthSession.returnUrlKey)\n }\n\n /**\n * Sets the return URL for successful OAuth login\n */\n set returnUrl(value: string | null) {\n if (!value) {\n sessionStorage.removeItem(OAuthSession.returnUrlKey)\n } else {\n sessionStorage.setItem(OAuthSession.returnUrlKey, value)\n }\n }\n\n /**\n * Clears all Looker SDK OAuth-related session storage\n */\n clearStorage() {\n sessionStorage.removeItem(OAuthSession.codeVerifierKey)\n sessionStorage.removeItem(OAuthSession.returnUrlKey)\n }\n\n async login(_sudoId?: string | number): Promise<any> {\n if (!this.isAuthenticated()) {\n if (this.reentry) {\n // do nothing\n } else if (!this.returnUrl) {\n // OAuth has not been initiated\n const authUrl = await this.createAuthCodeRequestUrl(\n 'cors_api',\n agentPrefix\n )\n const returnTo = window.location.pathname + window.location.search\n this.returnUrl = returnTo\n // Save the current URL so redirected successful OAuth login can restore it\n window.location.href = authUrl\n } else {\n this.reentry = true\n // If return URL is stored, we must be coming back from an OAuth request\n // so release the stored return url at the start of the redemption\n this.returnUrl = null\n if (!this.code_verifier) {\n return Promise.reject(\n new Error('OAuth failed: expected code_verifier to be stored')\n )\n }\n const params = new URLSearchParams(window.location.search)\n const code = params.get('code')\n if (!code) {\n return Promise.reject(\n new Error(\n `OAuth failed: no OAuth code parameter found in ${\n window.location.pathname + window.location.search\n }`\n )\n )\n }\n await this.redeemAuthCode(code)\n }\n return await this.getToken()\n }\n return this.activeToken\n }\n\n private async requestToken(\n body: IAuthCodeGrantTypeParams | IRefreshTokenGrantTypeParams\n ) {\n const config = this.readConfig()\n const url = new URL(config.base_url)\n // replace the entire path of the base_url because this\n // auth endpoint is independent of API version\n url.pathname = '/api/token'\n const token = await this.ok(\n this.transport.request<IAccessToken, IError>(\n 'POST',\n url.toString(),\n undefined,\n body\n )\n )\n\n return this.activeToken.setToken(token)\n }\n\n /*\n Generate an OAuth2 authCode request URL\n */\n async createAuthCodeRequestUrl(\n scope: string,\n state: string\n ): Promise<string> {\n // TODO: remove this comment when we remove hex backwards compatibility\n // in Looker API. For now it must not be 2^n so that Looker correctly\n // treats it as base64 encoded\n this.code_verifier = this.crypto.secureRandom(33)\n const code_challenge = await this.crypto.sha256Hash(this.code_verifier)\n const config = this.readConfig()\n const params: Record<string, string> = {\n client_id: config.client_id,\n code_challenge: code_challenge,\n code_challenge_method: 'S256',\n redirect_uri: config.redirect_uri,\n response_type: 'code',\n scope: scope,\n state: state,\n }\n const url = new URL(config.looker_url)\n url.pathname = '/auth'\n url.search = new URLSearchParams(params).toString()\n return url.toString()\n }\n\n redeemAuthCodeBody(authCode: string, codeVerifier?: string) {\n const verifier = codeVerifier || this.code_verifier || ''\n const config = this.readConfig()\n return {\n client_id: config.client_id,\n code: authCode,\n code_verifier: verifier,\n grant_type: 'authorization_code',\n redirect_uri: config.redirect_uri,\n } as IAuthCodeGrantTypeParams\n }\n\n /**\n * Convert an authCode received from server into an active auth token\n * The app is responsible for obtaining the authCode via interactive user login\n * via /auth front-end endpoint and URL redirect. When the authCode is received\n * by url redirect to an app route, pass the authCode into this function to\n * get an access_token and refresh_token.\n * @param {string} authCode\n * @param {string} codeVerifier\n * @returns {Promise<AuthToken>}\n */\n async redeemAuthCode(authCode: string, codeVerifier?: string) {\n return this.requestToken(this.redeemAuthCodeBody(authCode, codeVerifier))\n }\n\n async getToken() {\n if (!this.isAuthenticated()) {\n if (this.activeToken.refresh_token) {\n const config = this.readConfig()\n await this.requestToken({\n client_id: config.client_id,\n grant_type: 'refresh_token',\n redirect_uri: config.redirect_uri,\n refresh_token: this.activeToken.refresh_token,\n })\n }\n }\n return this.activeToken\n }\n\n isAuthenticated(): boolean {\n return this.activeToken.isActive()\n }\n\n async logout() {\n if (this.activeToken.access_token) {\n await this.ok(\n this.transport.request<IAccessToken, IError>(\n 'DELETE',\n `/api/logout`,\n undefined,\n undefined,\n (init: IRequestProps) => {\n init.headers.Authorization = `Bearer ${this.activeToken.access_token}`\n return init\n }\n )\n )\n\n // logout destroys the access_token AND the refresh_token\n this.activeToken = new AuthToken()\n this.clearStorage()\n return true\n }\n return false\n }\n}\n"],"file":"oauthSession.js"}
@@ -14,6 +14,7 @@ interface IAuthCodeGrantTypeParams {
14
14
  export declare class OAuthSession extends AuthSession {
15
15
  activeToken: AuthToken;
16
16
  crypto: ICryptoHash;
17
+ reentry: boolean;
17
18
  private static readonly codeVerifierKey;
18
19
  static readonly returnUrlKey = "looker_oauth_return_url";
19
20
  constructor(services: IPlatformServices);
@@ -29,6 +29,8 @@ class OAuthSession extends _authSession.AuthSession {
29
29
 
30
30
  _defineProperty(this, "crypto", void 0);
31
31
 
32
+ _defineProperty(this, "reentry", false);
33
+
32
34
  this.crypto = services.crypto;
33
35
  var keys = ['client_id', 'redirect_uri', 'base_url', 'looker_url'];
34
36
 
@@ -97,12 +99,13 @@ class OAuthSession extends _authSession.AuthSession {
97
99
 
98
100
  return _asyncToGenerator(function* () {
99
101
  if (!_this2.isAuthenticated()) {
100
- if (!_this2.returnUrl) {
102
+ if (_this2.reentry) {} else if (!_this2.returnUrl) {
101
103
  var authUrl = yield _this2.createAuthCodeRequestUrl('cors_api', _transport.agentPrefix);
102
104
  var returnTo = window.location.pathname + window.location.search;
103
105
  _this2.returnUrl = returnTo;
104
106
  window.location.href = authUrl;
105
107
  } else {
108
+ _this2.reentry = true;
106
109
  _this2.returnUrl = null;
107
110
 
108
111
  if (!_this2.code_verifier) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/oauthSession.ts"],"names":["OAuthSession","AuthSession","constructor","services","settings","transport","AuthToken","crypto","keys","config","readConfig","forEach","key","value","message","authenticate","props","token","getToken","access_token","headers","Authorization","code_verifier","sessionStorage","getItem","codeVerifierKey","removeItem","setItem","returnUrl","returnUrlKey","clearStorage","login","_sudoId","isAuthenticated","authUrl","createAuthCodeRequestUrl","agentPrefix","returnTo","window","location","pathname","search","href","Promise","reject","Error","params","URLSearchParams","code","get","redeemAuthCode","activeToken","requestToken","body","url","URL","base_url","ok","request","toString","undefined","setToken","scope","state","secureRandom","code_challenge","sha256Hash","client_id","code_challenge_method","redirect_uri","response_type","looker_url","redeemAuthCodeBody","authCode","codeVerifier","verifier","grant_type","refresh_token","isActive","logout","init"],"mappings":";;;;;;;AA2BA;;AAEA;;AACA;;;;;;;;;;;;AAmBO,MAAMA,YAAN,SAA2BC,wBAA3B,CAAuC;AAM5CC,EAAAA,WAAW,CAACC,QAAD,EAA8B;AACvC,UAAMA,QAAQ,CAACC,QAAf,EAAyBD,QAAQ,CAACE,SAAlC;;AADuC,yCAL3B,IAAIC,oBAAJ,EAK2B;;AAAA;;AAGvC,SAAKC,MAAL,GAAcJ,QAAQ,CAACI,MAAvB;AAEA,QAAMC,IAAc,GAAG,CACrB,WADqB,EAErB,cAFqB,EAGrB,UAHqB,EAIrB,YAJqB,CAAvB;;AAMA,QAAMC,MAAM,mCAAQ,KAAKL,QAAb,GAA0B,KAAKA,QAAL,CAAcM,UAAd,EAA1B,CAAZ;;AAEAF,IAAAA,IAAI,CAACG,OAAL,CAAcC,GAAD,IAAS;AACpB,UAAMC,KAAK,GAAGJ,MAA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AY;AACzB,WAAO,KAAKkB,WAAL,CAAiB2B,QAAjB,EAAP;AACD;;AAEKC,EAAAA,MAAM,GAAG;AAAA;;AAAA;AACb,UAAI,MAAI,CAAC5B,WAAL,CAAiBhC,YAArB,EAAmC;AACjC,cAAM,MAAI,CAACsC,EAAL,CACJ,MAAI,CAACpD,SAAL,CAAeqD,OAAf,CACE,QADF,iBAGEE,SAHF,EAIEA,SAJF,EAKGoB,IAAD,IAAyB;AACvBA,UAAAA,IAAI,CAAC5D,OAAL,CAAaC,aAAb,oBAAuC,MAAI,CAAC8B,WAAL,CAAiBhC,YAAxD;AACA,iBAAO6D,IAAP;AACD,SARH,CADI,CAAN;AAcA,QAAA,MAAI,CAAC7B,WAAL,GAAmB,IAAI7C,oBAAJ,EAAnB;;AACA,QAAA,MAAI,CAACwB,YAAL;;AACA,eAAO,IAAP;AACD;;AACD,aAAO,KAAP;AApBa;AAqBd;;AAzP2C;;;;gBAAjC9B,Y,qBAG+B,4B;;gBAH/BA,Y,kBAI2B,yB","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport type { IAccessToken, IError } from './authSession'\nimport { AuthSession } from './authSession'\nimport type { IRequestProps } from './transport'\nimport { agentPrefix, sdkError } from './transport'\nimport { AuthToken } from './authToken'\nimport type { ICryptoHash } from './cryptoHash'\nimport type { IPlatformServices } from './platformServices'\n\ninterface IAuthCodeGrantTypeParams {\n grant_type: 'authorization_code'\n code: string\n code_verifier: string\n client_id: string\n redirect_uri: string\n}\n\ninterface IRefreshTokenGrantTypeParams {\n grant_type: 'refresh_token'\n refresh_token: string\n client_id: string\n redirect_uri: string\n}\n\nexport class OAuthSession extends AuthSession {\n activeToken = new AuthToken()\n crypto: ICryptoHash\n private static readonly codeVerifierKey = 'looker_oauth_code_verifier'\n public static readonly returnUrlKey = 'looker_oauth_return_url'\n\n constructor(services: IPlatformServices) {\n super(services.settings, services.transport)\n\n this.crypto = services.crypto\n\n const keys: string[] = [\n 'client_id',\n 'redirect_uri',\n 'base_url',\n 'looker_url',\n ]\n const config = { ...this.settings, ...this.settings.readConfig() }\n\n keys.forEach((key) => {\n const value = config[key]\n if (!value) {\n throw sdkError({\n message: `Missing required configuration setting: '${key}'`,\n })\n }\n })\n }\n\n /**\n * merge the dynamically defined configuration values with the initial settings\n */\n readConfig() {\n return { ...this.settings, ...this.settings.readConfig() }\n }\n\n /**\n * Apply current auth token credentials to an HTTP request\n * @param props request properties to update\n * @returns updated request properties with auth information added\n */\n async authenticate(props: IRequestProps): Promise<IRequestProps> {\n const token = await this.getToken()\n if (token.access_token) {\n props.headers.Authorization = `Bearer ${token.access_token}`\n }\n return props\n }\n\n /**\n * Gets session storage for OAuth code verification\n * @returns saved code verifier\n */\n get code_verifier() {\n return sessionStorage.getItem(OAuthSession.codeVerifierKey)\n }\n\n /**\n * Sets session storage for OAuth code verification\n */\n set code_verifier(value: string | null) {\n if (value === null) {\n // only clear code_verifier if it's `null`\n sessionStorage.removeItem(OAuthSession.codeVerifierKey)\n } else {\n sessionStorage.setItem(OAuthSession.codeVerifierKey, value)\n }\n }\n\n /**\n * URL to return to after login process completes\n * @returns the URL that started the OAuth login process\n */\n get returnUrl() {\n return sessionStorage.getItem(OAuthSession.returnUrlKey)\n }\n\n /**\n * Sets the return URL for successful OAuth login\n */\n set returnUrl(value: string | null) {\n if (!value) {\n sessionStorage.removeItem(OAuthSession.returnUrlKey)\n } else {\n sessionStorage.setItem(OAuthSession.returnUrlKey, value)\n }\n }\n\n /**\n * Clears all Looker SDK OAuth-related session storage\n */\n clearStorage() {\n sessionStorage.removeItem(OAuthSession.codeVerifierKey)\n sessionStorage.removeItem(OAuthSession.returnUrlKey)\n }\n\n async login(_sudoId?: string | number): Promise<any> {\n if (!this.isAuthenticated()) {\n if (!this.returnUrl) {\n // OAuth has not been initiated\n const authUrl = await this.createAuthCodeRequestUrl(\n 'cors_api',\n agentPrefix\n )\n const returnTo = window.location.pathname + window.location.search\n this.returnUrl = returnTo\n // Save the current URL so redirected successful OAuth login can restore it\n window.location.href = authUrl\n } else {\n // If return URL is stored, we must be coming back from an OAuth request\n // so release the stored return url at the start of the redemption\n this.returnUrl = null\n if (!this.code_verifier) {\n return Promise.reject(\n new Error('OAuth failed: expected code_verifier to be stored')\n )\n }\n const params = new URLSearchParams(window.location.search)\n const code = params.get('code')\n if (!code) {\n return Promise.reject(\n new Error(\n `OAuth failed: no OAuth code parameter found in ${\n window.location.pathname + window.location.search\n }`\n )\n )\n }\n await this.redeemAuthCode(code)\n }\n return await this.getToken()\n }\n return this.activeToken\n }\n\n private async requestToken(\n body: IAuthCodeGrantTypeParams | IRefreshTokenGrantTypeParams\n ) {\n const config = this.readConfig()\n const url = new URL(config.base_url)\n // replace the entire path of the base_url because this\n // auth endpoint is independent of API version\n url.pathname = '/api/token'\n const token = await this.ok(\n this.transport.request<IAccessToken, IError>(\n 'POST',\n url.toString(),\n undefined,\n body\n )\n )\n\n return this.activeToken.setToken(token)\n }\n\n /*\n Generate an OAuth2 authCode request URL\n */\n async createAuthCodeRequestUrl(\n scope: string,\n state: string\n ): Promise<string> {\n // TODO: remove this comment when we remove hex backwards compatibility\n // in Looker API. For now it must not be 2^n so that Looker correctly\n // treats it as base64 encoded\n this.code_verifier = this.crypto.secureRandom(33)\n const code_challenge = await this.crypto.sha256Hash(this.code_verifier)\n const config = this.readConfig()\n const params: Record<string, string> = {\n client_id: config.client_id,\n code_challenge: code_challenge,\n code_challenge_method: 'S256',\n redirect_uri: config.redirect_uri,\n response_type: 'code',\n scope: scope,\n state: state,\n }\n const url = new URL(config.looker_url)\n url.pathname = '/auth'\n url.search = new URLSearchParams(params).toString()\n return url.toString()\n }\n\n redeemAuthCodeBody(authCode: string, codeVerifier?: string) {\n const verifier = codeVerifier || this.code_verifier || ''\n const config = this.readConfig()\n return {\n client_id: config.client_id,\n code: authCode,\n code_verifier: verifier,\n grant_type: 'authorization_code',\n redirect_uri: config.redirect_uri,\n } as IAuthCodeGrantTypeParams\n }\n\n /**\n * Convert an authCode received from server into an active auth token\n * The app is responsible for obtaining the authCode via interactive user login\n * via /auth front-end endpoint and URL redirect. When the authCode is received\n * by url redirect to an app route, pass the authCode into this function to\n * get an access_token and refresh_token.\n * @param {string} authCode\n * @param {string} codeVerifier\n * @returns {Promise<AuthToken>}\n */\n async redeemAuthCode(authCode: string, codeVerifier?: string) {\n return this.requestToken(this.redeemAuthCodeBody(authCode, codeVerifier))\n }\n\n async getToken() {\n if (!this.isAuthenticated()) {\n if (this.activeToken.refresh_token) {\n const config = this.readConfig()\n await this.requestToken({\n client_id: config.client_id,\n grant_type: 'refresh_token',\n redirect_uri: config.redirect_uri,\n refresh_token: this.activeToken.refresh_token,\n })\n }\n }\n return this.activeToken\n }\n\n isAuthenticated(): boolean {\n return this.activeToken.isActive()\n }\n\n async logout() {\n if (this.activeToken.access_token) {\n await this.ok(\n this.transport.request<IAccessToken, IError>(\n 'DELETE',\n `/api/logout`,\n undefined,\n undefined,\n (init: IRequestProps) => {\n init.headers.Authorization = `Bearer ${this.activeToken.access_token}`\n return init\n }\n )\n )\n\n // logout destroys the access_token AND the refresh_token\n this.activeToken = new AuthToken()\n this.clearStorage()\n return true\n }\n return false\n }\n}\n"],"file":"oauthSession.js"}
1
+ {"version":3,"sources":["../src/oauthSession.ts"],"names":["OAuthSession","AuthSession","constructor","services","settings","transport","AuthToken","crypto","keys","config","readConfig","forEach","key","value","message","authenticate","props","token","getToken","access_token","headers","Authorization","code_verifier","sessionStorage","getItem","codeVerifierKey","removeItem","setItem","returnUrl","returnUrlKey","clearStorage","login","_sudoId","isAuthenticated","reentry","authUrl","createAuthCodeRequestUrl","agentPrefix","returnTo","window","location","pathname","search","href","Promise","reject","Error","params","URLSearchParams","code","get","redeemAuthCode","activeToken","requestToken","body","url","URL","base_url","ok","request","toString","undefined","setToken","scope","state","secureRandom","code_challenge","sha256Hash","client_id","code_challenge_method","redirect_uri","response_type","looker_url","redeemAuthCodeBody","authCode","codeVerifier","verifier","grant_type","refresh_token","isActive","logout","init"],"mappings":";;;;;;;AA2BA;;AAEA;;AACA;;;;;;;;;;;;AAmBO,MAAMA,YAAN,SAA2BC,wBAA3B,CAAuC;AAO5CC,EAAAA,WAAW,CAACC,QAAD,EAA8B;AACvC,UAAMA,QAAQ,CAACC,QAAf,EAAyBD,QAAQ,CAACE,SAAlC;;AADuC,yCAN3B,IAAIC,oBAAJ,EAM2B;;AAAA;;AAAA,qCAJ/B,KAI+B;;AAGvC,SAAKC,MAAL,GAAcJ,QAAQ,CAACI,MAAvB;AAEA,QAAMC,IAAc,GAAG,CACrB,WADqB,EAErB,cAFqB,EAGrB,UAHqB,EAIrB,YAJqB,CAAvB;;AAMA,QAAMC,MAAM,mCAAQ,KAAKL,QAAb,GAA0B,KAAKA,QAAL,CAAcM,UAAd,EAA1B,CAAZ;;AAEAF,IAAAA,IAAI,CAACG,OAAL,CAAcC,GAAD,IAAS;AACpB,UAAMC,KAAK,GAAGJ,MAAM,CAACG,GAAD,C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AACF;;AACD,aAAO,MAAI,CAAC1B,WAAZ;AAZe;AAahB;;AAEDnB,EAAAA,eAAe,GAAY;AACzB,WAAO,KAAKmB,WAAL,CAAiB2B,QAAjB,EAAP;AACD;;AAEKC,EAAAA,MAAM,GAAG;AAAA;;AAAA;AACb,UAAI,MAAI,CAAC5B,WAAL,CAAiBjC,YAArB,EAAmC;AACjC,cAAM,MAAI,CAACuC,EAAL,CACJ,MAAI,CAACrD,SAAL,CAAesD,OAAf,CACE,QADF,iBAGEE,SAHF,EAIEA,SAJF,EAKGoB,IAAD,IAAyB;AACvBA,UAAAA,IAAI,CAAC7D,OAAL,CAAaC,aAAb,oBAAuC,MAAI,CAAC+B,WAAL,CAAiBjC,YAAxD;AACA,iBAAO8D,IAAP;AACD,SARH,CADI,CAAN;AAcA,QAAA,MAAI,CAAC7B,WAAL,GAAmB,IAAI9C,oBAAJ,EAAnB;;AACA,QAAA,MAAI,CAACwB,YAAL;;AACA,eAAO,IAAP;AACD;;AACD,aAAO,KAAP;AApBa;AAqBd;;AA7P2C;;;;gBAAjC9B,Y,qBAI+B,4B;;gBAJ/BA,Y,kBAK2B,yB","sourcesContent":["/*\n\n MIT License\n\n Copyright (c) 2021 Looker Data Sciences, Inc.\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n */\n\nimport type { IAccessToken, IError } from './authSession'\nimport { AuthSession } from './authSession'\nimport type { IRequestProps } from './transport'\nimport { agentPrefix, sdkError } from './transport'\nimport { AuthToken } from './authToken'\nimport type { ICryptoHash } from './cryptoHash'\nimport type { IPlatformServices } from './platformServices'\n\ninterface IAuthCodeGrantTypeParams {\n grant_type: 'authorization_code'\n code: string\n code_verifier: string\n client_id: string\n redirect_uri: string\n}\n\ninterface IRefreshTokenGrantTypeParams {\n grant_type: 'refresh_token'\n refresh_token: string\n client_id: string\n redirect_uri: string\n}\n\nexport class OAuthSession extends AuthSession {\n activeToken = new AuthToken()\n crypto: ICryptoHash\n reentry = false\n private static readonly codeVerifierKey = 'looker_oauth_code_verifier'\n public static readonly returnUrlKey = 'looker_oauth_return_url'\n\n constructor(services: IPlatformServices) {\n super(services.settings, services.transport)\n\n this.crypto = services.crypto\n\n const keys: string[] = [\n 'client_id',\n 'redirect_uri',\n 'base_url',\n 'looker_url',\n ]\n const config = { ...this.settings, ...this.settings.readConfig() }\n\n keys.forEach((key) => {\n const value = config[key]\n if (!value) {\n throw sdkError({\n message: `Missing required configuration setting: '${key}'`,\n })\n }\n })\n }\n\n /**\n * merge the dynamically defined configuration values with the initial settings\n */\n readConfig() {\n return { ...this.settings, ...this.settings.readConfig() }\n }\n\n /**\n * Apply current auth token credentials to an HTTP request\n * @param props request properties to update\n * @returns updated request properties with auth information added\n */\n async authenticate(props: IRequestProps): Promise<IRequestProps> {\n const token = await this.getToken()\n if (token.access_token) {\n props.headers.Authorization = `Bearer ${token.access_token}`\n }\n return props\n }\n\n /**\n * Gets session storage for OAuth code verification\n * @returns saved code verifier\n */\n get code_verifier() {\n return sessionStorage.getItem(OAuthSession.codeVerifierKey)\n }\n\n /**\n * Sets session storage for OAuth code verification\n */\n set code_verifier(value: string | null) {\n if (value === null) {\n // only clear code_verifier if it's `null`\n sessionStorage.removeItem(OAuthSession.codeVerifierKey)\n } else {\n sessionStorage.setItem(OAuthSession.codeVerifierKey, value)\n }\n }\n\n /**\n * URL to return to after login process completes\n * @returns the URL that started the OAuth login process\n */\n get returnUrl() {\n return sessionStorage.getItem(OAuthSession.returnUrlKey)\n }\n\n /**\n * Sets the return URL for successful OAuth login\n */\n set returnUrl(value: string | null) {\n if (!value) {\n sessionStorage.removeItem(OAuthSession.returnUrlKey)\n } else {\n sessionStorage.setItem(OAuthSession.returnUrlKey, value)\n }\n }\n\n /**\n * Clears all Looker SDK OAuth-related session storage\n */\n clearStorage() {\n sessionStorage.removeItem(OAuthSession.codeVerifierKey)\n sessionStorage.removeItem(OAuthSession.returnUrlKey)\n }\n\n async login(_sudoId?: string | number): Promise<any> {\n if (!this.isAuthenticated()) {\n if (this.reentry) {\n // do nothing\n } else if (!this.returnUrl) {\n // OAuth has not been initiated\n const authUrl = await this.createAuthCodeRequestUrl(\n 'cors_api',\n agentPrefix\n )\n const returnTo = window.location.pathname + window.location.search\n this.returnUrl = returnTo\n // Save the current URL so redirected successful OAuth login can restore it\n window.location.href = authUrl\n } else {\n this.reentry = true\n // If return URL is stored, we must be coming back from an OAuth request\n // so release the stored return url at the start of the redemption\n this.returnUrl = null\n if (!this.code_verifier) {\n return Promise.reject(\n new Error('OAuth failed: expected code_verifier to be stored')\n )\n }\n const params = new URLSearchParams(window.location.search)\n const code = params.get('code')\n if (!code) {\n return Promise.reject(\n new Error(\n `OAuth failed: no OAuth code parameter found in ${\n window.location.pathname + window.location.search\n }`\n )\n )\n }\n await this.redeemAuthCode(code)\n }\n return await this.getToken()\n }\n return this.activeToken\n }\n\n private async requestToken(\n body: IAuthCodeGrantTypeParams | IRefreshTokenGrantTypeParams\n ) {\n const config = this.readConfig()\n const url = new URL(config.base_url)\n // replace the entire path of the base_url because this\n // auth endpoint is independent of API version\n url.pathname = '/api/token'\n const token = await this.ok(\n this.transport.request<IAccessToken, IError>(\n 'POST',\n url.toString(),\n undefined,\n body\n )\n )\n\n return this.activeToken.setToken(token)\n }\n\n /*\n Generate an OAuth2 authCode request URL\n */\n async createAuthCodeRequestUrl(\n scope: string,\n state: string\n ): Promise<string> {\n // TODO: remove this comment when we remove hex backwards compatibility\n // in Looker API. For now it must not be 2^n so that Looker correctly\n // treats it as base64 encoded\n this.code_verifier = this.crypto.secureRandom(33)\n const code_challenge = await this.crypto.sha256Hash(this.code_verifier)\n const config = this.readConfig()\n const params: Record<string, string> = {\n client_id: config.client_id,\n code_challenge: code_challenge,\n code_challenge_method: 'S256',\n redirect_uri: config.redirect_uri,\n response_type: 'code',\n scope: scope,\n state: state,\n }\n const url = new URL(config.looker_url)\n url.pathname = '/auth'\n url.search = new URLSearchParams(params).toString()\n return url.toString()\n }\n\n redeemAuthCodeBody(authCode: string, codeVerifier?: string) {\n const verifier = codeVerifier || this.code_verifier || ''\n const config = this.readConfig()\n return {\n client_id: config.client_id,\n code: authCode,\n code_verifier: verifier,\n grant_type: 'authorization_code',\n redirect_uri: config.redirect_uri,\n } as IAuthCodeGrantTypeParams\n }\n\n /**\n * Convert an authCode received from server into an active auth token\n * The app is responsible for obtaining the authCode via interactive user login\n * via /auth front-end endpoint and URL redirect. When the authCode is received\n * by url redirect to an app route, pass the authCode into this function to\n * get an access_token and refresh_token.\n * @param {string} authCode\n * @param {string} codeVerifier\n * @returns {Promise<AuthToken>}\n */\n async redeemAuthCode(authCode: string, codeVerifier?: string) {\n return this.requestToken(this.redeemAuthCodeBody(authCode, codeVerifier))\n }\n\n async getToken() {\n if (!this.isAuthenticated()) {\n if (this.activeToken.refresh_token) {\n const config = this.readConfig()\n await this.requestToken({\n client_id: config.client_id,\n grant_type: 'refresh_token',\n redirect_uri: config.redirect_uri,\n refresh_token: this.activeToken.refresh_token,\n })\n }\n }\n return this.activeToken\n }\n\n isAuthenticated(): boolean {\n return this.activeToken.isActive()\n }\n\n async logout() {\n if (this.activeToken.access_token) {\n await this.ok(\n this.transport.request<IAccessToken, IError>(\n 'DELETE',\n `/api/logout`,\n undefined,\n undefined,\n (init: IRequestProps) => {\n init.headers.Authorization = `Bearer ${this.activeToken.access_token}`\n return init\n }\n )\n )\n\n // logout destroys the access_token AND the refresh_token\n this.activeToken = new AuthToken()\n this.clearStorage()\n return true\n }\n return false\n }\n}\n"],"file":"oauthSession.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@looker/sdk-rtl",
3
- "version": "21.3.1",
3
+ "version": "21.3.2",
4
4
  "description": "Looker SDK Runtime Library",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/esm/index.js",
@@ -51,5 +51,5 @@
51
51
  "SDK",
52
52
  "RTL"
53
53
  ],
54
- "gitHead": "933163198d7e1ab482c8c5aedc43c35eb9923d86"
54
+ "gitHead": "f8867339965baf85c26b3beaee8e4621e3cff3a8"
55
55
  }