Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
heldersepu committed Mar 15, 2024
2 parents 0d1c45c + 96d45c9 commit 592a3c5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Swagger.Net/Application/SwaggerUiConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public SwaggerUiConfig(IEnumerable<string> discoveryPaths, Func<HttpRequestMessa
{ "%(OAuth2Realm)", "" },
{ "%(OAuth2AppName)", "" },
{ "%(OAuth2ScopeSeparator)", " " },
{ "%(UsePkceWithAuthorizationCodeGrant)", "false" },
{ "%(OAuth2AdditionalQueryStringParams)", "{}" }
};
_rootUrlResolver = rootUrlResolver;
Expand Down Expand Up @@ -183,6 +184,7 @@ public void EnableOAuth2Support(
string realm,
string appName,
string scopeSeperator = " ",
bool usePkce = true,
Dictionary<string, string> additionalQueryStringParams = null)
{
_templateParams["%(OAuth2Enabled)"] = "true";
Expand All @@ -191,6 +193,7 @@ public void EnableOAuth2Support(
_templateParams["%(OAuth2Realm)"] = realm;
_templateParams["%(OAuth2AppName)"] = appName;
_templateParams["%(OAuth2ScopeSeparator)"] = scopeSeperator;
_templateParams["%(UsePkceWithAuthorizationCodeGrant)"] = usePkce ? "true" : "false";

if (additionalQueryStringParams != null)
_templateParams["%(OAuth2AdditionalQueryStringParams)"] = JsonConvert.SerializeObject(additionalQueryStringParams);
Expand Down Expand Up @@ -233,4 +236,4 @@ public enum DefaultModelRender
Model,
Example
}
}
}
2 changes: 2 additions & 0 deletions Swagger.Net/SwaggerUi/CustomAssets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
oAuth2Realm: '%(OAuth2Realm)',
oAuth2AppName: '%(OAuth2AppName)',
OAuth2ScopeSeparator: '%(OAuth2ScopeSeparator)',
usePkceWithAuthorizationCodeGrant: ('%(UsePkceWithAuthorizationCodeGrant)' == 'true'),
oAuth2AdditionalQueryStringParams: JSON.parse('%(OAuth2AdditionalQueryStringParams)')
};
</script>
Expand Down Expand Up @@ -134,6 +135,7 @@
realm: swaggerNetConfig.oAuth2Realm,
appName: swaggerNetConfig.oAuth2AppName,
scopeSeparator: swaggerNetConfig.OAuth2ScopeSeparator,
usePkceWithAuthorizationCodeGrant: swaggerNetConfig.usePkceWithAuthorizationCodeGrant,
additionalQueryStringParams: swaggerNetConfig.oAuth2AdditionalQueryStringParams
})
}
Expand Down
4 changes: 3 additions & 1 deletion Tests/Swagger.Net.Tests/SwaggerUi/SwaggerUiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public void It_exposes_config_for_swagger_ui_outh2_settings()
"test-realm",
"Swagger UI",
" ",
true,
new Dictionary<string, string> { { "TestHeader", "TestValue" } });
});

Expand All @@ -151,6 +152,7 @@ public void It_exposes_config_for_swagger_ui_outh2_settings()
StringAssert.Contains("oAuth2Realm: 'test-realm'", content);
StringAssert.Contains("oAuth2AppName: 'Swagger UI'", content);
StringAssert.Contains("OAuth2ScopeSeparator: ' '", content);
StringAssert.Contains("usePkceWithAuthorizationCodeGrant: ('true' == 'true')", content);
StringAssert.Contains("oAuth2AdditionalQueryStringParams: JSON.parse('{\"TestHeader\":\"TestValue\"}')", content);
}

Expand Down Expand Up @@ -263,4 +265,4 @@ public void It_exposes_config_for_UImaxDisplayedTags()
StringAssert.Contains("maxDisplayedTags: 2", content);
}
}
}
}

0 comments on commit 592a3c5

Please sign in to comment.