@smartcar/auth 2.10.0 → 2.12.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 +2 -2
- package/dist/npm/sdk.js +27 -18
- package/doc/README.md +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ npm install @smartcar/auth
|
|
|
24
24
|
### Smartcar CDN
|
|
25
25
|
|
|
26
26
|
```html
|
|
27
|
-
<script src="https://javascript-sdk.smartcar.com/2.
|
|
27
|
+
<script src="https://javascript-sdk.smartcar.com/2.12.0/sdk.js"></script>
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
## SDK reference
|
|
@@ -178,4 +178,4 @@ https://application-backend.com/page?error=access_denied&error_description=User+
|
|
|
178
178
|
[tag-image]: https://img.shields.io/github/tag/smartcar/javascript-sdk.svg
|
|
179
179
|
|
|
180
180
|
<!-- Please do not modify or remove this, it is used by the build process -->
|
|
181
|
-
[version]: 2.
|
|
181
|
+
[version]: 2.12.0
|
package/dist/npm/sdk.js
CHANGED
|
@@ -137,7 +137,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
137
137
|
|
|
138
138
|
this.messageHandler = function (event) {
|
|
139
139
|
// bail if message from unexpected source
|
|
140
|
-
if (!_this.redirectUri.startsWith(event.origin)) {
|
|
140
|
+
if (_this.redirectUri && !_this.redirectUri.startsWith(event.origin)) {
|
|
141
141
|
return;
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -264,6 +264,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
264
264
|
* for more information.
|
|
265
265
|
* @param {String[]} [options.flags] - An optional space-separated list of feature
|
|
266
266
|
* flags that your application has early access to.
|
|
267
|
+
* @param {String} [options.user] - An optional unique identifier for a vehicle owner.
|
|
268
|
+
* This identifier is used to aggregate analytics across Connect sessions for each vehicle owner.
|
|
267
269
|
*
|
|
268
270
|
* @return {String} Connect URL to redirect user to.
|
|
269
271
|
*
|
|
@@ -278,6 +280,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
278
280
|
* &single_select=true
|
|
279
281
|
* &single_select_vin=5YJSA1E14FF101307
|
|
280
282
|
* &flags=country:DE color:00819D
|
|
283
|
+
* &user=2dad4eaf-9094-4bff-bb0f-ffbbdde8b562
|
|
281
284
|
*/
|
|
282
285
|
function getAuthUrl(options) {
|
|
283
286
|
options = options || {};
|
|
@@ -285,11 +288,15 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
285
288
|
link += 'https://connect.smartcar.com/oauth/authorize';
|
|
286
289
|
link += "?response_type=".concat(this.responseType);
|
|
287
290
|
link += "&client_id=".concat(this.clientId);
|
|
288
|
-
|
|
291
|
+
|
|
292
|
+
if (this.redirectUri) {
|
|
293
|
+
link += "&redirect_uri=".concat(encodeURIComponent(this.redirectUri));
|
|
294
|
+
} // map forcePrompt to approvalPrompt, two options: 'force' and 'auto'
|
|
295
|
+
|
|
289
296
|
|
|
290
297
|
var forcePrompt = options.forcePrompt === true;
|
|
291
|
-
link += "&approval_prompt=".concat(forcePrompt ? 'force' : 'auto'); // If scope is not specified, Smartcar will default to requesting
|
|
292
|
-
//
|
|
298
|
+
link += "&approval_prompt=".concat(forcePrompt ? 'force' : 'auto'); // If scope is not specified, Smartcar will default to requesting the application's vehicle
|
|
299
|
+
// access configuration if available or the default set of permissions
|
|
293
300
|
|
|
294
301
|
if (this.scope) {
|
|
295
302
|
link += "&scope=".concat(encodeURIComponent(this.scope.join(' ')));
|
|
@@ -350,6 +357,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
350
357
|
link += "&flags=".concat(encodeURIComponent(options.flags.join(' ')));
|
|
351
358
|
}
|
|
352
359
|
|
|
360
|
+
if (options.user) {
|
|
361
|
+
link += "&user=".concat(encodeURIComponent(options.user));
|
|
362
|
+
}
|
|
363
|
+
|
|
353
364
|
return link;
|
|
354
365
|
}
|
|
355
366
|
/**
|
|
@@ -515,22 +526,20 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
515
526
|
throw new TypeError('A client ID option must be provided');
|
|
516
527
|
}
|
|
517
528
|
|
|
518
|
-
if (
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
if (!options.onComplete || options.onComplete.length < 2) {
|
|
526
|
-
throw new Error("When using Smartcar's CDN redirect an onComplete function with at" + ' least 2 parameters (error & code) is required to handle' + ' completion of Connect');
|
|
527
|
-
}
|
|
529
|
+
if (options.redirectUri) {
|
|
530
|
+
if (options.redirectUri.startsWith('https://javascript-sdk.smartcar.com')) {
|
|
531
|
+
// require onComplete method with at least two parameters (error & code)
|
|
532
|
+
// when hosting on Smartcar CDN
|
|
533
|
+
if (!options.onComplete || options.onComplete.length < 2) {
|
|
534
|
+
throw new Error("When using Smartcar's CDN redirect an onComplete function with at" + ' least 2 parameters (error & code) is required to handle' + ' completion of Connect');
|
|
535
|
+
}
|
|
528
536
|
|
|
529
|
-
|
|
537
|
+
var usesOldUriScheme = /redirect-[0-9]+\.[0-9]+\.[0-9]+\?/.test(options.redirectUri);
|
|
530
538
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
539
|
+
if (usesOldUriScheme) {
|
|
540
|
+
// eslint-disable-next-line no-console
|
|
541
|
+
console.warn("\nThe Smartcar redirect URI you're using is outdated! To update it, please see:\nhttps://github.com/smartcar/javascript-sdk#1-register-a-javascript-sdk-redirect-uri\n");
|
|
542
|
+
}
|
|
534
543
|
}
|
|
535
544
|
}
|
|
536
545
|
}
|
package/doc/README.md
CHANGED
|
@@ -72,6 +72,7 @@ Generates Smartcar OAuth URL.
|
|
|
72
72
|
| [options.vehicleInfo.make] | <code>String</code> | | `vehicleInfo` is an object with an optional property `make`, which allows users to bypass the car brand selection screen. For a complete list of supported brands, please see our [API Reference](https://smartcar.com/docs/api#authorization) documentation. |
|
|
73
73
|
| [options.singleSelect] | <code>Boolean</code> \| <code>Object</code> | | An optional value that sets the behavior of the grant dialog displayed to the user. If set to `true`, `single_select` limits the user to selecting only one vehicle. If `single_select` is passed in as an object with the property `vin`, Smartcar will only authorize the vehicle with the specified VIN. See the [API reference](https://smartcar.com/docs/api/#connect-match) for more information. |
|
|
74
74
|
| [options.flags] | <code>Array.<String></code> | | An optional space-separated list of feature flags that your application has early access to. |
|
|
75
|
+
| [options.user] | <code>String</code> | | An optional unique identifier for a vehicle owner. This identifier is used to aggregate analytics across Connect sessions for each vehicle owner. |
|
|
75
76
|
|
|
76
77
|
**Example**
|
|
77
78
|
```js
|
|
@@ -85,6 +86,7 @@ response_type=code
|
|
|
85
86
|
&single_select=true
|
|
86
87
|
&single_select_vin=5YJSA1E14FF101307
|
|
87
88
|
&flags=country:DE color:00819D
|
|
89
|
+
&user=2dad4eaf-9094-4bff-bb0f-ffbbdde8b562
|
|
88
90
|
```
|
|
89
91
|
<a name="Smartcar+openDialog"></a>
|
|
90
92
|
|