对于Chrome扩展程序,可以与MSAL一起使用的重定向是什么? [英] What redirect to use with MSAL for a Chrome extension?

查看:227
本文介绍了对于Chrome扩展程序,可以与MSAL一起使用的重定向是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Chrome扩展程序,该扩展程序需要访问需要AAD访问令牌的ASP.NET Core Web API.我正在尝试使用 msal NPM软件包提供身份验证流程,以便用户可以签名使用他们现有的AAD帐户加入我的扩展程序,从而为我的扩展程序提供所需的访问令牌.

I'm writing a Chrome extension that needs to access an ASP.NET Core web API that demands an AAD access token. I'm trying to use the msal NPM package to offer an auth flow so the user can sign in to my extension with their existing AAD account, thereby giving my extension the access token it needs.

到目前为止,有一个弹出窗口可以使用户登录,但是在我的扩展名获得令牌之前,弹出窗口显示以下错误:

I got so far as a popup window that signs the user in, but before my extension gets the token, the popup window displays this error:

ERR_UNSAFE_REDIRECT

ERR_UNSAFE_REDIRECT

我猜这是因为https页面正尝试使用chrome-extension://方案重定向回URL.但是我该怎么办呢?这是我现在拥有的代码:

I'm guessing this is because an https page is trying to redirect back to a URL with a chrome-extension:// scheme. But how should I do it? This is the code I have now:

    var userAgentApplication = new Msal.UserAgentApplication(applicationConfig.clientId, applicationConfig.authority, authCallback, {
        redirectUri: chrome.extension.getURL('popup.html'),
        cacheLocation: 'localStorage',
    });
    const idToken = await userAgentApplication.loginPopup(applicationConfig.scopes);

推荐答案

我发现我需要将redirectUri中使用的html页面添加到manifest.json文件中的web_accessible_resources数组中,作为在此处记录.

I found out that I need to add the html page used in redirectUri to the web_accessible_resources array in my manifest.json file, as documented here.

这篇关于对于Chrome扩展程序,可以与MSAL一起使用的重定向是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆