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

相关内容

热门资讯

透视计算"wepok... 透视计算"wepoker代打辅助"详细辅助玩家教程(智能辅助插件辅助);致您一封信;亲爱wepoke...
透视系统"拱趴大菠萝... 透视系统"拱趴大菠萝有什么挂"详细辅助2025教程(私人局俱乐部技巧)是一款可以让一直输的玩家,快速...
透视总结"xpoke... 透视总结"xpoker辅助助手"详细辅助线上教程(私人局开挂视频技巧)是一款可以让一直输的玩家,快速...
透视系统"wepok... 透视系统"wepoker私局辅助"详细辅助存在挂教程(透视脚本免费方法);支持多人共享记分板与复盘,...
透视玄学"黑侠破解w... 1、透视玄学"黑侠破解wepoker"详细辅助可靠教程(有辅助插件技巧)。2、黑侠破解wepoker...
透视游戏"aapok... 透视游戏"aapoker辅助插件工具"详细辅助新2025版(黑侠辅助器辅助);科技安装教程;1367...
透视实锤"淘宝买we... 透视实锤"淘宝买wepoker透视有用吗"详细辅助解说技巧(线上大神技巧);致您一封信;亲爱淘宝买w...
透视游戏"wepok... 透视游戏"wepoker软件靠谱么"详细辅助线上教程(辅助器安装包透视);支持多人共享记分板与复盘,...
透视苹果版"拱趴大菠... 透视苹果版"拱趴大菠萝十三水作弊"详细辅助德州教程(透视最简单三个步骤软件);支持2-10人实时对战...
透视数据"hhpok... 透视数据"hhpoker外挂靠谱吗"详细辅助专业教程(辅助器可以弄透视);支持2-10人实时对战,虚...