Fix token login
This commit is contained in:
parent
45d3ce2e2f
commit
9997313ce7
2 changed files with 6 additions and 21 deletions
|
|
@ -161,20 +161,6 @@ 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,
|
||||
|
|
|
|||
|
|
@ -112,12 +112,14 @@ abstract class _AuthBase with Store {
|
|||
final url = Uri.parse(result.replaceFirst('#', '?'));
|
||||
_token = url.queryParameters['access_token'];
|
||||
} else {
|
||||
// Validate the custom token.
|
||||
_tokenIsValid = await twitchApi.validateToken(token: customToken);
|
||||
if (!_tokenIsValid) return;
|
||||
|
||||
// Replace the current default token with the new custom token.
|
||||
_token = customToken;
|
||||
}
|
||||
|
||||
_tokenIsValid = await twitchApi.validateToken(token: _token!);
|
||||
if (!_tokenIsValid) return;
|
||||
|
||||
// Store the user token.
|
||||
await _storage.write(key: _userTokenKey, value: customToken ?? _token);
|
||||
|
||||
|
|
@ -135,8 +137,7 @@ abstract class _AuthBase with Store {
|
|||
@action
|
||||
Future<void> logout() async {
|
||||
try {
|
||||
// Revoke the existing user token and delete it.
|
||||
await twitchApi.revokeToken(token: _token!);
|
||||
// Delete the existing user token.
|
||||
await _storage.delete(key: _userTokenKey);
|
||||
_token = null;
|
||||
|
||||
|
|
@ -151,7 +152,6 @@ abstract class _AuthBase with Store {
|
|||
if (_token == null) {
|
||||
_token = await twitchApi.getDefaultToken();
|
||||
await _storage.write(key: _defaultTokenKey, value: _token);
|
||||
_tokenIsValid = await twitchApi.validateToken(token: _token!);
|
||||
} else {
|
||||
// Validate the stored token.
|
||||
_tokenIsValid = await twitchApi.validateToken(token: _token!);
|
||||
|
|
@ -160,7 +160,6 @@ abstract class _AuthBase with Store {
|
|||
if (!_tokenIsValid) {
|
||||
_token = await twitchApi.getDefaultToken();
|
||||
await _storage.write(key: _defaultTokenKey, value: _token);
|
||||
_tokenIsValid = await twitchApi.validateToken(token: _token!);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue