Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ npm install @smartcar/auth
### Smartcar CDN

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

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

<!-- Please do not modify or remove this, it is used by the build process -->
[version]: 2.10.0
[version]: 2.11.0
2 changes: 2 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Generates Smartcar OAuth URL.
| [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. |
| [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. |
| [options.flags] | <code>Array.&lt;String&gt;</code> | | An optional space-separated list of feature flags that your application has early access to. |
| [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. |

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

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@smartcar/auth",
"version": "2.10.0",
"version": "2.11.0",
"description": "javascript auth sdk for the smartcar",
"main": "dist/npm/sdk.js",
"license": "MIT",
Expand Down
7 changes: 7 additions & 0 deletions src/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ class Smartcar {
* for more information.
* @param {String[]} [options.flags] - An optional space-separated list of feature
* flags that your application has early access to.
* @param {String} [options.user] - An optional unique identifier for a vehicle owner.
* This identifier is used to aggregate analytics across Connect sessions for each vehicle owner.
*
* @return {String} Connect URL to redirect user to.
*
Expand All @@ -290,6 +292,7 @@ class Smartcar {
* &single_select=true
* &single_select_vin=5YJSA1E14FF101307
* &flags=country:DE color:00819D
* &user=2dad4eaf-9094-4bff-bb0f-ffbbdde8b562
*/
getAuthUrl(options) {
options = options || {};
Expand Down Expand Up @@ -355,6 +358,10 @@ class Smartcar {
link += `&flags=${encodeURIComponent(options.flags.join(' '))}`;
}

if (options.user) {
link += `&user=${encodeURIComponent(options.user)}`;
}

return link;
}

Expand Down
22 changes: 22 additions & 0 deletions test/unit/sdk.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,28 @@ describe('sdk', () => {
expect(link).toBe(expectedLink);
});

test('Includes user when passed to getAuthUrl', () => {
const options = {
clientId: 'clientId',
redirectUri: 'https://smartcar.com',
scope: ['read_vehicle_info', 'read_odometer'],
onComplete: jest.fn(),
mode: 'live',
};

const smartcar = new Smartcar(options);

const link = smartcar.getAuthUrl({
state: originalState,
forcePrompt: true,
user: 'test-user-param',
});

const expectedLink =
`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`;
expect(link).toBe(expectedLink);
});

describe('openDialog and addClickHandler', () => {
const options = {
clientId: 'clientId',
Expand Down