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

相关内容

热门资讯

德扑之星有作弊!德州wpk(透... 德扑之星有作弊!德州wpk(透视)竟然真的有挂(详细辅助黑科技教程)是一款可以让一直输的玩家,快速成...
微扑克有辅助挂!微扑克辅助是什... 自定义微扑克有辅助挂系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器,不管你...
wpk ai辅助!微扑克全自动... wpk ai辅助!微扑克全自动机器人(透视)一向存在有挂(详细辅助2025教程)1)微扑克全自动机器...
aapoker透明挂!aa p... aapoker透明挂!aa poker智能ai辅助介绍(透视)从前有挂(详细辅助解说技巧)是一款可以...
wepoke辅助挂!weopk... 自定义wepoke辅助挂系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器,不...
微扑克全自动机器人!德扑之星软... 微扑克全自动机器人!德扑之星软件介绍(透视)其实有挂(详细辅助教你攻略)是一款可以让一直输的玩家,快...
微扑克辅助软件!wpk被系统针... 微扑克辅助软件!wpk被系统针对(透视)起初有挂(详细辅助安装教程);是一款可以让一直输的玩家,快速...
wepoke辅助有挂!wpk怎... 1、wepoke辅助有挂!wpk怎么下载ios(透视)起初是有挂(详细辅助wpk教程);代表性(透视...
aapoker透视辅助!德州游... 1、aapoker透视辅助!德州游戏辅助器大全(透视)原本真的有挂(详细辅助必胜教程);代表性(透视...
德扑之星有作弊!aa扑克有外挂... 德扑之星有作弊!aa扑克有外挂吗(透视)真是是有挂(详细辅助攻略教程)1、超多福利:超高返利,海量正...