@@ -28,7 +28,7 @@ abstract class Auth {
2828 // Save also in globals to get direct access
2929 globals.token.accessToken = token;
3030 globals.token.scope = scope;
31- globals.token.expiresAt = expire;
31+ globals.token.expiresAt = expire;
3232
3333 globals.displayInfo ('token saved!!!' );
3434 }
@@ -44,10 +44,10 @@ abstract class Auth {
4444 localToken.expiresAt = prefs.getInt ('expire' );
4545 localToken.scope = prefs.getString ('scope' );
4646
47- // load the data in globals
48- globals.token.accessToken = localToken.accessToken;
49- globals.token.expiresAt = localToken.expiresAt;
50- globals.token.scope = localToken.scope;
47+ // load the data in globals
48+ globals.token.accessToken = localToken.accessToken;
49+ globals.token.expiresAt = localToken.expiresAt;
50+ globals.token.scope = localToken.scope;
5151 } catch (error) {
5252 globals.displayInfo ('Error getting the key' );
5353 localToken.accessToken = null ;
@@ -58,18 +58,20 @@ abstract class Auth {
5858 if (localToken.expiresAt != null ) {
5959 var dateExpired =
6060 DateTime .fromMillisecondsSinceEpoch (localToken.expiresAt);
61- var _disp = dateExpired.day.toString () + '/' +
62- dateExpired.month.toString () + ' ' +
63- dateExpired.hour.toString () + 'hours' ;
64-
65- globals.displayInfo ('stored token ${localToken .accessToken } expires: $_disp ' );
61+ var _disp = dateExpired.day.toString () +
62+ '/' +
63+ dateExpired.month.toString () +
64+ ' ' +
65+ dateExpired.hour.toString () +
66+ 'hours' ;
67+
68+ globals.displayInfo (
69+ 'stored token ${localToken .accessToken } expires: $_disp ' );
6670 }
6771
6872 return (localToken);
6973 }
7074
71-
72-
7375 // Get the code from Strava server
7476 Future <void > getStravaCode (
7577 String clientID, String scope, String prompt) async {
@@ -117,57 +119,55 @@ abstract class Auth {
117119 });
118120 }
119121
120- /// Do Strava Authentication.
121- ///
122+ /// Do Strava Authentication.
123+ ///
122124 /// Do not do/show the Strava login if a token has been stored previously
123125 /// and is not expired
124126 /// Do/show the Strava login if the scope has been changed since last storage of the token
125127 /// return true if no problem in authentication has been found
126- Future <bool > OAuth (
128+ Future <bool > Oauth (
127129 String clientID, String scope, String secret, String prompt) async {
128130 print ('Welcome to Oauth' );
129131 bool isAuthOk = false ;
130132 bool isExpired = true ;
131133
132-
133134 final Token tokenStored = await getStoredToken ();
134135 final String _token = tokenStored.accessToken;
135136
136- // Check if the token is not expired
137+ // Check if the token is not expired
137138 if (_token != "null" ) {
138- globals.displayInfo ('token has been stored before! ${tokenStored .accessToken }' );
139+ globals.displayInfo (
140+ 'token has been stored before! ${tokenStored .accessToken }' );
139141
140142 isExpired = isTokenExpired (tokenStored);
141143 globals.displayInfo ('isExpired $isExpired ' );
142144 }
143145
144-
145- // Check if the scope has changed
146+ // Check if the scope has changed
146147 if ((tokenStored.scope != scope) || (_token == "null" ) || isExpired) {
147148 // Ask for a new authorization
148149 globals.displayInfo ('Doing a new authorization' );
149- isAuthOk = await newAuthorization (clientID, secret, scope, prompt);
150+ isAuthOk = await newAuthorization (clientID, secret, scope, prompt);
150151 } else {
151152 isAuthOk = true ;
152153 }
153154
154155 return isAuthOk;
155156 }
156157
157-
158- Future <bool > newAuthorization (
159- String clientID, String secret, String scope, String prompt) async {
160-
158+ Future <bool > newAuthorization (
159+ String clientID, String secret, String scope, String prompt) async {
161160 bool returnValue = false ;
162161
163162 await getStravaCode (clientID, scope, prompt);
164163
165- var stravaCode = await onCodeReceived.stream.first;
164+ var stravaCode = await onCodeReceived.stream.first;
166165
167166 if (stravaCode != null ) {
168167 var answer = await getStravaToken (clientID, secret, stravaCode);
169168
170- globals.displayInfo ('answer ${answer .expiresAt } , ${answer .accessToken }' );
169+ globals
170+ .displayInfo ('answer ${answer .expiresAt } , ${answer .accessToken }' );
171171
172172 // Save the token information
173173 if (answer.accessToken != null && answer.expiresAt != null ) {
@@ -180,8 +180,6 @@ Future<bool> newAuthorization(
180180 return returnValue;
181181 }
182182
183-
184-
185183 Future <Token > getStravaToken (
186184 String clientID, String secret, String code) async {
187185 Token _answer = Token ();
@@ -230,14 +228,10 @@ Future<bool> newAuthorization(
230228 DateTime .fromMillisecondsSinceEpoch (token.expiresAt);
231229 return (_expiryDate.isBefore (DateTime .now ()));
232230 }
233-
234231
235232 Future <void > deAuthorize () async {
236- String returnValue;
237-
238- var _token = await getStoredToken ();
239233
240- var _header = globals.createHeader ();
234+ var _header = globals.createHeader ();
241235 if (_header != null ) {
242236 final reqDeAuthorize = "https://www.strava.com/oauth/deauthorize" ;
243237 var rep = await http.post (reqDeAuthorize, headers: _header);
0 commit comments