-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
OAuth2 invalid redirection to localhost:3200 (SwaggerUi3) #961
Comments
Have you checked the served HTML of Swagger UI 3? The auth settings are replaced here: https://github.com/RSuter/NSwag/blob/master/src/NSwag.AspNetCore/SwaggerUi3/index.html#L99 Maybe we need more settings to make this work? |
Can you try to host these files yourself (in your project): https://github.com/RSuter/NSwag/tree/master/src/NSwag.AspNetCore/SwaggerUi3 and find a solution to this problem? As soon as we know how to fix this, we can implement this in NSwag... |
Hitting this issue. ASP.NET Core apps are hosted behind a reverse proxy with IIS. Somehow the internal url is getting used as the redirect url for the oauth instead of the IIS specific address. Easiest solution would be to allow giving the redirect url in the C# OAuth2ClientSettings and using that when initializing the JS client. |
Upon close inspection the wrong url was just a false positive on the identity server logs. The actual issue seems to be that the patch for the redirect is wrong. If my app is hosted at https://localhost/api/app then the redirect url is sent as https://localhost/oauth2-redirect.html. Is there somewhere option to set the base path? |
After deepdive it seems that the problem is not with any reverse proxy thingy either. |
Currently there are not many options in the Swagger UI 3 middleware... We need to add the missing options. |
Any ETA? |
Added the setting ServerUrl => check my commit. Is this how this should work? |
Yes, that is my understanding of how it's suppose to work. |
I'm not sure if the new |
If you use Oauth2/Redirect you also need to set the ServerUrl property... isnt it working if it is correctly set? |
That requires knowing the URL beforehand. It's possible, but it's not very flexible, and I'd prefer not introducing such configuration in my code. For example, locally the app might be running at |
So, should we use |
That would cause problems when the site is configured as an application in IIS (e.g. Something like this maybe: window.location.origin + window.location.pathname.replace("index.html", "oauth2-redirect.html") |
Do you think this would not work? html = html.Replace("{DocExpansion}", DocExpansion);
html = html.Replace("{RedirectUrl}", string.IsNullOrEmpty(ServerUrl) ?
"window.location.origin + \"" + SwaggerUiRoute + "/oauth2-redirect.html\"" :
"\"" + ServerUrl + SwaggerUiRoute + "/oauth2-redirect.html\""); |
I think in this case, you would set MiddlewareBasePath = /MySite and it should work... |
Thanks, I'll give it a try tomorrow. Need to get an URL added to the valid redirect URLs by our OAuth team first. |
Ok, but this change is not released yet... |
I can reproduce this issue using Swashbuckle.AspNetCore.SwaggerUI 2.2.0 on AspNetCore app |
Can we close this? |
I have moved away from using it, so I couldn't say. Sorry.
John Morris
Sr. Software Architect
SoftPro
…________________________________
From: Rico Suter <[email protected]>
Sent: Tuesday, May 29, 2018 7:01 PM
To: RSuter/NSwag
Cc: Morris, John; Comment
Subject: Re: [RSuter/NSwag] OAuth2 invalid redirection to localhost:3200 (SwaggerUi3) (#961)
IMPORTANT NOTICE - This message sourced from an external mail server outside of the Company.
Can we close this?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#961 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/Af_4UrhFen2z7kW3UCctP0oZi7sXuGLEks5t3dMtgaJpZM4PiWrS>.
________________________________
NOTICE: The information contained in this message is proprietary and/or confidential and may be privileged. If you are not the intended recipient of this communication, you are hereby notified to: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately.
|
I had the same issue using NSwag 11.18.6 on .NET Framework 4.6.1 web api. The solution was set the Setting:
@RSuter your fix from 19 Dec 2017 seems to work properly. Thanks! |
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. |
I still have this issue using NSwag.AspNetCore 11.20.1. I haven't set So the URL the API runs is The generated oauth2 redirect URL is So it seems the The suggested solution by @stijnherreman
would work in this scenario and I think it should work in every case... |
I've a similar problem. On Production environment, the application runs on Kestrel behind a Reverse Proxy. So, there's the need to bind I see so many comments here about UsePathBase(), ServerUrl and so on... What are all the necessary settings and where are located? Obviously, I want to avoid hard-coded strings and paths, because the application should be able to be moved to another server/environment without needing a recompilation. |
Same problem here: #1717 |
Closing issue as original problem is solved and discussions are now in this issue: #1717 |
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:
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?
The text was updated successfully, but these errors were encountered: