I think I have what you need:
lets take it one step on a time, first you need to build your registration form, that can easily done, and gere a sample:
<form action="https://www.strava.com/oauth/authorize" method="get" id="myform"> <input name="redirect_uri" value="[your final url for the registration]"/> <input name="client_id" value="[your client Id]"/> <input name="response_type" value="code"/> <input name="scope" value="activity:read"/> <input name="approval_prompt" value="force"/> <input type="submit" value="Submit from"/> </form> |
| |
| |
|
|
| |
| |
code here...
when the form submitted - the user will be redirected to strava auth page, I guess this is no need to explain.
but the second part is:
one the user approve the app for his Strava account he will redirected back to the URL you've entered in the redirect_uri in the form.
there you'll have to do something like that:
first you need to extract the code out of the response from strava, this will be in the queryString
thank you need to create an http request to strava with that code and your clientId and client_secret, the request will be something like this: (nodejs)
| request.post({ |
| url: 'https://www.strava.com/api/v3/oauth/token', |
| form: { |
| client_id: '[your client id]', |
| client_secret: '[your client secret]', |
| code: data.code, |
| grant_type: 'authorization_code' |
| } |
| }, function (err, httpResponse, body) { |
| let jsonData = JSON.parse(body); |
| |
|
|
| } |
code here...
now you have a json object with all the data you need:
| access_token: jsonData.access_token,
refresh_token: jsonData.refresh_token,
stravaId: jsonData.athlete.id
|
|
|
now you have completed the registration for the user,
note that the access token is the one you need to use to get the user activities and the refresh token will be use to get new access token once the old one is expired.