1
1
import 'dart:async' ;
2
2
import 'dart:convert' ;
3
3
4
- import 'package:flutter/foundation.dart' ;
5
4
import 'package:http/http.dart' as http;
6
5
import 'package:s3i_flutter/src/auth/authentication_manager.dart' ;
7
6
import 'package:s3i_flutter/src/auth/client_identity.dart' ;
@@ -24,6 +23,7 @@ class OAuthProxyFlow extends AuthenticationManager {
24
23
OAuthProxyFlow (ClientIdentity clientIdentity,
25
24
{required this .openUrlCallback,
26
25
this .onAuthSuccess,
26
+ this .onNewRefreshToken,
27
27
this .maxRetryPickup = 100 ,
28
28
this .retryWaitingTimeMilliSec = 200 ,
29
29
List <String > scopes = const < String > []})
@@ -63,11 +63,17 @@ class OAuthProxyFlow extends AuthenticationManager {
63
63
/// Is called everytime the [_accessToken] is changed.
64
64
Function (AccessToken )? onAuthSuccess;
65
65
66
- // TODO(poq): enable storage and loading of refresh token
67
- // Is invoked if a new refresh token is available. Could be used to store
68
- // the token in an external database.
69
- // Function(RefreshToken)? onNewRefreshToken;
70
- // void setRefreshToken(RefreshToken token){}
66
+ /// Is invoked if a new refresh token is available. Could be used to store
67
+ /// the token in an external database.
68
+ Function (RefreshToken )? onNewRefreshToken;
69
+
70
+ /// Overwrites the current [_refreshToken] . Could be used to set an older
71
+ /// token from an external database. To receive new [RefreshToken] s see
72
+ /// the [onNewRefreshToken] callback.
73
+ // ignore: avoid_setters_without_getters
74
+ set refreshToken (RefreshToken token) {
75
+ _refreshToken = token;
76
+ }
71
77
72
78
/// Returns a valid [AccessToken] for the [clientIdentity]
73
79
/// which is at least valid for the time specified in [tokenValidBuffer] .
@@ -102,6 +108,7 @@ class OAuthProxyFlow extends AuthenticationManager {
102
108
try {
103
109
_parseAndSetTokenResponse (response.body);
104
110
//_accessToken and _refreshToken should be valid if this is reached
111
+ if (onNewRefreshToken != null ) onNewRefreshToken !(_refreshToken! );
105
112
if (onAuthSuccess != null ) onAuthSuccess !(_accessToken! );
106
113
return _accessToken! ;
107
114
// TODO(poq): test _accessToken.isNotExpired
@@ -146,6 +153,7 @@ class OAuthProxyFlow extends AuthenticationManager {
146
153
_parseAndSetTokenResponse (response.body);
147
154
//_accessToken and _refreshToken should be
148
155
// valid if this code is reached
156
+ if (onNewRefreshToken != null ) onNewRefreshToken !(_refreshToken! );
149
157
if (onAuthSuccess != null ) onAuthSuccess !(_accessToken! );
150
158
return _accessToken! ;
151
159
// TODO(poq): test _accessToken.isNotExpired
@@ -170,9 +178,11 @@ class OAuthProxyFlow extends AuthenticationManager {
170
178
}
171
179
172
180
@override
173
- Future <bool > logout () {
181
+ Future <bool > logout () async {
174
182
// TODO(poq): implement logout
175
- throw UnimplementedError ();
183
+ //throw UnimplementedError();
184
+ _invalidateLoginState ();
185
+ return true ;
176
186
}
177
187
178
188
@override
0 commit comments