Asp.net core mvc Swagger永久授权令牌

Asp.net core mvc Swagger永久授权令牌,asp.net-core-mvc,swagger,Asp.net Core Mvc,Swagger,我正在ASP.NET核心MVC中开发web api。我想知道是否有办法使swagger中的授权令牌持久化,这样就不需要在每次运行应用程序时手动执行授权。 这将使测试更容易。本地存储可用于保存授权令牌 要将令牌存储到本地存储器中,请在浏览器控制台中键入: localStorage.setItem('authKey', 'the authorization token') 然后,使用请求拦截器从本地存储提供令牌作为授权标头: const ui = SwaggerUIBundle({ url

我正在ASP.NET核心MVC中开发web api。我想知道是否有办法使swagger中的授权令牌持久化,这样就不需要在每次运行应用程序时手动执行授权。
这将使测试更容易。

本地存储可用于保存授权令牌

要将令牌存储到本地存储器中,请在浏览器控制台中键入:

localStorage.setItem('authKey', 'the authorization token')
然后,使用请求拦截器从本地存储提供令牌作为授权标头:

const ui = SwaggerUIBundle({
    url: "/swagger/v2/swagger.json",
    dom_id: '#swagger-ui',
    deepLinking: true,
    requestInterceptor: function (req) {
        var key = localStorage.getItem("authKey");

        if (key && key.trim() !== "") {
            req.headers.Authorization = 'Bearer ' + key;
            console.log('Authorized from authKey');
        }
    },
    presets: [
        SwaggerUIBundle.presets.apis,
        SwaggerUIStandalonePreset
    ],
    plugins: [
        SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout",
})

window.ui = ui;

接收错误,未捕获引用错误,未定义swaggerui捆绑包也未执行本地存储。setItem('key',ettc发出未定义的警告replyRelated-