Azure活动目录颤振身份验证问题



我的应用程序使用Azure活动目录身份验证。我设法使用aad_oauth获得访问令牌。但是我无法使用该凭据登录到firebase。

final Config config = Config(
tenant: 'my_tenant',
clientId: 'my_clientId',
scope: 'https://graph.microsoft.com/User.Read/offline_access',
redirectUri:
'https://login.microsoftonline.com/common/oauth2/nativeclient',
);
final AadOAuth oauth = AadOAuth(config);
await oauth.login();
String? accessToken = await oauth.getAccessToken();
final OAuthProvider oAuthProvider = OAuthProvider('microsoft.com');
oAuthProvider.addScope('openid');
final OAuthCredential credential = oAuthProvider.credential(
accessToken: accessToken,
);
try {
final UserCredential authResult =
await _firebaseAuth.signInWithCredential(credential);
_updateAuthStatus(authResult);
} on FirebaseAuthException catch (e) {
print('caught firebase auth exceptionn ${e.code}n ${e.message}');
} catch (e) {
print('Error -- $e');
}

我得到错误消息- FLTFirebaseAuth:调用方法Auth#signInWithCredential时发生错误,errorOrNil =>(空)。如有任何帮助,我将不胜感激。

在您提供的代码中,您有_firebaseAuth.signInWithCredential_firebaseAuthnull,您缺少初始化它,或者您使用无效值(null?)初始化它

这是初始化FirebaseAuth实例的方法。

FirebaseAuth _auth = FirebaseAuth._instance_;

请参考这篇文章,它展示了如何将您的flutter应用程序与FirebaseAuth集成。

你也可以参考这个SO线程,这里也讨论过。

最新更新