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

相关内容

热门资讯

9分钟了解!情怀麻将友内置挂吗... 9分钟了解!情怀麻将友内置挂吗,闲来麻将输赢靠系统吗,透视教程(有挂技巧);1、闲来麻将输赢靠系统吗...
七分钟了解!兴动助手有挂吗,福... 七分钟了解!兴动助手有挂吗,福建老友麻将有挂的吗,详细教程(有挂方法)进入游戏-大厅左侧-新手福利-...
两分钟了解!闽游福建十三水辅助... 两分钟了解!闽游福建十三水辅助器哪里买,手机上南通长牌有没有外挂,微扑克教程(有挂实操)1.闽游福建...
十分钟了解!豆豆斗牌有辅助吗,... 十分钟了解!豆豆斗牌有辅助吗,开心十三张有外挂吗,AI教程(有挂辅助挂)1、金币登录送、破产送、升级...
8分钟了解!兴动棋牌软件有挂吗... 8分钟了解!兴动棋牌软件有挂吗,闽游十三水辅助器,必赢方法(有挂秘笈);1、下载好兴动棋牌软件有挂吗...
五分钟了解!新蜜瓜正版有没有外... 五分钟了解!新蜜瓜正版有没有外 挂,中至鹰潭麻将有挂吗,扑克教程(有挂方法)1、这是跨平台的新蜜瓜正...
3分钟了解!财神十三张增加胜率... 3分钟了解!财神十三张增加胜率,ccpoker有挂吗,普及教程(有挂插件)1、每一步都需要思考,不同...
五分钟了解!边锋绍兴麻将有挂吗... 五分钟了解!边锋绍兴麻将有挂吗,喜扣跑胡子有外挂吗,细节方法(有挂科普)小薇(透视辅助)致您一封信;...
3分钟了解!中至吉安麻将有挂吗... 3分钟了解!中至吉安麻将有挂吗,新科乐棋牌有没有挂,安装教程(有挂教程);1、每一步都需要思考,不同...
2分钟了解!陕麻圈吗,可乐斗地... 2分钟了解!陕麻圈吗,可乐斗地主残局修改器,靠谱教程(有挂攻略);一、可乐斗地主残局修改器软件透明挂...