Created
June 10, 2020 22:08
-
-
Save e96031413/3e5df18941c87292a4a0d8f738e14544 to your computer and use it in GitHub Desktop.
Function to deal with google auth credentials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | |
import 'package:googleapis_auth/auth_io.dart'; | |
class SecureStorage { | |
final storage = FlutterSecureStorage(); | |
//Save Credentials | |
Future saveCredentials(AccessToken token, String refreshToken) async { | |
print(token.expiry.toIso8601String()); | |
await storage.write(key: "type", value: token.type); | |
await storage.write(key: "data", value: token.data); | |
await storage.write(key: "expiry", value: token.expiry.toString()); | |
await storage.write(key: "refreshToken", value: refreshToken); | |
} | |
//Get Saved Credentials | |
Future<Map<String, dynamic>> getCredentials() async { | |
var result = await storage.readAll(); | |
if (result.length == 0) return null; | |
return result; | |
} | |
//Clear Saved Credentials | |
Future clear() { | |
return storage.deleteAll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment