Skip to content

Commit

Permalink
feat: enhance Fitbit credential handling to include permission scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimozkn committed Feb 25, 2025
1 parent a8da0d2 commit e070000
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions app/lib/util/fitbit_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class FitbitHandler {

static Future<fitbitter.FitbitCredentials?> _obtainCredentials(
Study study,
List<FitbitQuestionType> types,
) async {
final fitbitCreds = study.fitbitCredentials?.fitbitCredentials;

Expand All @@ -123,12 +124,28 @@ class FitbitHandler {
if (validCredentials != null) return validCredentials;
}
try {
final scopes = <fitbitter.FitbitAuthScope>[];

for (final type in types) {
switch (type) {
case FitbitQuestionType.steps:
scopes.add(fitbitter.FitbitAuthScope.ACTIVITY);
break;
case FitbitQuestionType.heartrate:
scopes.add(fitbitter.FitbitAuthScope.HEART_RATE);
break;
case FitbitQuestionType.sleep:
scopes.add(fitbitter.FitbitAuthScope.SLEEP);
break;
}
}

final newCredentials = await fitbitter.FitbitConnector.authorize(
clientID: fitbitCreds.clientId,
clientSecret: fitbitCreds.clientSecret,
redirectUri: fitbitRedirectUrl,
callbackUrlScheme: fitbitCallbackScheme,
);
clientID: fitbitCreds.clientId,
clientSecret: fitbitCreds.clientSecret,
redirectUri: fitbitRedirectUrl,
callbackUrlScheme: fitbitCallbackScheme,
scopeList: scopes);

if (newCredentials != null) {
await _storeCredentials(newCredentials, study.id);
Expand Down Expand Up @@ -418,7 +435,7 @@ class FitbitHandler {
String taskId,
StudySubject subject,
) async {
final credentials = await _obtainCredentials(study);
final credentials = await _obtainCredentials(study, question.types);

if (credentials == null) {
throw Exception(
Expand Down

0 comments on commit e070000

Please sign in to comment.