如何在 Flutter 移动应用程序中将 Azure AD 用户登录到 Firebase?

Jan*_*sen 5 azure-active-directory firebase-authentication flutter

对于 Flutter 移动应用程序,我尝试使用 Microsoft OAuthProvider 获取 Firebase 凭据,使用该凭据将用户与他们的 Azure AD 帐户登录到 Firebase。

我得到的最接近的是使用第三方 Active Directory 身份验证包来登录用户并获取访问令牌。但是,登录 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);
Run Code Online (Sandbox Code Playgroud)

因为它是平台特定的错误(在这种情况下为 iOS),所以不会显示异常详细信息。我得到的是:

PlatformException(内部错误,) nativeErrorCode:17999

这是我在 Azure 门户中的应用设置:

截屏

完整清单在这里

有没有人成功地使用 Microsoft Auth 在 Flutter 移动应用程序中将用户登录到 Firebase?

Pau*_*ain 6

您可以使用Firebase Auth OAuth包。

并使用 Microsoft Auth 提供程序登录 Firebase。

User user = await FirebaseAuthOAuth().openSignInFlow(
  "microsoft.com", ["email openid"], {'tenant': 'your-tenent-id'});
Run Code Online (Sandbox Code Playgroud)

这与 firebase 很好地集成在一起,因此 firebaseauthStateChange也适用于这种方法。