FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit b9553b29 authored by Monty Dawson's avatar Monty Dawson :coffee:
Browse files

Remove openapi security definition code as it was swagger 2 specific

parent 53b84f74
No related branches found
No related tags found
1 merge request!1Initial implementation
Pipeline #172805 waiting for manual action
from django.conf import settings
API_SERVICE_CLIENT_CREDENTIALS = 'API Service OAuth2 Client Credentials'
API_SERVICE_ACCESS_CODE = 'API Service OAuth2 Access Code'
SCOPES_TO_DESCRIPTION = getattr(settings, 'API_GATEWAY_SCOPES_TO_DESCRIPTION', {})
SECURITY_DEFINITIONS = {
API_SERVICE_CLIENT_CREDENTIALS: {
'type': 'oauth2',
'description': (
'Allows authentication using client credentials obtained from the API Service'
),
'flow': 'application', # should be `clientCredentials` when we update to OpenApi 3.0
'tokenUrl': 'https://<gateway_host>/oauth/client_credential/accesstoken'
'?grant_type=client_credentials',
'scopes': SCOPES_TO_DESCRIPTION
},
API_SERVICE_ACCESS_CODE: {
'type': 'oauth2',
'flow': 'accessCode',
'authorizationUrl': 'https://<gateway_host>/oauth2/v1/auth',
'tokenUrl': 'https://<gateway_host>/oauth2/v1/token',
'scopes': SCOPES_TO_DESCRIPTION
}
}
def any_api_service_security_method_with_scopes(*scopes):
"""
Helper method which returns security definitions for any API Service security
method with the given scopes.
"""
return [
{security_method: list(scopes)}
for security_method in SECURITY_DEFINITIONS.keys()
]
from django.test import TestCase
from apigatewayauth.openapi import any_api_service_security_method_with_scopes
class OpenAPITestCase(TestCase):
def test_any_api_service_security_method_with_scopes(self):
"""
Test that the service definitions are returned for a given set of scopes.
"""
self.assertListEqual(
any_api_service_security_method_with_scopes('read', 'write', 'admin'),
[
{
'API Service OAuth2 Client Credentials': ['read', 'write', 'admin']
},
{
'API Service OAuth2 Access Code': ['read', 'write', 'admin']
}
]
)
...@@ -20,7 +20,7 @@ setup( ...@@ -20,7 +20,7 @@ setup(
long_description=open('README.md').read(), long_description=open('README.md').read(),
long_description_content_type='text/markdown', long_description_content_type='text/markdown',
url='https://gitlab.developers.cam.ac.uk/uis/devops/django/api-gateway-auth', url='https://gitlab.developers.cam.ac.uk/uis/devops/django/api-gateway-auth',
version='0.0.1-rc1', version='0.0.1-rc2',
license='MIT', license='MIT',
author='DevOps Division, University Information Services, University of Cambridge', author='DevOps Division, University Information Services, University of Cambridge',
author_email='devops@uis.cam.ac.uk', author_email='devops@uis.cam.ac.uk',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment