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

相关内容

热门资讯

五分钟普及!中至510k技巧,... 您好,中至510k这款游戏可以开挂的,确实是有挂的,需要了解加微【487309276】很多玩家在这款...
一分钟揭秘!wpk的发牌有规律... 一分钟揭秘!wpk的发牌有规律,wpk神器其实真的有挂,教你攻略(有挂了解)-哔哩哔哩;精心打造了俱...
分享实测!微扑克辅助(辅助挂)... 分享实测!微扑克辅助(辅助挂)外挂辅助工具(2021已更新)(哔哩哔哩),您好,微扑克辅助这款游戏可...
一分钟揭秘(微扑克下载)外挂透... 一分钟揭秘(微扑克下载)外挂透明挂辅助脚本(透视)辅助透视(2021已更新)(哔哩哔哩);微扑克下载...
七分钟攻略!荔枝竞技游戏外挂(... 七分钟攻略!荔枝竞技游戏外挂(透视)外挂透视辅助工具(2025已更新)(哔哩哔哩)1、竞技游戏ai辅...
5分钟了解!wepoke挂真的... 5分钟了解!wepoke挂真的,微扑克总结反正真的有挂,细节方法(有挂了解)-哔哩哔哩;玩家必备必赢...
5分钟了解!微扑克wpk有挂吗... 5分钟了解!微扑克wpk有挂吗(辅助挂)其实真的有挂2024已更新)(哔哩哔哩)1、起透看视 微扑克...
推荐攻略(德扑之星自定义)外挂... 推荐攻略(德扑之星自定义)外挂透视辅助工具(辅助挂)透明挂教程!(2020已更新)(哔哩哔哩);免费...
5分钟实锤!全民牛牛app拼三... 5分钟实锤!全民牛牛app拼三张辅助器(辅助挂)外挂透视辅助插件(2024已更新)(哔哩哔哩)1、每...
发现玩家!wopoker分析器... 发现玩家!wopoker分析器下载,wPk原来真的有挂,2024新版教程!(有挂教学)-哔哩哔哩;亲...