Authentication

The FitnessSyncer API uses OAuth2 for authentication. This is a standard authentication scheme that is well documented on the web; the sequence diagram below will help you understand the big picture and this documentation will describe what you need to do.

Sequence Diagram of Authenticating with OAuth2

FitnessSyncer supports Proof of Key Code Exchange (PKCE), an extension of OAuth 2.0 which helps protect against interception attacks. You are not required to use this, but are highly encouraged to. You can enable this functionality in our developer console.

Personal Applications can be created in our developer console. For other use-cases, please contact us, provide us with your Redirect URL(s), and we will provide you with the following information:

Note that the Redirect URL is case sensitive and should be SSL-based as our browser policy is to not redirect to non-SSL enabled locations.

Personal applications do not have a configurable Redirect URL. When the flow goes to that hard-coded Redirect URL, simply edit the URL to where you need it to go. You should only need to do this once.

Authenticating

To authenticate a web-application, the basic workflow is as follows:

  1. Redirect the user to FitnessSyncer to authorize your application’s access to their data. See Authorizing for details.
  2. Once approved, FitnessSyncer will redirect the user back to your site with a temporary token.
  3. With the temporary token, you can get the Access Token
  4. After the Access Token Expires, you must Refresh the Access Token.

The sections below will walk you through all of the steps but we have provided fitnesssyncer_oauth_authorization_flow.py for the authorization flow and fitnesssyncer_oauth_refresh_flow.py for the refresh flow as examples to help you get up and running faster. These examples do not support PKCE.

Authorizing

To start the authentication workflow, you will need to redirect the user to https://www.fitnesssyncer.com/api/oauth/authorize with following query string parameters:

Throughout this document, a parameter shown in bold in a table is required, and bold text within a URL is a placeholder for you to substitute.

Query String Parameter NameDescription
response_typeSet to “code”
client_idSet to your Client Id.
redirect_uriSet to your Redirect URL
scopeSpace separated set of scopes. See Scopes
stateSet to any state you wish to get returned on the redirect URL. We strongly recommend using this for CSRF protection, as described in RFC 6749.
code_challengeIf you are using PKCE, this is the BASE64 encoded SHA256 hash of a random verification string. PKCE does not need to be required to use this option, but if PKCE is required, this parameter is required. It is always required for a public client.
code_challenge_methodSet to “S256” when sending a code_challenge. S256 is the only method supported; a public client must send it.

Here is an example URL:

https://www.fitnesssyncer.com/api/oauth/authorize?client_id=YourClientId&response_type=code&scope=source_read+destination_read+source_data_read&redirect_uri=YourRedirectURL&state=InformationForYourService

Scopes

The user will need to grant you access to their account. The scope query string will have each listed separated by a space. In order to allow minimal permissions for the information you need and to allow the user to control the access to their account, FitnessSyncer uses the following scopes:

ScopeDescription
profile_readRead data from the User’s Profile
profile_writeWrite data to the User’s Profile
source_readView Sources in the User’s Account (but not associated data)
source_writeAdd, Modify, and Delete Sources in the User’s Account
source_data_readAccess the data associated with the User’s Sources and FitnessSyncer Notebook Items, including associated Goals. This is an alias for: source_data_activity_read source_data_allergy_read source_data_blood_panel_read source_data_blood_pressure_read source_data_cholesterol_read source_data_condition_read source_data_cycle_tracking_read source_data_ecg_read source_data_glucose_read source_data_medication_read source_data_nutrition_read source_data_oxygen_read source_data_sleep_read source_data_temperature_read source_data_weight_read
source_data_activity_readAccess the Activity data associated with the User’s Sources and FitnessSyncer Notebook Items, including associated Goals.
source_data_allergy_readAccess the Allergy data associated with the User’s Sources and FitnessSyncer Notebook Items, including associated Goals.
source_data_blood_pressure_readAccess the Blood Pressure data associated with the User’s Sources and FitnessSyncer Notebook Items, including associated Goals.
source_data_blood_panel_readAccess the Blood Panel data associated with the User’s Sources and FitnessSyncer Notebook Items, including associated Goals.
source_data_condition_readAccess the Condition data associated with the User’s Sources and FitnessSyncer Notebook Items, including associated Goals.
source_data_cycle_tracking_readAccess the Cycle Tracking data associated with the User’s Sources and FitnessSyncer Notebook Items, including associated Goals.
source_data_ecg_readAccess the ECG data associated with the User’s Sources and FitnessSyncer Notebook Items, including associated Goals.
source_data_glucose_readAccess the Glucose data associated with the User’s Sources and FitnessSyncer Notebook Items, including associated Goals.
source_data_medication_readAccess the Medication data associated with the User’s Sources and FitnessSyncer Notebook Items, including associated Goals.
source_data_nutrition_readAccess the Nutrition data associated with the User’s Sources and FitnessSyncer Notebook Items, including associated Goals.
source_data_oxygen_readAccess the Oxygen data associated with the User’s Sources and FitnessSyncer Notebook Items, including associated Goals.
source_data_sleep_readAccess the Sleep data associated with the User’s Sources and FitnessSyncer Notebook Items, including associated Goals.
source_data_temperature_readAccess the Temperature data associated with the User’s Sources and FitnessSyncer Notebook Items, including associated Goals.
source_data_weight_readAccess the Body Composition data associated with the User’s Sources and FitnessSyncer Notebook Items, including associated Goals.
annotation_readView the notes the User has written on their charts.
annotation_writeAdd, Modify, and Delete the notes the User has written on their charts.
destination_readView Destinations in the User’s Account (but not associated data)
destination_writeAdd, Modify, and Delete Destinations in the User’s Account
notebook_writeAdd, Modify, and Delete FitnessSyncer Notebook Items in the User’s Account. This is an alias for: notebook_activity_write notebook_allergy_write notebook_blood_panel_write notebook_blood_pressure_write notebook_cholesterol_write notebook_condition_write notebook_cycle_tracking_write notebook_glucose_write notebook_medication_write notebook_nutrition_write notebook_oxygen_write notebook_sleep_write notebook_temperature_write notebook_weight_write
notebook_activity_writeAdd, Modify, and Delete FitnessSyncer Notebook Activity Items in the User’s Account.
notebook_allergy_writeAdd, Modify, and Delete FitnessSyncer Notebook Allergy Items in the User’s Account.
notebook_blood_pressure_writeAdd, Modify, and Delete FitnessSyncer Notebook Blood Pressure Items in the User’s Account.
notebook_blood_panel_writeAdd, Modify, and Delete FitnessSyncer Notebook Blood Panel Items in the User’s Account.
notebook_condition_writeAdd, Modify, and Delete FitnessSyncer Notebook Condition Items in the User’s Account.
notebook_cycle_tracking_writeAdd, Modify, and Delete FitnessSyncer Notebook Cycle Tracking Items in the User’s Account.
notebook_glucose_writeAdd, Modify, and Delete FitnessSyncer Notebook Glucose Items in the User’s Account.
notebook_medication_writeAdd, Modify, and Delete FitnessSyncer Notebook Medication Items in the User’s Account.
notebook_nutrition_writeAdd, Modify, and Delete FitnessSyncer Notebook Nutrition Items in the User’s Account.
notebook_oxygen_writeAdd, Modify, and Delete FitnessSyncer Notebook Oxygen Items in the User’s Account.
notebook_sleep_writeAdd, Modify, and Delete FitnessSyncer Notebook Sleep Items in the User’s Account.
notebook_temperature_writeAdd, Modify, and Delete FitnessSyncer Notebook Temperature Items in the User’s Account.
notebook_weight_writeAdd, Modify, and Delete FitnessSyncer Notebook Body Composition Items in the User’s Account.
updatable_providersFor integrations that are the source of branded data, allows the integration to Add, Modify, and Delete Branded Items in the User’s Account
leaderboard_participateParticipate in Leaderboards via opt-in, viewing the data, viewing and updating personal preferences in the User’s Account.
leaderboard_adminAdd, Modify, Delete, and Administer Leaderboards in the User’s Account.
researcher_readFor FitnessSyncer for Researchers, list the participants who have consented to the study and their credentials.

Accessing the token

On authorizing success, this will redirect back to your site with the following query string parameters:

Redirect Query String Parameter NameDescription
codeA temporary Access Code. The code will be set to “error” if there was an error granting the permission.
stateThe same value you passed in the above state, if any. Compare it against the value you generated for this user’s session before acting on the code, and discard the response if it does not match — see the note on the state parameter above.
issThe issuer identifier of this authorization server, currently “https://www.fitnesssyncer.com”.

If you are paying for the users of your application, this is where the subscription is activated unless the user has another active subscription on their account. The user can opt-out by removing the token.

Once you have the code, you can access the code by making a POST request to https://api.fitnesssyncer.com/api/oauth/access_token. The body of this request should contain as application/x-www-form-urlencoded:

POSThttps://api.fitnesssyncer.com/api/oauth/access_token
Request bodyapplication/x-www-form-urlencoded
Response 200JSON
POST Parameter NameDescription
grant_typeSet to “authorization_code”
codeThe temporary code received.
client_idSet to your Client Id.
client_secretSet to your Client Secret. A public client has none and must omit it.
redirect_uriSet to your Redirect URL
code_verifierIf you are using PKCE, this is the raw, random verification string that was originally provided as a BASE64 encoded SHA256 hash. PKCE does not need to be required to use this option, but if PKCE is required, this parameter is required.

Upon success, you will receive a 200-response code with a JSON Body as follows:

KeyDescription
expires_inThe lifetime of the access token, in seconds from when this response was generated.
access_tokenToken to access the data.
refresh_tokenA token to get a new access_token when the token expires.
scopeThe space separate scopes that were provided to the application.
user_idAn opaque, stable identifier for the account this token was issued for. This is only useful for tagging your own diagnostics or a support request so an issue can be traced back to one account.

To access any resources from this point forward, simply include the Authorization header with the value “Bearer ” followed by the access_token above. For example, if the access_token was “asdfasdf”, the Authorization header would be set to “Bearer asdfasdf”.

Refreshing the token

The access token will expire periodically. You may either track the expiration yourself, or detect it when a 401 status code is returned, at which point you will need to reauthenticate. You can renew the token by making a POST request to: https://api.fitnesssyncer.com/api/oauth/access_token. The body of this request should contain the following as application/x-www-form-urlencoded:

POSThttps://api.fitnesssyncer.com/api/oauth/access_token
Request bodyapplication/x-www-form-urlencoded
Response 200JSON
POST Parameter NameDescription
grant_typeSet to “refresh_token”
refresh_tokenSet to the refresh_token as received above.
client_idSet to your Client Id.
client_secretSet to your Client Secret. A public client has none and must omit it.
redirect_uriSet to your Redirect URL as included in the original request

Upon success, you will receive a 200-response code with a JSON Body as follows:

KeyDescription
expires_inThe lifetime of the access token, in seconds from when this response was generated.
access_tokenToken to access the data.
refresh_tokenA token to get a new access_token when the token expires.
scopeThe space-separated scopes that were provided to the application.
user_idAn opaque, stable identifier for the account this token was issued for. This is only useful for tagging your own diagnostics or a support request so an issue can be traced back to one account.

Revoking the token

You may revoke a token at any time by making a POST request to: https://api.fitnesssyncer.com/api/oauth/revoke_token.

We support both self-logout by simply using the Authorization header as defined above or we support the RFC 7009 method.

If you are paying for the users of your application, this request will also remove the payment details from their account and it will return to a free account afterwards.

POSThttps://api.fitnesssyncer.com/api/oauth/revoke_token
Request bodyapplication/x-www-form-urlencoded

Request Parameters

For self-logout, there are no parameters.

For RFC 7009, the body of the request should contain an application/x-www-form-urlencoded encoded body:

POST Parameter NameDescription
tokenToken to remove
token_type_hintOptional: access_token or refresh_token
client_idSet to your Client Id (or use BASIC auth)
client_secretSet to your Client Secret (or use BASIC auth). A public client omits it.

Response

On success, a 200 will be returned with a JSON object indicating the successful status.

This is also how you deregister a user. When someone stops using your application such as they delete their account with you, cancel, or disconnect FitnessSyncer from your side, revoke the token at that point rather than leaving it live.

Public Clients

An application that runs on the user’s own device, such as a phone app, a desktop app or a command-line tool, cannot keep a Client Secret: anything built into it can be extracted. Create it as a public client instead by checking Public client when you create the application in the developer console. A public client has a Client ID and no Client Secret, and the following rules apply:

A public client’s Redirect URL can take three forms, following RFC 8252 (OAuth 2.0 for Native Apps):

As with any application, contact us with the Redirect URLs you need.

Creating users

If your application can create new users, you can do so using this API.

To do so, make a POST request to https://api.fitnesssyncer.com/api/oauth/access_token. The body of this request should contain the following as application/x-www-form-urlencoded:

POSThttps://api.fitnesssyncer.com/api/oauth/access_token
Request bodyapplication/x-www-form-urlencoded
Response 200JSON
POST Parameter NameDescription
grant_typeSet to “password”
createSet to “true”
usernameThe new user’s username. This must be in the form of an e-mail address.
passwordThe new user’s password
client_idSet to your Client Id.
client_secretSet to your Client Secret.
redirect_uriSet to your Redirect URL

Upon success, you will receive a 200-response code with a JSON Body as follows:

KeyDescription
expires_inThe lifetime of the access token, in seconds from when this response was generated.
access_tokenToken to access the data.
refresh_tokenA token to get a new access_token when the token expires.

To access any resources from this point forward, simply include the Authorization header with the value “Bearer ” followed by the access_token above. For example, if the access_token was “asdfasdf”, the Authorization header would be set to “Bearer asdfasdf”.

Other Considerations

It is important to realize that a user can also revoke an access token. For example, under the Permissions tab of My Account, they may choose to revoke your permissions entirely. When this occurs, accessing and refreshing the token will fail with a 403 and you will need to reauthenticate from the beginning.

Changing a password also ends every authorization the user has granted. When a user changes their FitnessSyncer password, every access token, refresh token and API key issued for their account is invalidated, for your application and for every other one. Requests and refreshes made with them then fail with a 401 and an error code of “InvalidToken”, and the user has to authorize your application again.

A user may also delete their FitnessSyncer account outright, either themselves or by leaving it dormant long enough that we delete it for them. Once that happens the token you hold no longer resolves to a user, and requests made with it fail with a 401 and an error code of “InvalidToken”.