22 lines
652 B
Dart
22 lines
652 B
Dart
import 'package:dio/dio.dart' as dio;
|
|
import 'package:injectable/injectable.dart';
|
|
|
|
@lazySingleton
|
|
class GoogleApi {
|
|
const GoogleApi();
|
|
|
|
Future<String?> getGoogleUserId(String googleIdToken) async {
|
|
final v = dio.Dio();
|
|
final response = await v.get(
|
|
'https://www.googleapis.com/oauth2/v1/tokeninfo?id_token=' +
|
|
googleIdToken);
|
|
print(response.data); //contains the token info
|
|
final userId = response.data['user_id'].toString();
|
|
final expiresInSeconds = response.data['expires_in'];
|
|
// final email = response.data['email'];
|
|
if (expiresInSeconds > 0) {
|
|
return userId;
|
|
}
|
|
return null;
|
|
}
|
|
}
|