NSwag: OAuth2 invalid redirection to localhost:3200 (SwaggerUi3)
When you switch from .UseSwaggerUi() to .UseSwaggerUi3() and try to use OAuth 2.0 Authorization in the Swagger Ui, the redirection after signing in (to e.g. Azure AD) always wants to go to localhost:3000.
So:
app.UseSwaggerUi(typeof(Startup).GetTypeInfo().Assembly, new SwaggerUiSettings()
{
OAuth2Client = new OAuth2ClientSettings
{
ClientId = clientId,
ClientSecret = clientSecret,
AppName = "App",
Realm = realm,
AdditionalQueryStringParameters =
{
{ "resource", clientId }
}
},
DocumentProcessors =
{
new SecurityDefinitionAppender("oauth2", new SwaggerSecurityScheme
{
Type = SwaggerSecuritySchemeType.OAuth2,
Description = "DocCheck",
Flow = SwaggerOAuth2Flow.Implicit,
AuthorizationUrl = authorizationUrl,
TokenUrl = tokenUrl,
})
},
OperationProcessors =
{
new OperationSecurityScopeProcessor("oauth2")
},
DefaultPropertyNameHandling = PropertyNameHandling.CamelCase,
});
works correctly.
If you change it to SwaggerUi3 and SwaggerUi3Settings without changing anything else, you always get redirected to localhost:3000 after signing in. I guess its hardcoded somewhere?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 29 (18 by maintainers)
Commits related to this issue
- Added SwaggerUi3 RedirectUrl, #961 — committed to RicoSuter/NSwag by RicoSuter 7 years ago
- Fixed redirecturl, #961 — committed to RicoSuter/NSwag by RicoSuter 7 years ago
- Improved oauth2RedirectUrl handling (SwaggerUi3), #961 — committed to RicoSuter/NSwag by RicoSuter 7 years ago
I had the same issue using NSwag 11.18.6 on .NET Framework 4.6.1 web api.
The solution was set the Setting:
SwaggerUi3Settings.ServerUrl = "..."@RSuter your fix from 19 Dec 2017 seems to work properly. Thanks!
I’ve created a new PR with a new setting: https://github.com/RSuter/NSwag/pull/1728 See #1717 (bottom) for more information
Same problem here: https://github.com/RSuter/NSwag/issues/1717
The earlier reference to MiddlewareBasePath did not work for me. However the ServerUrl property does work. I know use this to correctly configure the url.
settings.ServerUrl = env.IsDevelopment() ? "https://localhost:44399" : "https://api.domain.com/v1";