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

相关内容

热门资讯

透视挂!wepoker破解版内... 透视挂!wepoker破解版内购(透视)原来真的有挂(详细辅助德州论坛)1、透视辅助简单,软件透明挂...
透视科技!pokemmo脚本辅... 透视科技!pokemmo脚本辅助(透视)竟然存在有挂(详细辅助软件教程)1、首先打开最新版本,在首页...
透视教学!pokermaste... 透视教学!pokermaster脚本(透视)真是存在有挂(详细辅助2025新版总结)1、上手简单,内...
透视新版!红龙poker作弊指... 透视新版!红龙poker作弊指令(透视)本来真的是有挂(详细辅助玩家教你);1、进入游戏-大厅左侧-...
透视肯定!德州局hhpoker... 透视肯定!德州局hhpoker(透视)真是是真的有挂(详细辅助必备教程)1、玩家可以在软件透明挂俱乐...
透视存在!wpk插件(透视)一... 透视存在!wpk插件(透视)一贯存在有挂(详细辅助解说技巧)辅助器中分为三种模型:软件透明挂辅助挂、...
透视实锤!epoker免费透视... 透视实锤!epoker免费透视脚本(透视)都是真的是有挂(详细辅助AI教程)1、系统规律教程、辅助透...
透视脚本!wepoker辅助是... 透视脚本!wepoker辅助是真的吗(透视)切实有挂(详细辅助安装教程)运辅助工具,进入游戏界面。进...
透视实锤!aapoker怎么拿... 透视实锤!aapoker怎么拿好牌(透视)总是存在有挂(详细辅助新版2025教程)1、让任何用户在无...
透视数据!wepoker辅助器... 透视数据!wepoker辅助器安装包(透视)原来是有挂(详细辅助辅助教程)该软件可以轻松地帮助玩家将...