Skip to content
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 password credential doesn't work in SwaggerUI #138

Closed
StdCarrot opened this issue Feb 24, 2016 · 7 comments
Closed

OAuth2 password credential doesn't work in SwaggerUI #138

StdCarrot opened this issue Feb 24, 2016 · 7 comments
Labels
Milestone

Comments

@StdCarrot
Copy link

In SwaggerUI which created by flask-restplus, just simple request is working well.

But, if I trying to use oauth2 with password credential then the credential popup doesn't show up.

To make sure this problem, I tried to use SwaggerUI from SwaggerUI project page with Swagger json; /swagger.json.

And it worked. But the other SwaggerUI that created by flask-restplus still doesn't work.

I think, something wrong in swagger template at flask-restplus on pip-py3.

Please check it.

@frol
Copy link
Contributor

frol commented Feb 27, 2016

It is just a lack of implementation in Swagger UI, and here is an open PR swagger-api/swagger-ui#1853.

BTW, you may also be interested in an extensive example RESTful API server based on Flask-RESTplus with some patches: https://github.com/frol/flask-restplus-server-example

@StdCarrot
Copy link
Author

But it worked with swagger.json that generated by flask-restplus on this template: https://github.com/swagger-api/swagger-ui/blob/master/dist/index.html

@frol
Copy link
Contributor

frol commented Feb 28, 2016

Password Flow can be displayed in Swagger-UI, but it won't work unless the related support is merged. By the way, once I re-read your initial issue description it occurred to me that you may have missed @api.doc(security=...) decorator to your endpoints. Having your swagger.json is required to say something for certain.

@StdCarrot
Copy link
Author

My code looks like this:

@ns.route('/me')
class CurrentMemberAPI(Resource):
    @api.doc(security=[{'oauth2_password': ['member:read']}])
    @api.marshal_with(member_fields)
    @oauth.require_oauth('member:read')
    def get(self):
        """
        Get my member information
        """
        return request.oauth.user.dict(include_company=True)

    @api.doc(parser=member_parser, security=[{'oauth2_password': ['member:write']}])
    @api.marshal_with(member_fields)
    @api.response(400, 'Invalid profile file type or Invalid fields set')
    @oauth.require_oauth('member:write')
    def put(self):
        """
        Modify my member information

        If you want to upload profile image, fill profile_file field.
        Also, you can fill profile[uid] field after upload something

        email[] field will not work. If you want to modify member's email, use /member/me/email.
        """
        args = Process.parse_args(member_parser.parse_args())
        member = request.auth.user
...

My swagger.son is perfectly fine as I checked and it worked on other swagger template.
If you want, I can give the template to you.

@frol
Copy link
Contributor

frol commented Feb 29, 2016

Everything looks fine to me. Is there any error in Dev tools console?

I'm actually using a custom SwaggerUI (the one which includes my PR with Password Flow OAuth2 support) and it works just fine for me, but I know that neither the SwaggerUI master branch nor prepackaged version in Flask-RESTplus will work, so I haven't even try.

@StdCarrot
Copy link
Author

I see, maybe I used dev branch of SwaggerUI for password credential.
But it still problem that flask-resplus's SwaggerUI template doesn't work for some authorizing flow even it work on other template. I think.

@frol
Copy link
Contributor

frol commented Mar 2, 2016

Oh yeah, I remember it now! I have a custom template with uncommented initOAuth, since Flask-RESTplus has it commented out for some reason: https://github.com/noirbizarre/flask-restplus/blob/master/flask_restplus/templates/swagger-ui.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants