cod*_*kls 7 dart firebase-authentication google-signin flutter
我已经在我的应用程序中使用 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",
]
);
Run Code Online (Sandbox Code Playgroud)
在此之后用户是否需要身份验证,或者uid由此生成的是否足以对用户进行身份验证?到处都是带有 googleAPI 示例的在线用户,用户已在线进行身份验证,但我找不到任何带有google sign in.
我不是 flutter 方面的专家,但根据此处找到的示例,您需要以编程方式向 firebase 进行身份验证的唯一内容是token_id和access_token就像这样:
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
Run Code Online (Sandbox Code Playgroud)
据此,要向 Firebase 进行身份验证,您只需添加登录范围:'email', 'profile' and 'openid'或范围:('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile' and 'openid'它们通常代表相同的内容,具体取决于所使用的库)。然后,使用生成的访问令牌,您可以使用 firebase 库对 firebase 进行身份验证,而无需重新进行身份验证。如果您需要更多信息,请与我们联系。
编辑:
您必须找到 Google 登录收到的访问令牌,并将信息传递给 firebase 登录。访问令牌应如下所示:
{
"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..."
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
479 次 |
| 最近记录: |