diff --git a/app/api/__init__.py b/app/api/__init__.py index b307e92..96d3ce7 100644 --- a/app/api/__init__.py +++ b/app/api/__init__.py @@ -39,7 +39,7 @@ class ProtectedResource(Resource): def add_resources(): from .resources.account import AccountResource, AccountListResource - from .resources.token import TokenResource + from .resources.token import TokenResource, ValidateTokenResource from .resources.device import (DeviceResource, DeviceRecordingResource, DeviceListResource) @@ -47,6 +47,7 @@ def add_resources(): api.add_resource(AccountResource, '/v1/accounts/') api.add_resource(AccountListResource, '/v1/accounts') api.add_resource(TokenResource, '/v1/token') + api.add_resource(ValidateTokenResource, '/v1/token/validate') api.add_resource(DeviceResource, '/v1/devices/') api.add_resource(DeviceRecordingResource, '/v1/devices//recordings') diff --git a/app/api/resources/swagger/validate_token_spec.yaml b/app/api/resources/swagger/validate_token_spec.yaml new file mode 100644 index 0000000..ea5511b --- /dev/null +++ b/app/api/resources/swagger/validate_token_spec.yaml @@ -0,0 +1,22 @@ +Validates token passed in Authorization header +--- +tags: + - Token +responses: + 200: + description: Valid token + schema: + required: + - status + - message + properties: + status: + type: string + default: success + message: + type: string + default: Valid token + 401: + description: Bad credentials + schema: + $ref: '#/definitions/UnauthorizedError' diff --git a/app/api/resources/token.py b/app/api/resources/token.py index 345127f..d98f2b4 100644 --- a/app/api/resources/token.py +++ b/app/api/resources/token.py @@ -2,6 +2,7 @@ from flask_restful import Resource, abort from webargs import fields from webargs.flaskparser import use_args from flasgger import swag_from +from app.api import ProtectedResource import app.accounts as accounts @@ -25,3 +26,9 @@ class TokenResource(Resource): return {'status': 'success', 'token': token}, 200 except ValueError: abort(401, message='Invalid credentials', status='error') + + +class ValidateTokenResource(ProtectedResource): + @swag_from('swagger/validate_token_spec.yaml') + def get(self): + return {'status': 'success', 'message': 'Valid token'}, 200