Skip to content

Commit

Permalink
Merge pull request #2326 from pixellos/feat/add-username
Browse files Browse the repository at this point in the history
Add default username for OAuth2 password flow.
  • Loading branch information
domaindrivendev committed Jan 31, 2022
2 parents 2c5306e + d01d8e6 commit 844e11c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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

0 comments on commit 844e11c

Please sign in to comment.