# Authorization

# Authorize your application

To do that, simply call the asynchronous method FitbitConnector.authorize(), within your code, as:

    String? userId = await FitbitConnector.authorize(
        context: context,
        clientID: '<OAuth 2.0 Client ID>',
        clientSecret: '<Client Secret>',
        redirectUri: '<Redirect Uri used during the registration, e.g., example://fitbit/auth>',
        callbackUrlScheme: '<Callback Uri scheme, e.g., example>');

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 String? containing the userId.

WARNING

Don't worry about storing the auth tokens provided by the Fitbit API, Fitbitter will do that for you leveraging the SharedPreferences abd GetIt packages. If you want, you can access to the token values using

GetIt.instance<SharedPreferences>().getString("fitbitAccessToken")
GetIt.instance<SharedPreferences>().getString("fitbitRefreshToken")

TIP

Remember to retain userId: it will be used to fetch data.

# 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>'
    );

WARNING

Don't worry about removing the auth tokens provided by the Fitbit API, Fitbitter will do that for you leveraging the SharedPreferences abd GetIt packages. The token values wil no longer be accessible using

GetIt.instance<SharedPreferences>().getString("fitbitAccessToken")
GetIt.instance<SharedPreferences>().getString("fitbitRefreshToken")

# Check token validity

To check if the token, retained by Fitbitter, are still valid, simply call the asynchronous method FitbitConnector.isTokenValid(), within your code, as:

    bool valid = await FitbitConnector.isTokenValid();

# Refresh retained token

To do that, simply call the asynchronous method FitbitConnector.refreshToken(), within your code, as:

    await FitbitConnector.refreshToken(
            clientID: '<OAuth 2.0 Client ID>',
            clientSecret: '<Client Secret>'
        );