Add revoke token when logging out
This commit is contained in:
parent
56152ad57a
commit
8c096dd820
2 changed files with 20 additions and 5 deletions
|
|
@ -161,6 +161,20 @@ class TwitchApi {
|
|||
}
|
||||
}
|
||||
|
||||
/// Revokes the given [token] and returns a bool indicating success.
|
||||
Future<bool> revokeToken({required String token}) async {
|
||||
final url = Uri.parse('https://id.twitch.tv/oauth2/revoke');
|
||||
|
||||
final response = await _client.post(url, body: {'client_id': clientId, 'token': token});
|
||||
if (response.statusCode == 200) {
|
||||
debugPrint('Token revoked!');
|
||||
return true;
|
||||
} else {
|
||||
debugPrint('Failed to revoke token :(');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a [StreamsTwitch] object that contains the top 20 streams and a cursor for further requests.
|
||||
Future<StreamsTwitch> getTopStreams({
|
||||
required Map<String, String> headers,
|
||||
|
|
|
|||
|
|
@ -132,7 +132,8 @@ abstract class _AuthBase with Store {
|
|||
@action
|
||||
Future<void> logout() async {
|
||||
try {
|
||||
// Delete the existing user token.
|
||||
// Revoke the existing user token and delete it.
|
||||
await twitchApi.revokeToken(token: _token!);
|
||||
await _storage.delete(key: 'USER_TOKEN');
|
||||
_token = null;
|
||||
|
||||
|
|
@ -159,12 +160,12 @@ abstract class _AuthBase with Store {
|
|||
_tokenIsValid = await twitchApi.validateToken(token: _token!);
|
||||
}
|
||||
}
|
||||
// Set the login status to logged out.
|
||||
_isLoggedIn = false;
|
||||
|
||||
debugPrint('Successfully logged out');
|
||||
} catch (e) {
|
||||
debugPrint(e.toString());
|
||||
}
|
||||
// Set the login status to logged out.
|
||||
_isLoggedIn = false;
|
||||
|
||||
debugPrint('Successfully logged out');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue