From 171f48fa421829a12ce2b021b93f1d67bcddd315 Mon Sep 17 00:00:00 2001 From: Toby Dickinson Williams Date: Mon, 4 Jan 2021 16:47:23 +0000 Subject: [PATCH] docs: updates readme --- README.md | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 27d54c4..69befb0 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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) => { @@ -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.