当前位置: 首页 > 知识库问答 >
问题:

Azure Functions使用swagger用户界面的广告身份验证说找不到redirect.html

鞠泰平
2023-03-14

我正在使用Azure functions V3这里是我的启动. cs公共覆盖void Configure(IFunctionsHostBuilder builder){ var configuration = builder。GetContext()。配置;

        builder.AddSwashBuckle(Assembly.GetExecutingAssembly(), opts =>
        {
            opts.SpecVersion = Microsoft.OpenApi.OpenApiSpecVersion.OpenApi3_0;
            opts.Title = "My test app";
            
            opts.ConfigureSwaggerGen = x =>
            {
                //custom operation example
                x.CustomOperationIds(apiDesc => apiDesc.TryGetMethodInfo(out MethodInfo methodInfo)
                ? methodInfo.Name
                : new Guid().ToString());

                //custom filter example
                //x.DocumentFilter<RemoveSchemasFilter>();
                //oauth2
                x.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
                {
                    Type = SecuritySchemeType.OAuth2,
                    Flows = new OpenApiOAuthFlows
                    {
                        Implicit = new OpenApiOAuthFlow
                        {
                            AuthorizationUrl = new Uri(string.Format("https://login.microsoftonline.com/{0}/oauth2/v2.0/authorize", configuration["AzureAd:TenantId"])),
                            Scopes = new Dictionary<string, string>
                            {
                                { configuration["AzureAd:scope"], "scope" }
                            }
                        },
                        AuthorizationCode = new OpenApiOAuthFlow
                        {
                            AuthorizationUrl = new Uri(string.Format("https://login.microsoftonline.com/{0}/oauth2/v2.0/authorize", configuration["AzureAd:TenantId"])),
                            TokenUrl = new Uri(string.Format("https://login.microsoftonline.com/{0}/oauth2/v2.0/token", configuration["AzureAd:TenantId"])),
                            Scopes = new Dictionary<string, string>
                            {
                                { configuration["AzureAd:scope"], "scope" }
                            }

                        }
                    }
                });
                x.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                     {
                     new OpenApiSecurityScheme
                        {
                        Reference = new OpenApiReference
                        {
                        Type = ReferenceType.SecurityScheme,
                        Id = "oauth2"
                        },
                                Scheme = "oauth2",
                                Name = "oauth2",
                                In = ParameterLocation.Header
                     },
                        new List<string>()
                     }
                });
                
            };
            opts.ClientId = configuration["AzureAd:ClientId"];
            
            opts.OAuth2RedirectPath = "http://localhost:7071/api/swagger/ui/o2c-html";
            //configuration["AzureAd:redirectURI"];
            
        });
        
        builder.Services.AddLogging();

       
    }

生成了昂首阔步的Ui。但是,当我单击授权时,它会重定向到redirect.html并说找不到。找不到此localhost页面没有找到网址的网页:http://localhost:7071/api/swagger/ui/o2c-html#

共有1个答案

姜经武
2023-03-14

感谢@User1672994对此提供的见解。添加此项解决了问题

/// <summary>
    /// This is only needed for OAuth2 client. This redirecting document is normally served
    /// as a static content. Functions don't provide this out of the box, so we serve it here.
    /// Don't forget to set OAuth2RedirectPath configuration option to reflect this route.
    /// </summary>
    /// <param name="req"></param>
    /// <param name="swashBuckleClient"></param>
    /// <returns></returns>
    [SwaggerIgnore]
    [FunctionName("SwaggerOAuth2Redirect")]
    public static Task<HttpResponseMessage> SwaggerOAuth2Redirect(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "swagger/oauth2-redirect")]
        HttpRequestMessage req,
        [SwashBuckleClient] ISwashBuckleClient swashBuckleClient)
    {
        return Task.FromResult(swashBuckleClient.CreateSwaggerOAuth2RedirectResponse(req));
    }
 类似资料:
  • 根据Spring Security,如果身份验证由外部身份验证提供者完成,则使用身份验证提供者。认证后,Spring Security将获得封装用户信息的认证对象。 如果Spring Security框架进行身份验证,则用户信息被封装在User接口的实例中(例如作为默认实现的User细节类)。 我的问题是——为什么Spring Security框架不能使用一致的方法?为什么他们不能在所有情况下使用

  • 我的代码在这里:代码重新发布是因为我想问一个更直接的问题。如何在未经身份验证的用户和经过身份验证的用户之间切换?我的未经验证的文件似乎已缓存,我使用了以下方法: 在我剩下的api代码之前,它仍然不能工作。谢谢你的帮助 注意:我知道它不起作用,因为我在切换配置/凭据提供程序后立即使用lambda进行调用,并且只有授权用户才能调用此方法。 编辑@behrooziAWS答案: API代码: 完整错误:B

  • 于是我在这里看到:https://firebase . Google . com/docs/auth/web/account-linking # link-auth-provider-credentials-to-a-user-account现在可以在Firebase中链接用户账号了。我还看到Firebase提供了匿名认证的功能,它为一个用户创建一个用户会话,不需要任何凭证。 在我们的应用程序中,

  • 我是jboss和jBPM的新手;我需要关于JBOSS7身份验证的帮助。我们遇到“密码不正确/密码需要”错误。 下面是我们的jboss standlone.*.xml conf的一部分。 谁能帮帮我吗?

  • 问题内容: 是否存在node.js的现有用户身份验证库?特别是,我正在寻找可以对用户进行密码身份验证的东西(使用自定义后端身份验证数据库),并将该用户与会话相关联。 在编写身份验证库之前,我认为我会看看人们是否知道现有的库。通过Google搜索找不到任何明显的内容。 -Shreyas 问题答案: 看起来连接中间件的connect-auth插件正是我所需要的:http : //wiki.github

  • 该应用程序应该接受用户电子邮件和密码,并使用Firebase身份验证作为后端。我使用像素2作为模拟器。每次应用程序处理登录功能时,它都会崩溃。 下面是Java文件和gradle文件 Java文件: