Closed sshellabarger closed 6 years ago
Hello, I have coded 'security' support in a local branch and it works, at least in my scenario. I'm wondering if this feature will be officially included or it's better I do a 'pull request' of my approach:
Given an authentication class used in Eve:
class MyTokenAuth(TokenAuth):
I define the swagger securityDefinitions:
app = Eve(auth=MyTokenAuth())
app.config['SWAGGER_SECURITY_DEFINITIONS'] = {
"MyTokenAuth": {
"type": "apiKey",
"name": "Access-Token",
"in": "header"
}
}
Then, all Eve resources and items methods will have the swagger specification 'security':
"security": [
{
"MyTokenAuth": []
}
]
Tell me if a pull request of this approach is wanted, in that case I will prepare documentation and tests.
Actually, there is another approach using 'eve_swagger.add_documentation()'. Therefore is not necessary touch any eve-swagger source code.
Here it is:
app = Eve(auth=MyTokenAuth())
####################################################################
# Add security documentation
eve_swagger.add_documentation({'securityDefinitions': {
"MyTokenAuth": {
"type": "apiKey",
"name": "Access-Token",
"in": "header"
}
}})
# iterate over all resources and items and add security
for resource, rd in app.config['DOMAIN'].items():
if (rd.get('disable_documentation')
or resource.endswith('_versions')):
continue
methods = rd['resource_methods']
url = '/%s' % rd['url']
for method in methods:
eve_swagger.add_documentation({'paths': {url: {method.lower(): {"security": [{"MyTokenAuth": []}]}}}})
methods = rd['item_methods']
item_id = '%sId' % rd['item_title'].lower()
url = '/%s/{%s}' % (rd['url'], item_id)
for method in methods:
eve_swagger.add_documentation({'paths': {url: {method.lower(): {"security": [{"MyTokenAuth": []}]}}}})
####################################################################
@marceljanerfont so this scenario works only for global auth definition and not at resource/operation level. Thanks BTW!
Would be nice to code a full solution :) swagger seems to support operation security definition but not sure how it's implemented and how it looks in Swagger UI.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
When will eve-swagger support securityDefinitions?