对于 Flutter 移动应用程序,我尝试使用 Microsoft OAuthProvider 获取 Firebase 凭据,使用该凭据将用户与他们的 Azure AD 帐户登录到 Firebase。
我得到的最接近的是使用 third party Active Directory auth package登录用户并获取访问 token 。但是,登录 Firebase 失败并显示一条错误消息,表明 idToken 无效。
final AadOAuth oauth = new AadOAuth(config);
await oauth.login();
// accessToken looks legit
String accessToken = await oauth.getAccessToken();
String idToken = await oauth.getIdToken();
OAuthProvider provider = OAuthProvider('microsoft.com');
// Also tried the constructor without the idToken
OAuthCredential credential = provider.credential(accessToken: accessToken, idToken: idToken);
// app fails here:
await FirebaseAuth.instance.signInWithCredential(credential);
// this works fine, but only on web platform:
await FirebaseAuth.instance.signInWithPopup(provider);
因为它是平台特定的错误(在这种情况下为 iOS),所以不会显示异常详细信息。我得到的是:PlatformException(internal-error, ) nativeErrorCode: 17999
这是我在 Azure 门户中的应用设置:
完整 list here
有没有人成功地使用 Microsoft Auth 在 Flutter 移动应用程序中将用户登录到 Firebase?
最佳答案
您可以使用 Firebase Auth OAuth为它打包。
并使用 Microsoft Auth 提供程序登录 Firebase。
User user = await FirebaseAuthOAuth().openSignInFlow(
"microsoft.com", ["email openid"], {'tenant': 'your-tenent-id'});
这与 firebase 很好地集成在一起,所以 firebase authStateChange
也适用于这种方法。
关于flutter - 如何在 Flutter 移动应用程序中将 Azure AD 用户登录到 Firebase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64066566/