mul*_*sen 5 javascript azure firebase-authentication
我正在使用 Google Firebase 实现网络用户登录。我在 Google 和 Facebook 上使用了此功能(我正在获取填充的user
对象),但对于 Microsoft 登录,即使在登录屏幕上授权后,我也会进入null
该对象。user
我的代码:
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.17.2/firebase-app.js";
import {
getAuth,
signInWithRedirect,
getRedirectResult,
signOut,
GoogleAuthProvider,
FacebookAuthProvider,
OAuthProvider, // microsoft
onAuthStateChanged
} from "https://www.gstatic.com/firebasejs/9.17.2/firebase-auth.js";
const firebaseConfig = { /* my settings */ };
const firebase = initializeApp(firebaseConfig);
const auth = getAuth(firebase);
document.querySelector('.login-with button.microsoft').addEventListener('click', microsoftSignIn, false);
function microsoftSignIn() {
const provider = new OAuthProvider('microsoft.com');
signInWithRedirect(auth, provider);
}
onAuthStateChanged(auth, user => {
if (user) {
console.log("user is logged in", user);
} else {
console.log("user is not logged in");
}
});
Run Code Online (Sandbox Code Playgroud)
在 Azure AD 中,我已将重定向 URI 设置为https://my-app.firebaseapp.com/__/auth/handler。我还添加了本地主机,尽管我怀疑这是没有必要的:
我授予它登录用户的权限:
我已将客户端 ID 和密钥复制回 firebase auth。
当我测试登录时,我得到以下信息:
然后,在我接受后,我被重定向回我的网站,但user
对象是null
。我怎样才能获得填充的user
对象?另请注意,即使使用 ngrok 在 https URL 上托管我的网站,结果也是相同的。
我在一月份就经历过这个。
您必须验证自己作为发布者的身份。
如图2所示:
从 2020 年 11 月 9 日开始,未经验证的发布商,最终用户将无法再向新注册的多租户应用程序授予同意。
这意味着如果您的 Microsoft AD“应用程序”可用于多租户,您将需要完成注册。
仅当您正在构建单租户应用程序时,您才可以未经验证。
另请注意,如果您使用的 Microsoft 帐户是 Active Directory 的一部分(例如学校或工作帐户),则 AD 管理员必须先注册并同意应用程序连接到 AD,然后再其他用户可以同意。
因此,如果您要在应用程序中测试登录流程,最好使用个人 Microsoft 帐户或属于您拥有管理员权限的 Active Directory 一部分的帐户。
归档时间: |
|
查看次数: |
329 次 |
最近记录: |