Add token validation endpoint
parent
44d5d67b40
commit
8cb0661eb6
|
@ -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/<int:account_id>')
|
||||
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/<int:device_id>')
|
||||
api.add_resource(DeviceRecordingResource,
|
||||
'/v1/devices/<int:device_id>/recordings')
|
||||
|
|
|
@ -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'
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue