【发布时间】:2020-03-17 02:44:50
【问题描述】:
我正在创建一个 Javascript 单页应用程序。它要求用户在隐式流程期间登录,以便稍后使用 Microsoft Graph API。 我正在使用 MSAL.js 并尝试从 this guide 调整 sn-ps 以从 authRedirectCallBack
获取身份验证令牌我意识到在其他流程中 redirect uri(在身份验证后使用)对于获取令牌并继续进行是必不可少的。 但是在我的流程中,我在 Javascript 回调函数中处理了令牌。
是否可以避免在向 Azure AD 注册应用程序时和/或在代码执行期间提供 redirect uri?我根本不想将用户带到这个重定向 uri。
目前我的代码如下所示:
var msalConfig = {
auth: {
clientId: 'my-app-id',
},
cache: {
cacheLocation: "localStorage",
storeAuthStateInCookie: true,
forceRefresh: false
}
};
const loginRequest = {scopes: ['openid', 'profile', 'user.read']};
const msalClient = new Msal.UserAgentApplication(msalConfig);
msalClient.handleRedirectCallback(authRedirectCallBack);
singIn();
async function singIn() {
try {
msalClient.loginPopup(loginRequest).then(function (response) {
if (msalClient.getAccount()) {
console.log('logged');
}
});
} catch (err) {
console.log(err);
}
}
function authRedirectCallBack(err, response) {
if (err) {
console.log(err);
} else {
if (response.tokenType === "access_token") {
console.log('token', response);
}
}
}
【问题讨论】:
标签: javascript oauth single-page-application msal