在SwaggerUI中启用OAuth流程

时间:2017-07-09 15:49:43

标签: swagger-ui

在最后一天花了很多时间让SwaggerUI使用OAuth2身份验证流程。好像我几乎在那里,但在从Oauth提供程序(Microsoft Azure AD)返回重定向时,我得到一个 - JavaScript运行时错误:无法获取未定义或空引用的属性'swaggerUiAuth'。

Startup.cs    ConfigureServices

            services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
            // Define the OAuth2.0 scheme that's in use (i.e. Implicit Flow)
            c.AddSecurityDefinition("oauth2", new OAuth2Scheme
            {
                Type = "oauth2",
                Flow = "implicit",
                AuthorizationUrl = "https://login.windows.net/guid-me-this/oauth2/authorize",
                Scopes = new Dictionary<string, string>
                {
                    { "readAccess", "Access read operations" },
                    { "writeAccess", "Access write operations" }
                }
            });
            c.OperationFilter<SecurityRequirementsOperationFilter>();
        });

配置

            app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            // Provide client ID, client secret, realm and application name
            c.ConfigureOAuth2("d0000000-1234-5678-9023-8000000000", 
                "isecretsecretihaveasecret=",
                "http://localhost:44363/swagger/o2c.html", 
                "Swagger UI");
        });

在我的AspNetCore(1.1.2)WebApi中使用Swashbuckle.AspNetCore.SwaggerUI(1.0.0)nuget。

0 个答案:

没有答案