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

相关内容

热门资讯

透视透视!德普之星怎么作弊,w... 透视透视!德普之星怎么作弊,wpk辅助购买,研究成果(有挂教程)1、起透看视 德普之星怎么作弊透明视...
透视苹果版!aapoker辅助... 透视苹果版!aapoker辅助器怎么用,德州透视脚本,揭秘教程(原来真的有挂)1、让任何用户在无需A...
透视app!德普之星辅助功能如... 透视app!德普之星辅助功能如何打开,aapoker怎么选牌,切实教程(确实是有挂)是由北京得德普之...
透视游戏!aapoker透视插... 透视游戏!aapoker透视插件,德普之星透视辅助ios,科技揭秘(有挂辅助挂)您好,德普之星透视辅...
透视软件!aapoker有脚本... 透视软件!aapoker有脚本吗,hhpoker透视工具,解说技巧(确实有挂)1、让任何用户在无需A...
透视透视挂!wepoker透视... 透视透视挂!wepoker透视脚本苹果版,德普之星透视辅助,揭秘关于(有挂详情),您好,wepoke...
透视ai代打!德普之星辅助器,... 透视ai代打!德普之星辅助器,wejoker免费脚本,必备教程(从来存在有挂);(需添加指定Q群10...
透视代打!wepoker底牌透... 透视代打!wepoker底牌透视脚本,wepoker底牌透视脚本怎样安装,分享认知(有挂规律)1、实...
透视挂透视!wpk透视表,we... 透视挂透视!wpk透视表,wepoker公共底牌,曝光教程(原先有挂)科技教程也叫必备教程,这是一款...
透视透视挂!wpk辅助购买,w... 透视透视挂!wpk辅助购买,wpk有没有脚本,科普分享(有挂方法)是一款可以让一直输的玩家,快速成为...