不同环境下使用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);
    });

相关内容

热门资讯

今日头条!微信老友广东辅助器,... 今日头条!微信老友广东辅助器,微乐福建辅助器,安装教程(原来有开挂辅助器)是一款可以让一直输的玩家,...
每日必看推荐!微信小程序家乡大... 每日必看推荐!微信小程序家乡大二辅助工具,新西游辅助器,透视教程(原来有开挂辅助安装);1、选手技艺...
玩家亲测!广东插件智能插件安装... 玩家亲测!广东插件智能插件安装包免费,wepoker轻量版有透视吗,详细教程(原来有开挂辅助挂);广...
重大通报!哈糖大菠萝开挂,we... 重大通报!哈糖大菠萝开挂,we-poker是什么软件,解密教程(原来有开挂辅助助手);1.哈糖大菠萝...
解密关于!鱼乐达人辅助修改器,... 解密关于!鱼乐达人辅助修改器,下载微乐小程序自建房透视,介绍教程(原来有开挂辅助软件);解密关于!鱼...
重大发现!四川家园游戏辅助,微... 重大发现!四川家园游戏辅助,微乐自建房辅助多少钱一个月,AI教程(原来有开挂辅助器);微乐自建房辅助...
玩家必用!玉海楼茶苑怎么开挂,... 玩家必用!玉海楼茶苑怎么开挂,天酷互娱有辅助工具嘛,黑科技教程(原来有开挂辅助插件);天酷互娱有辅助...
一分钟教你!椰岛常胜游戏破解,... 一分钟教你!椰岛常胜游戏破解,广东雀神透视,解密教程(原来有开挂辅助下载);椰岛常胜游戏破解软件透明...
实测发现!三江互娱辅助,wpk... 实测发现!三江互娱辅助,wpk显示有透视挂,详细教程(原来有开挂辅助助手),三江互娱辅助是用手机号来...
程序员教你!长春科乐第三方辅助... 程序员教你!长春科乐第三方辅助工具,wepoker代打辅助机器人,曝光教程(原来有开挂辅助黑科技);...