2

Spent the last day or so getting SwaggerUI to work with a OAuth2 authentication flow. Seems like Im almost there but on the return redirect from Oauth provider (Microsoft Azure AD) i get a - JavaScript runtime error: Unable to get property 'swaggerUiAuth' of undefined or null reference.

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>();
        });

Configure

            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");
        });

Using the Swashbuckle.AspNetCore.SwaggerUI(1.0.0) nuget in my AspNetCore(1.1.2) WebApi.

David
  • 1,131
  • 9
  • 22

0 Answers0