-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Swagger Oauth redirect not working #195
Comments
Thanks for your feedback. I didn't test this feature before. So I just follow the Swagger OAuth2 + Google OAuth2 documents. The SecurityScheme I use is SecurityScheme(
name="auth_oauth2",
data={
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://accounts.google.com/o/oauth2/v2/auth",
"tokenUrl": "https://sts.googleapis.com",
"scopes": {
"https://www.googleapis.com/auth/tasks.readonly": "View your tasks",
},
},
},
},
) I found that the redirect URL is incorrect. Here is a good answer: https://stackoverflow.com/a/54251778 After I change this in the window.onload = function() {{
var full = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
// Begin Swagger UI call region
const ui = SwaggerUIBundle({{
url: "{spec_url}",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
oauth2RedirectUrl: full + "/apidoc/swagger",
layout: "StandaloneLayout"
}})
// End Swagger UI call region
window.ui = ui
}} I'll create a PR. |
Hi @ttekampe you can try the following PR to see if it works for you. |
@kemingy I just tested, the redirect is working. Thanks a lot! I have one remaining question about the |
I found a document about this: Will add this feature. |
Hi @ttekampe, you can install the following PR and try to add the spectree/examples/security_demo.py Lines 45 to 50 in b574d1d
|
Hi @kemingy, thanks a lot for your help! The client_id is now prepopulated and also the redirect back to the swagger from the authorization server is working. The URL I am redirected to from the auth endpoint looks like this:
(is there a Also, looking at other swaggers, their redirect url goes to It should be this file here I tried working with a local copy of spectree making the following change in
but this only results in a 404 after the redirect. |
Hi @ttekampe, thanks for your feedback. I added this I encountered a "TypeError: NetworkError when attempting to fetch resource." error. I think it's related to the CORS.
Let me know if you have any other questions. |
Hi @kemingy , I just tested your latest changes and it works now. Thank you very much! |
Describe the bug
I am trying to set up swagger with oauth2 flow. I set the the
authorizationUrl
in theSecurityScheme
that I pass to theSpecTree
constructor. On the swagger page that is created by spectree I can click the Authorize button, which redirects me to my identity provider's login page. If I login, I am redirected back to the swagger with some query parameters that include the JWT. However, the URL that I am redirected to does not exist in the app.I am new to setting up swagger, is this URL endpoint created automatically by spectree on my falcon app, or is some work needed from my end?
Expected behavior
I should end up on the swagger page again with the Authorization header prepopulated such that I can send requests to the endpoints documented in the OpenAPI specs that already include the JWT.
Desktop (please complete the following information):
Python Information (please complete the following information):
Additional context
Maybe I am just missing some required steps to set this up. If that is the case, would it be possible for you to add documentation around this topic?
The text was updated successfully, but these errors were encountered: