|
|
"""Authentication API blueprint and endpoint definitions.""" from flask import Blueprint, g, request
from atheneum.api.decorators import return_json from atheneum.api.model import APIMessage, APIResponse from atheneum.middleware import authentication_middleware from atheneum.model import UserToken from atheneum.service import ( authentication_service, transformation_service, user_service, user_token_service, )
AUTH_BLUEPRINT = Blueprint( name='auth', import_name=__name__, url_prefix='/auth')
@AUTH_BLUEPRINT.route('/login', methods=['POST']) @return_json @authentication_middleware.require_basic_auth def login() -> APIResponse: """
Get a token for continued authentication.
:return: A login token for continued authentication """
new_token_options: UserToken = transformation_service.deserialize_model( UserToken, request.json, ['note', 'expirationTime']) user_token = user_token_service.create( g.user, note=new_token_options.note, expiration_time=new_token_options.expiration_time) return APIResponse(user_token, 200)
@AUTH_BLUEPRINT.route('/bump', methods=['POST']) @return_json @authentication_middleware.require_token_auth def login_bump() -> APIResponse: """
Update the user last seen timestamp.
:return: A time stamp for the bumped login """
user_service.update_last_login_time(g.user) return APIResponse(g.user, 200, ['lastLoginTime'])
@AUTH_BLUEPRINT.route('/logout', methods=['POST']) @return_json @authentication_middleware.require_token_auth def logout() -> APIResponse: """
Logout and delete a token.
:return: """
authentication_service.logout(g.user_token) return APIResponse(APIMessage(True, None), 200)
|