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

相关内容

热门资讯

透视存在!德普之星辅助工具如何... 透视存在!德普之星辅助工具如何设置,(德扑之心)真是有挂,玩家教程(有挂教程)1、全新机制【德普之星...
透视工具!德普之星辅助工具如何... 透视工具!德普之星辅助工具如何打开,德普之星透视辅助软件下载,存在挂教程(有挂技巧)1、游戏颠覆性的...
透视能赢!德普之星有辅助软件吗... 透视能赢!德普之星有辅助软件吗,德普之星私人局辅助器,揭秘攻略(有挂规律)1、首先打开德普之星私人局...
透视了解!德普之星app安卓版... 透视了解!德普之星app安卓版破解版,(德扑之心)好像有挂,大神讲解(有挂教程)1.德普之星app安...
透视挂透视!德普之星有透视辅助... 透视挂透视!德普之星有透视辅助吗,德普之星辅助工具如何设置,力荐教程(有挂揭秘);1、在德普之星辅助...
透视游戏!德普之星透视软件免费... 透视游戏!德普之星透视软件免费入口官网,德普之星有辅助软件吗,详细教程(有挂技巧);1)德普之星透视...
透视了解!德普之星辅助器,(德... 透视了解!德普之星辅助器,(德扑之心)本来是真的有挂,揭秘攻略(有挂辅助)1、上手简单,内置详细流程...
透视能赢!德普之星透视辅助软件... 透视能赢!德普之星透视辅助软件下载,德普之星有透视辅助吗,靠谱教程(有挂解说)所有人都在同一条线上,...
透视总结!德普辅助器辅助器怎么... 透视总结!德普辅助器辅助器怎么用,(德普)一直是真的有挂,AI教程(有挂介绍)1、让任何用户在无需德...
透视科技!德扑圈透视挂,(德扑... 透视科技!德扑圈透视挂,(德扑之心)竟然真的有挂,实用技巧(有挂细节)1、在德扑圈透视挂ai机器人技...