Skip to content

Commit

Permalink
Merge pull request #59 from smartcar/feature-flag
Browse files Browse the repository at this point in the history
feat: add feature flag parameter to getAuthUrl
  • Loading branch information
allisonc07 authored Sep 16, 2020
2 parents 18c7c8b + f23dbd7 commit 142cdbd
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
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.7.1/sdk.js"></script>
<script src="https://javascript-sdk.smartcar.com/2.8.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.7.1
[version]: 2.8.0
3 changes: 3 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Generates Smartcar OAuth URL.
| [options.forcePrompt] | <code>Boolean</code> | <code>false</code> | force permission approval screen to show on every authentication, even if the user has previously consented to the exact scope of permission |
| [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. |

**Example**
```js
Expand All @@ -78,6 +79,8 @@ response_type=code
&state=0facda3319
&make=TESLA
&single_select=true
&single_select_vin=5YJSA1E14FF101307
&flags=country:DE color:00819D
```
<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.7.1",
"version": "2.8.0",
"description": "javascript auth sdk for the smartcar",
"main": "dist/npm/sdk.js",
"license": "MIT",
Expand Down
8 changes: 8 additions & 0 deletions src/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ class Smartcar {
* the vehicle with the specified VIN. See the
* [API reference](https://smartcar.com/docs/api/#connect-match)
* for more information.
* @param {String[]} [options.flags] - An optional space-separated list of feature
* flags that your application has early access to.
*
* @return {String} Connect URL to redirect user to.
*
Expand All @@ -260,6 +262,8 @@ class Smartcar {
* &state=0facda3319
* &make=TESLA
* &single_select=true
* &single_select_vin=5YJSA1E14FF101307
* &flags=country:DE color:00819D
*/
getAuthUrl(options) {
options = options || {};
Expand Down Expand Up @@ -321,6 +325,10 @@ class Smartcar {
}
}

if (options.flags) {
link += `&flags=${encodeURIComponent(options.flags.join(' '))}`;
}

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 @@ -957,6 +957,28 @@ describe('sdk', () => {
});
});

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

const smartcar = new Smartcar(options);

const link = smartcar.getAuthUrl({
state: originalState,
forcePrompt: true,
flags: ['country:DE', 'flag:suboption'],
});

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)}&flags=country%3ADE%20flag%3Asuboption`;
expect(link).toBe(expectedLink);
});

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

0 comments on commit 142cdbd

Please sign in to comment.