Skip to content

Commit cbe4461

Browse files
author
Patrick FINKELSTEIN
committed
Added promt as a parameter in OAuth
1 parent dca12de commit cbe4461

8 files changed

Lines changed: 18 additions & 41 deletions

File tree

example/lib/examples.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ void example(String secret) async {
8181
bool isAuthOk = false;
8282

8383
final strava = Strava(true,
84-
secret, 'auto');
84+
secret);
85+
final prompt = 'auto';
8586

86-
isAuthOk = await strava.OAuth(clientID, "http://localhost:8080", 'profile:read_all', secret);
87+
isAuthOk = await strava.OAuth(clientID, 'activity:write,profile:read_all', secret, prompt);
8788

8889
if (isAuthOk) {
8990

example/lib/main.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ class StravaFlutterPage extends StatefulWidget {
3636
}
3737

3838
class _StravaFlutterPageState extends State<StravaFlutterPage> {
39-
String clientID = "32212";
40-
final String redirectUrl = "http://localhost:8080";
41-
final String scope = 'profile:write';
4239

4340

4441
@override

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: Describes how to use strava_flutter package
88
# Both the version and the builder number may be overridden in flutter
99
# build by specifying --build-name and --build-number, respectively.
1010
# Read more about versioning at semver.org.
11-
version: 1.0.0+1
11+
version: 1.0.0+2
1212

1313
environment:
1414
sdk: ">=2.0.0-dev.68.0 <3.0.0"

lib/API/Oauth.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ abstract class Auth {
7272

7373
// Get the code from Strava server
7474
Future<void> getStravaCode(
75-
String clientID, String redirectUrl, String scope) async {
75+
String clientID, String scope, String prompt) async {
7676
globals.displayInfo('Entering getStravaCode');
7777
var code = "";
7878
var params = '?' +
@@ -83,7 +83,7 @@ abstract class Auth {
8383
'&response_type=' +
8484
'code' +
8585
'&approval_prompt=' +
86-
'auto' +
86+
prompt +
8787
'&scope=' +
8888
scope;
8989

@@ -124,7 +124,7 @@ abstract class Auth {
124124
/// Do/show the Strava login if the scope has been changed since last storage of the token
125125
/// return true if no problem in authentication has been found
126126
Future<bool> OAuth(
127-
String clientID, String redirectUrl, String scope, String secret) async {
127+
String clientID, String scope, String secret, String promt) async {
128128
print('Welcome to Oauth');
129129
bool isAuthOk = false;
130130
bool isExpired = true;
@@ -146,7 +146,7 @@ abstract class Auth {
146146
if ((tokenStored.scope != scope) || (_token == "null") || isExpired) {
147147
// Ask for a new authorization
148148
globals.displayInfo('Doing a new authorization');
149-
isAuthOk = await newAuthorization(clientID, redirectUrl, secret, scope);
149+
isAuthOk = await newAuthorization(clientID, secret, scope, prompt);
150150
} else {
151151
isAuthOk = true;
152152
}
@@ -156,11 +156,11 @@ abstract class Auth {
156156

157157

158158
Future<bool> newAuthorization(
159-
String clientID, String redirectUrl, String secret, String scope) async {
159+
String clientID, String secret, String scope, String prompt) async {
160160

161161
bool returnValue = false;
162162

163-
await getStravaCode(clientID, redirectUrl, scope);
163+
await getStravaCode(clientID, scope, prompt);
164164

165165
var stravaCode = await onCodeReceived.stream.first;
166166

lib/API/constants.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ final authorizationEndpoint = "https://www.strava.com/oauth/authorize";
88

99
final clientID = '32212';
1010

11+
final String redirectUrl = "http://localhost:8080";
12+
1113

1214

1315

lib/API/strava.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ import 'clubs.dart';
2323
/// prompt: to choose to ask Strava always to authenticate or only when needed (with 'auto')
2424
/// scope: Strava scope check https://developers.strava.com/docs/oauth-updates/
2525
class Strava with Upload, Auth, Clubs {
26-
Strava( this.isInDebug, this.secret, this.prompt);
26+
Strava( this.isInDebug, this.secret);
2727
final bool isInDebug;
2828
final String secret;
29-
final String prompt;
3029

3130

3231

@@ -39,10 +38,6 @@ final statusUnknownError = 2;
3938
final statusHeaderIsEmpty = 3;
4039
final statusNotFound = 4;
4140

42-
final tokenEndpoint = "https://www.strava.com/oauth/token";
43-
final authorizationEndpoint = "https://www.strava.com/oauth/authorize";
44-
45-
4641

4742
/// getRunningRacebyId
4843
///
@@ -387,7 +382,6 @@ final authorizationEndpoint = "https://www.strava.com/oauth/authorize";
387382
default: {
388383
returnStats.fault.statusCode = statusUnknownError;
389384
globals.displayInfo('problem in getStats request, {rep.statusCode}');
390-
// Todo add an error code
391385
}
392386
break;
393387
}

pubspec.lock

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,11 @@ packages:
4141
description: flutter
4242
source: sdk
4343
version: "0.0.0"
44-
flutter_oauth:
45-
dependency: "direct main"
46-
description:
47-
path: "."
48-
ref: HEAD
49-
resolved-ref: "2b5e66e1963efe8b1c337eeba5cce8d0d246552c"
50-
url: "git://github.com/ibrierley/FlutterOAuth.git"
51-
source: git
52-
version: "0.0.1"
5344
flutter_test:
5445
dependency: "direct dev"
5546
description: flutter
5647
source: sdk
5748
version: "0.0.0"
58-
flutter_webview_plugin:
59-
dependency: transitive
60-
description:
61-
name: flutter_webview_plugin
62-
url: "https://pub.dartlang.org"
63-
source: hosted
64-
version: "0.3.0+2"
6549
http:
6650
dependency: "direct main"
6751
description:

pubspec.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: strava_flutter
2-
description: to access Strava v3 API using flutter/Dart
3-
version: 0.0.1
2+
description: Flutter/Dart code to access Strava v3 API
3+
version: 1.0.1+2
44
author: Patrick FINKELSTEIN
55
homepage:
66

@@ -12,10 +12,9 @@ dependencies:
1212
sdk: flutter
1313

1414
http: ^0.12.0+1
15-
flutter_oauth:
16-
git:
17-
url: git://github.com/ibrierley/FlutterOAuth.git
18-
url_launcher: ^5.0.0
15+
# url_launcher: ^5.0.0
16+
url_launcher:
17+
path: vendor/url_launcher
1918
shared_preferences: ^0.5.0
2019
path_provider: ^0.5.0+1
2120

0 commit comments

Comments
 (0)