# Authorization
# Authorize your application
To do that, simply call the asynchronous method FitbitConnector.authorize()
, within your code, as:
FitbitCredentials? fitbitCredentials =
await FitbitConnector.authorize(
clientID: Strings.fitbitClientID,
clientSecret: Strings.fitbitClientSecret,
redirectUri: Strings.fitbitRedirectUri,
callbackUrlScheme: Strings.fitbitCallbackScheme
);
This will open a web view where user will be able to input his Fitbit credentials and login.
After the login, the web view will close and the method will return a FitbitCredentials?
instance that contains the credentials to be used to make requests to the Fitbit Web API via fitbitter
. In particular, fitbitCredentials.userID
contains the Fitbit user id of the user that just authorized fitbitter
, fitbitCredentials.fitbitAccessToken
contains the Fitbit access token, and fitbitCredentials.fitbitRefreshToken
contains the Fitbit refresh token.
WARNING
Since version 2.0.0, fitbitter
no longer stores the credentials automatically. As such, you, as a developer, must manage such crendentials according to your strategy.
# Unauthorize your application
To do that, simply call the asynchronous method FitbitConnector.unauthorize()
, within your code, as:
await FitbitConnector.unauthorize(
clientID: '<OAuth 2.0 Client ID>',
clientSecret: '<Client Secret>',
fitbitCredentials: fitbitCredentials,
);
this will unauthorize the provided FitbitCredentials
.
# Check token validity
To check if your FitbitCredentials
are still valid, simply call the asynchronous method FitbitConnector.isTokenValid()
, within your code, as:
bool valid = await FitbitConnector.isTokenValid(fitbitCredentials: fitbitCredentials);
# Refresh retained credentials
To do that, simply call the asynchronous method FitbitConnector.refreshToken()
, within your code, as:
FitbitCredentials newFitbitCredentials = await FitbitConnector.refreshToken(
clientID: '<OAuth 2.0 Client ID>',
clientSecret: '<Client Secret>',
fitbitCredentials: fitbitCredentials,
);
this will return a new instance of FitbitCredentials
containing the refreshed tokens.