Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default username for OAuth2 password flow. #2326

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ public enum SubmitMethod

public class OAuthConfigObject
{
/// <summary>
/// Default username for OAuth2 password flow.
/// </summary>
public string Username { get; set; } = null;

/// <summary>
/// Default clientId
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void InjectJavascript(this SwaggerUIOptions options, string path,
public static void SwaggerEndpoint(this SwaggerUIOptions options, string url, string name)
{
var urls = new List<UrlDescriptor>(options.ConfigObject.Urls ?? Enumerable.Empty<UrlDescriptor>());
urls.Add(new UrlDescriptor { Url = url, Name = name} );
urls.Add(new UrlDescriptor { Url = url, Name = name });
options.ConfigObject.Urls = urls;
}

Expand Down Expand Up @@ -221,6 +221,16 @@ public static void OAuthClientId(this SwaggerUIOptions options, string value)
options.OAuthConfigObject.ClientId = value;
}

/// <summary>
/// Default userName
/// </summary>
/// <param name="options"></param>
/// <param name="value"></param>
public static void OAuthUsername(this SwaggerUIOptions options, string value)
{
options.OAuthConfigObject.Username = value;
}

/// <summary>
/// Default clientSecret
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions test/WebSites/OAuth2Integration/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
c.EnableDeepLinking();

// Additional OAuth settings (See https://github.com/swagger-api/swagger-ui/blob/v3.10.0/docs/usage/oauth2.md)
c.OAuthUsername("username");
c.OAuthClientId("test-id");
c.OAuthClientSecret("test-secret");
c.OAuthAppName("test-app");
Expand Down