Skip to content

Commit 81ded35

Browse files
authored
feat: add user param for auth URL (#83)
* feat: add user param for auth URL * chore: run prepare release + update doc
1 parent 7342b5f commit 81ded35

File tree

6 files changed

+35
-4
lines changed

6 files changed

+35
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ npm install @smartcar/auth
2424
### Smartcar CDN
2525

2626
```html
27-
<script src="https://javascript-sdk.smartcar.com/2.10.0/sdk.js"></script>
27+
<script src="https://javascript-sdk.smartcar.com/2.11.0/sdk.js"></script>
2828
```
2929

3030
## SDK reference
@@ -178,4 +178,4 @@ https://application-backend.com/page?error=access_denied&error_description=User+
178178
[tag-image]: https://img.shields.io/github/tag/smartcar/javascript-sdk.svg
179179

180180
<!-- Please do not modify or remove this, it is used by the build process -->
181-
[version]: 2.10.0
181+
[version]: 2.11.0

doc/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Generates Smartcar OAuth URL.
7272
| [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. |
7373
| [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. |
7474
| [options.flags] | <code>Array.&lt;String&gt;</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. |
7576

7677
**Example**
7778
```js
@@ -85,6 +86,7 @@ response_type=code
8586
&single_select=true
8687
&single_select_vin=5YJSA1E14FF101307
8788
&flags=country:DE color:00819D
89+
&user=2dad4eaf-9094-4bff-bb0f-ffbbdde8b562
8890
```
8991
<a name="Smartcar+openDialog"></a>
9092

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@smartcar/auth",
3-
"version": "2.10.0",
3+
"version": "2.11.0",
44
"description": "javascript auth sdk for the smartcar",
55
"main": "dist/npm/sdk.js",
66
"license": "MIT",

src/sdk.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ class Smartcar {
276276
* for more information.
277277
* @param {String[]} [options.flags] - An optional space-separated list of feature
278278
* flags that your application has early access to.
279+
* @param {String} [options.user] - An optional unique identifier for a vehicle owner.
280+
* This identifier is used to aggregate analytics across Connect sessions for each vehicle owner.
279281
*
280282
* @return {String} Connect URL to redirect user to.
281283
*
@@ -290,6 +292,7 @@ class Smartcar {
290292
* &single_select=true
291293
* &single_select_vin=5YJSA1E14FF101307
292294
* &flags=country:DE color:00819D
295+
* &user=2dad4eaf-9094-4bff-bb0f-ffbbdde8b562
293296
*/
294297
getAuthUrl(options) {
295298
options = options || {};
@@ -355,6 +358,10 @@ class Smartcar {
355358
link += `&flags=${encodeURIComponent(options.flags.join(' '))}`;
356359
}
357360

361+
if (options.user) {
362+
link += `&user=${encodeURIComponent(options.user)}`;
363+
}
364+
358365
return link;
359366
}
360367

test/unit/sdk.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,28 @@ describe('sdk', () => {
10921092
expect(link).toBe(expectedLink);
10931093
});
10941094

1095+
test('Includes user when passed to getAuthUrl', () => {
1096+
const options = {
1097+
clientId: 'clientId',
1098+
redirectUri: 'https://smartcar.com',
1099+
scope: ['read_vehicle_info', 'read_odometer'],
1100+
onComplete: jest.fn(),
1101+
mode: 'live',
1102+
};
1103+
1104+
const smartcar = new Smartcar(options);
1105+
1106+
const link = smartcar.getAuthUrl({
1107+
state: originalState,
1108+
forcePrompt: true,
1109+
user: 'test-user-param',
1110+
});
1111+
1112+
const expectedLink =
1113+
`https://connect.smartcar.com/oauth/authorize?response_type=code&client_id=clientId&redirect_uri=https%3A%2F%2Fsmartcar.com&approval_prompt=force&scope=read_vehicle_info%20read_odometer&mode=live&state=${getEncodedState(smartcar.instanceId)}&user=test-user-param`;
1114+
expect(link).toBe(expectedLink);
1115+
});
1116+
10951117
describe('openDialog and addClickHandler', () => {
10961118
const options = {
10971119
clientId: 'clientId',

0 commit comments

Comments
 (0)