RicoSuter/NSwag

Swagger UI password authorization

Open

#1,235 opened on Mar 23, 2018

View on GitHub
 (0 comments) (0 reactions) (0 assignees)C# (6,291 stars) (1,189 forks)batch import
help wantedproject: NSwag.AspNetCoretype: bug

Description

OAuth2 password flow does not transmit client_id: image

Settings:

app.UseSwaggerUi(typeof(AboutController).GetTypeInfo().Assembly,
options => 
{
	options.OAuth2Client = new OAuth2ClientSettings
	{
		ClientId = Contracts.Constants.ApiClientId,
		AppName = "Swagger",
	};

	var gen = options.GeneratorSettings;

	gen.DocumentProcessors.Add(new SecurityDefinitionAppender("oauth2", new SwaggerSecurityScheme
	{
		Type = SwaggerSecuritySchemeType.OAuth2,
		Description = "OAuth",
		Flow = SwaggerOAuth2Flow.Password,
		AuthorizationUrl = hostingConfiguration.AuthorizationUrl,
		TokenUrl = hostingConfiguration.TokenUrl,
		
		Scopes = new Dictionary<string,string>
		{
			{ Contracts.Constants.ApiScopeName, Contracts.Constants.ApiScopeName },
		}
		
	}));

	gen.OperationProcessors.Add(new OperationSecurityScopeProcessor("oauth2"));
	gen.DefaultPropertyNameHandling = PropertyNameHandling.CamelCase;
});

Contributor guide