不同环境下使用msal.js可能会导致AuthenticationResults不同。
创始人
2025-01-09 03:30:22
0

使用相同的API访问同一环境中的Web API。具体而言,需要确保使用的是相同的scopes和redirectUri,并确保在应用程序注册页面上为相同的应用程序定义了正确的回调URI。以下是代码示例:

var msalConfig = {
    auth: {
        clientId: 'your_client_id',
        redirectUri: 'https://localhost:3000/auth.html',
        authority: 'https://login.microsoftonline.com/common',
        validateAuthority: true,
        navigateToLoginRequestUrl: false,
    },
    cache: {
        cacheLocation: 'localStorage',
        storeAuthStateInCookie: false,
    },
}

// Create the main MSAL instance
var msalInstance = new msal.PublicClientApplication(msalConfig);

// Login using the same scopes and redirectUri for all environments
msalInstance.loginPopup({ scopes: ['user.read'], redirectUri: 'https://localhost:3000/auth.html' })
    .then(function (response) {
        // Use the same access token for all environments
        var token = response.accessToken;
        console.log(token);
        // Call the API using the same scopes and access token for all environments
        callApi('https://your-web-api.com/api/data', token, ['user.read'])
            .then(function (response) {
                console.log(response);
            })
            .catch(function (error) {
                console.log(error);
            });
    })
    .catch(function (error) {
        console.log(error);
    });

相关内容

热门资讯

推荐十款!大菠萝手游辅助,we... 推荐十款!大菠萝手游辅助,wepoker破解器,技巧教程(有挂透明);1分钟了解详细教程(微信 13...
专业讨论!拱趴大菠萝怎么开挂,... 专业讨论!拱趴大菠萝怎么开挂,wejoker开挂,靠谱教程(有挂透明),支持语音通讯、好友开房及战队...
技巧知识分享!hhpoker买... 技巧知识分享!hhpoker买挂,hhpoker有没有作弊挂,黑科技教程(有挂辅助);原来确实真的有...
热门推荐!pokemmo内置修... 热门推荐!pokemmo内置修改器,wejoker辅助器要钱玩吗,技巧教程(有挂软件);原来确实真的...
新手必备!aapoker破解侠... 1、新手必备!aapoker破解侠是真的吗,epoker透视底牌,科技教程(有挂攻略);详细教程。2...
揭秘关于!wepoker透视脚... 揭秘关于!wepoker透视脚本免费app,pokerworld软件,AA德州教程(有挂技巧);小薇...
总算了解!wepoker透视脚... 总算了解!wepoker透视脚本是什么,wepoker有机器人吗,力荐教程(有挂软件);致您一封信;...
六分钟了解!pokemmo脚本... 自定义wepoker数据分析工具系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅...
教程辅助!哈糖大菠萝怎么挂,w... 教程辅助!哈糖大菠萝怎么挂,wepoker祈福有用吗,wpk教程(有挂方法);支持2-10人实时对战...
玩家必看秘籍!hhpoker免... 玩家必看秘籍!hhpoker免费透视脚本,wepoker辅助器软件下载,攻略方法(有挂软件)是一款可...