access_token 来自 google-sign-in-web

huangapple go评论68阅读模式
英文:

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 &#39;package:firebase_auth/firebase_auth.dart&#39; as auth;
import &#39;package:google_sign_in/google_sign_in.dart&#39;;
...
const List&lt;String&gt; scopes = &lt;String&gt;[
  &#39;profile&#39;,
  &#39;email&#39;,
  &#39;openid&#39;,
];
...
final GoogleSignIn _googleSignIn = GoogleSignIn(scopes: scopes);
GoogleSignInAccount? googleUser = await _googleSignIn.signInSilently();
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
...
debugPrint(&#39;googleAuth.accessToken: ${googleAuth.accessToken}&#39;);
debugPrint(&#39;googleAuth.idToken: ${googleAuth.idToken}&#39;);
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. {&quot;access_token&quot;:&quot;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

huangapple
  • 本文由 发表于 2023年7月18日 02:44:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76707301.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定