question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OAuth2 invalid redirection to localhost:3200 (SwaggerUi3)

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:29 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
jfidotcommented, Sep 18, 2018

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!

1reaction
RicoSutercommented, Nov 9, 2018

I’ve created a new PR with a new setting: https://github.com/RSuter/NSwag/pull/1728 See #1717 (bottom) for more information

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger UI Authorization using IdentityServer4 returns ...
The redirect address with the port 3200 is hardcoded into the Swagger UI. Fortunately, there is a simple workaround by adding the key ......
Read more >
Solved: Receiving a "redirect_uri_mismatch" error when aut...
I'm trying to use OAUTH 2.0 to authenticate/authorize. I'm testing on my local machine, where my application is running and accessible over HTTPS....
Read more >
Authorization Code Request: 400 - Invalid redirect...
Hi, I'm in the process of implementing OAuth 2.0 server flow authentication on my platform which serves multiple organizations with each - 323044....
Read more >
Not able to Authenticate through Swagger #1896
Apparently you have the dev environment redirect uri (https://localhost:44318/swagger/oauth2-redirect.html) and missing production redirect uri ...
Read more >
OAuth2.0 Redirect URI invalid error - Help - Intuit
I'm trying to develop an app to connect to Bubble.io's API Connector, and using Bubble's generic redirect URI that's provided by their API ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found