https://github.com/bendrucker/scriptable-strava-oauth
Scriptable (iOS) script for obtaining a Strava API token
https://github.com/bendrucker/scriptable-strava-oauth
ios scriptable strava
Last synced: 12 months ago
JSON representation
Scriptable (iOS) script for obtaining a Strava API token
- Host: GitHub
- URL: https://github.com/bendrucker/scriptable-strava-oauth
- Owner: bendrucker
- License: mit
- Created: 2021-08-23T03:08:18.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-08-23T03:32:40.000Z (over 4 years ago)
- Last Synced: 2025-03-14T22:03:49.987Z (12 months ago)
- Topics: ios, scriptable, strava
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Strava OAuth for [Scriptable](https://scriptable.app)
> Scriptable (iOS) script for obtaining a Strava API token
## Setup
1. [Register a new Strava API application](https://developers.strava.com/docs/getting-started/#account). Set the _Authorization Callback Domain_ to `open.scriptable.app`.
2. Add the [script](strava-oauth.js) to Scriptable.
3. Run the script and input your client ID and secret.
4. Authenticate in the presented Safari window and authorize your API application to access your account data.
Upon successful authorization, Strava will redirect to a Scriptable URL, re-triggering the script and passing an authorization code in a query parameter. The script will use your client secret and the code to obtain a token object, which will be saved as JSON to the keychain (key: `strava`).
## Usage
From other scripts, you can load the `strava` authentication data from the keychain and include it in requests to the Strava API:
```js
const token = JSON.parse(Keychain.get('strava'))
const req = new Request('https://www.strava.com/api/v3/athlete/activities')
req.headers.authorization = `Bearer ${token.access_token}`
const activities = await req.loadJSON()
// ...
```
Note that access tokens expire frequently so you will likely want to use the refresh token to obtain a new access token first.
## License
[MIT](LICENSE)