我已经在我的应用程序中使用 firebase auth 实现了谷歌登录。
我正在尝试使用已登录的 google 帐户实现 GmailAPI,但无法同时找到有关它们的任何信息。
我正在跟进
https://github.com/dart-lang/googleapis/blob/master/generated/googleapis/lib/gmail/v1.dart
并在代码中实现了这一点
final FirebaseAuth _auth = FirebaseAuth.instance;
final GoogleSignIn googleSignIn = GoogleSignIn(
scopes: [
"https://www.googleapis.com/auth/gmail.compose",
"https://www.googleapis.com/auth/gmail.insert",
"https://www.googleapis.com/auth/gmail.labels",
"https://www.googleapis.com/auth/gmail.metadata",
"https://www.googleapis.com/auth/gmail.modify",
"https://www.googleapis.com/auth/gmail.readonly",
"https://www.googleapis.com/auth/gmail.send",
"https://www.googleapis.com/auth/gmail.settings.basic",
"https://www.googleapis.com/auth/gmail.settings.sharing",
]
);
用户在此之后是否需要身份验证或
uid
用这个生成的足以验证用户身份吗?googleAPI 示例在线随处可见,用户已在线进行身份验证,但我找不到
google sign in
的任何内容。 .
最佳答案
我不是 flutter 方面的专家,但基于找到的示例 here您需要以编程方式验证 firebase 的唯一内容是 token_id
和 access_token
像这样:
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
据此,要对 Firebase 进行身份验证,您只需要添加登录范围:
'email', 'profile' and 'openid'
或范围:'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile' and 'openid'
(根据所使用的库,它们通常表示相同)。然后使用生成的访问 token ,您可以使用 firebase 库对 firebase 进行身份验证,而无需重新进行身份验证。如果您需要更多信息,请与我们联系。
编辑:
您必须找到 Google 登录收到的访问 token 并传递 firebase 登录信息。访问 token 应如下所示:
{
"access_token": "ya29.a0Adw1xekVMTQRK0_EAdr1PfiOS97Lnz-VCLTJHw7...",
"expires_in": 3599,
"refresh_token": "1//01iBd1CQsBUl2CgYIARAA...",
"scope": "https://www.googleapis.com/auth/userinfo.email openid",
"token_type": "Bearer",
"id_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjE31ZmY0ZTEwOTkxZDZiMGA..."
}
关于flutter - 带有 Google 登录帐户的 Google API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61522391/