Skip to content

Instantly share code, notes, and snippets.

@e96031413
Created June 10, 2020 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e96031413/3e5df18941c87292a4a0d8f738e14544 to your computer and use it in GitHub Desktop.
Save e96031413/3e5df18941c87292a4a0d8f738e14544 to your computer and use it in GitHub Desktop.
Function to deal with google auth credentials
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