- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在使用 msal.js 包,以便我可以为我自己的 Vue.js 应用程序使用 azure 授权。
到目前为止,我已经创建了一个 Teams 应用程序,可以在其中访问我的 Vue.js 网站,该网站使用 ngrok 进行隧道传输。
我在 Vue.js 中的代码如下所示(为了安全起见,我在这个 stackoverflow 帖子中用占位符替换了 clientId 和 authority):
import * as Msal from 'msal';
export default {
signIn: async () => {
const aDConfig = {
auth: {
clientId: 'AZUREAPPID',
authority: 'https://login.microsoftonline.com/AZURETENANTID',
redirectUri: 'https://login.microsoftonline.com/common/oauth2/nativeclient',
},
cache: {
cacheLocation: 'localStorage',
storeAuthStateInCookie: true,
},
};
const aDAuth = new Msal.UserAgentApplication(aDConfig);
const loginRequest = {
scopes: ['user.read'],
};
await aDAuth.handleRedirectCallback((error, response) => {
debugger;
console.log(error);
console.log(response);
});
await aDAuth.loginRedirect(loginRequest).then(async (loginResponse) => {
console.log(loginResponse);
debugger;
}).catch((error) => {
console.log(error);
});
},
};
最佳答案
loginRedirect
不返回 Promise(因为它使用户离开当前页面)。如果要处理重定向的结果,需要实现adAuth.handleRedirectCallback(callback)
(这应该在页面加载时完成,在实例化 adAuth
之后立即执行),当 Msal 检测到从重定向流返回后正在加载页面时,将调用它。
见:https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-core/README.md#1-instantiate-the-useragentapplication
编辑:误读了您的代码,我看到您已经这样做了。所以只需删除 .then
在 loginRedirect
你应该很好。
另外,handleRedirectCallback
不返回 Promise,所以你不应该 await
它。您需要实例化 Msal 并在 signIn
之外实现回调。功能(例如在页面加载时)。
import * as Msal from 'msal';
const aDConfig = {
auth: {
clientId: 'AZUREAPPID',
authority: 'https://login.microsoftonline.com/AZURETENANTID',
redirectUri: 'https://login.microsoftonline.com/common/oauth2/nativeclient',
},
cache: {
cacheLocation: 'localStorage',
storeAuthStateInCookie: true,
}
};
const aDAuth = new Msal.UserAgentApplication(aDConfig);
const loginRequest = {
scopes: ['user.read']
};
aDAuth.handleRedirectCallback((error, response) => {
debugger;
console.log(error);
console.log(response);
});
export default {
signIn: async () => {
aDAuth.loginRedirect(loginRequest);
}
};
关于javascript - msal.js 包的 loginRedirect() 方法导致 'TypeError: Cannot read property ' then' of undefined',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59299868/
我从 GitHub 下载了示例以试验 Azure AD B2C https://github.com/Azure-Samples/active-directory-b2c-dotnet-webapp-
为了在我的 JavaScript 代码中使用 MSAL 获取访问 token ,我拼凑了大量教程和文档。这是我的研究结果。 最佳答案 npm 安装@azure/msal 从@azure/msal 导入
我正在编写一个 Chrome 扩展程序,它需要访问需要 AAD 访问 token 的 ASP.NET Core Web API。我正在尝试使用 msal NPM 包提供身份验证流程,以便用户可以使用他
我没有从使用 MSAL 库的 UserAgentApplication 实例的 loginPopup(requestObj) 获得 loginResponse。 Azure 示例用作 https://
我对 OAuth2 以及 AccessToken 和 RefreshToken 的概念比较熟悉。 看起来 MSAL 在使用 ClientApplicationBase.AcquireTokenSile
我使用了 msal.js 文件(版本 1.0.3),但是没有调用 authCallback 函数, var clientApplication = new Msal.UserAgentApplicat
Dynamics 365 的门户功能提供了使用 Azure AD B2C 登录的功能。这是我对其控制能力有限的产品功能,据我所知,该功能是在没有 MSAL 的情况下实现的。 在门户上下文中,我尝试使用
我正在尝试遵循 Microsoft active-directory 的教程 将客户端 ID 和 key 输入代码并运行代码后,它会将我带到登录页面,我使用凭据登录,但出现以下错误: "errorCo
我正在尝试遵循 Microsoft active-directory 的教程 将客户端 ID 和 key 输入代码并运行代码后,它会将我带到登录页面,我使用凭据登录,但出现以下错误: "errorCo
我正在尝试使用 Azure MSAL 浏览器 js CDN 将对象初始化为 PublicClientApplication。但我发现 Msal 未定义。 CDN:https://alcdn.msaut
我尝试使用此处提供的代码:https://github.com/Azure-Samples/active-directory-javascript-singlepageapp-dotnet-webap
@azure/msal-browser 2.14.1@azure/msal-react 1.0.0-beta.2 我们正在使用自定义 B2C 政策 当我使用 PublicClientApplicati
我有一个使用 msal 0.1.2 的 angular7 应用程序。用户间歇性地无法访问任何需要身份验证的内容,当您查看开发人员工具网络选项卡时,您可以看到一个 GET 请求来获取 https://l
@azure/msal-browser 2.14.1@azure/msal-react 1.0.0-beta.2 我们正在使用自定义 B2C 政策 当我使用 PublicClientApplicati
我想使用应用程序 ID 和 secret 对 AAD 用户进行身份验证,以通过 MSAL 访问 powerBi 资源。所以我想获取访问 token 并将其缓存在 SQL Db 中。 经历了 docum
我尝试包含 Azure AD 进行登录,但在运行 npm install @azure/msal-browser @azure/msal-angular 以及 npm install @azure/m
我尝试包含 Azure AD 进行登录,但在运行 npm install @azure/msal-browser @azure/msal-angular 以及 npm install @azure/m
我想安装 @azure/msal-angular 以使用 Angular 作为前端来使用 azure B2C 身份验证,但是当我尝试安装该包时,它给了我一个错误 npm ERR! code E
我想安装 @azure/msal-angular 以使用 Angular 作为前端来使用 azure B2C 身份验证,但是当我尝试安装该包时,它给了我一个错误 npm ERR! code E
使用msal.js库(Microsoft身份验证库),可以通过哪种方法知道给定用户是否已经登录?我的意图是如果用户的凭据已经保存在浏览器的存储中,则避免显示登录弹出窗口 我目前的做法: functio
我是一名优秀的程序员,十分优秀!