英文:
access_token from google-sign-in-web
问题
由于google-sign-in-web现在将身份验证与授权分开,您如何访问所需的用于firebase_auth的access_token。
它不再通过GoogleSignInAuthentication对象提供。
import 'package:firebase_auth/firebase_auth.dart' as auth;
import 'package:google_sign_in/google_sign_in.dart';
...
const List<String> scopes = <String>[
'profile',
'email',
'openid',
];
...
final GoogleSignIn _googleSignIn = GoogleSignIn(scopes: scopes);
GoogleSignInAccount? googleUser = await _googleSignIn.signInSilently();
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
...
debugPrint('googleAuth.accessToken: ${googleAuth.accessToken}');
debugPrint('googleAuth.idToken: ${googleAuth.idToken}');
final auth.AuthCredential credential = auth.GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final auth.UserCredential userCredential = await _auth.signInWithCredential(credential);
它实际上显示在浏览器控制台日志中,但我不知道如何从Dart代码中访问它:
英文:
Since google-sign-in-web now separates Authentication from Authorization, how can I access the access_token that is required for firebase_auth.
It is no longer available through the GoogleSignInAuthentication object.
import 'package:firebase_auth/firebase_auth.dart' as auth;
import 'package:google_sign_in/google_sign_in.dart';
...
const List<String> scopes = <String>[
'profile',
'email',
'openid',
];
...
final GoogleSignIn _googleSignIn = GoogleSignIn(scopes: scopes);
GoogleSignInAccount? googleUser = await _googleSignIn.signInSilently();
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
...
debugPrint('googleAuth.accessToken: ${googleAuth.accessToken}');
debugPrint('googleAuth.idToken: ${googleAuth.idToken}');
final auth.AuthCredential credential = auth.GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final auth.UserCredential userCredential = await _auth.signInWithCredential(credential);
It actually shows up in the browser console logs, but I don't see how to access it from the dart code:
[GSI_LOGGER-TOKEN_CLIENT]: Handling response. {"access_token":"ya29.a0AbVbY6MRHT
答案1
得分: 0
access_token 在通过 Flutter 进行的 Web 实现中不是必需的:
https://firebase.google.com/docs/auth/flutter/federated-auth#web
英文:
access_token is not needed for the web implementation through flutter:
https://firebase.google.com/docs/auth/flutter/federated-auth#web
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论