-
Notifications
You must be signed in to change notification settings - Fork 270
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 redirectUrl works only as an absolute path #457
Comments
This could be a simple fix. Perhaps, the only thing needed is to build the absolute oauth2redirecturl before returning the
|
i see. oauth2 redirect is only really sensible when it's an absolute URL. At the moment we simply pass through your settings unchanged. The problem is that this absolute/relative thing has bitten me quite a few times before. This usually breaks half of the userbase because of proxy/translation/deployment details, so it is brittle trying to make URLs absolute. i'm not quite sure how to make everyone happy on this topic. |
It would be easier if a relative path can be given to the |
yes i understand that it would be easier. this may work for you, but it will not work for all users. the last time we attempted to translate relative to absolute, we broke quite a few users. the reason is that some users rewrite urls with a reverse proxy. Django is unable know how to form a valid absolute URL there. i saw a solution where the url is constructed client-side with js (e.g. |
@Joezeppe class OAuthFixedSpectacularSwaggerView(SpectacularSwaggerView):
@extend_schema(exclude=True)
def get(self, request, *args, **kwargs):
"""Some dirty hack to change oauth2RedirectUrl with JS"""
response = super().get(request, *args, **kwargs)
response_data = response.data
settings = json.loads(response_data['settings'])
required_config = '`${window.location.protocol}//${window.location.host}/static/swagger-oauth2-redirect.html`'
settings['oauth2RedirectUrl'] = required_config
settings = json.dumps(settings).replace(f'"{required_config}"', required_config)
response_data['settings'] = settings
return Response(response_data) This hack with replace works because template gets settings with |
@georgy-komarov thanks for that hint. i see you used my suggestion there with can you test if that works for you now?
i have no idea why this file is missing. isn't it supposed to be part of the build release on CDN? it is part of their dist here https://github.com/swagger-api/swagger-ui/tree/master/dist |
Yes, it works when I set settings in such a way.
By default I got inspiration from drf-yasg [1], [2]. They host swagger dist as app's static files. |
I tried to set |
awesome, that is how i initially intended it.
ahh.. CORS... that makes sense i suppose. however i'm still hesitant to include swagger ui dist files into our source. yasg does host it's own version but it is severely outdated and customized. i always tried to stay away from that tight coupling. |
You don't need to include the whole swagger dist. The only file we need is |
i'd like to not open that can of worms for the moment and push that further until something comes along that we cannot get around. although not that big of a deal in this case, it breaks the separation we tried to achieve very diligently. the added fix makes this workable even though convenience is a bit lacking. i'll close this issue as the initial problem is solved. however, we can revisit this again if there are new cirumstances. |
the sidecar is here: https://github.com/tfranzel/drf-spectacular-sidecar convenience methods and doc added with aeda969 now |
When setting the oauth2RedirectUrl as an absolute path in settings like this:
It works fine, but when using a relative path, it doesn't build the absolute url
The text was updated successfully, but these errors were encountered: