Skip to content

Commit

Permalink
docs: updates readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyDickinson committed Jan 4, 2021
1 parent 918fc7b commit 171f48f
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Using npm:
npm install strava-oauth2
```

## API Reference
## API Examples

### Class Instantiation
`strava-oauth2` exposes 2 classes which can be used to interact with the Strava authentication services.
Expand All @@ -29,7 +29,8 @@ const client = new Client(config);
```

### Client Authentication
The below uses express to redirect a connecting client to the Strava authentication page before parsing the resultant code and obtaining a `Token`.
#### By URL
The below uses Express to redirect a connecting client to the Strava authentication page before parsing the resultant code and obtaining a `Token`.

```js
app.get('/auth', (req, res) => {
Expand All @@ -49,6 +50,26 @@ app.get('/home', (req, res) => {
});
```

#### By Request Parameters
You can also parse the request query string parameters yourself and pass them to `strava-oauth2`, via `Client.getTokenFromObject(params)`. The example below generates a token via the event passed by an [AWS API Gateway Lambda Proxy integration](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html).

```js
exports.handler = async (event) => {
const params = event.queryStringParameters;
console.info('Here are our params', params);
const token = await client.getTokenFromObject(params);
}
```

Console output:
```
Here are our params {
state: '',
code: 'abcdef1234567890',
scope: 'read,activity:read_all'
}
```

### Request Signing
To interact with the Strava API, you must sign your request with the access token. The `Token` class can provide an axios client which signs all requests made with it using your access token.

Expand Down

0 comments on commit 171f48f

Please sign in to comment.