Ejemplo n.º 1
0
    def wrapped(*args, **kwargs):
        auth_service = AuthService()
        auth_token = auth_service.extract_token(request)
        if not auth_token:
            message = "This resource cannot be accessed without a valid authentication token"
            source = auth_service.AUTH_HEADER_KEY
            return utils.make_error(errors.UnauthenticatedRequestError(message, source))

        payload = None
        try:
            payload = auth_service.validate_token(auth_token)
        except exceptions.TokenValidationException, e:
            message = e.message
            source = auth_service.AUTH_HEADER_KEY
            return utils.make_error(errors.UnauthenticatedRequestError(message, source))
Ejemplo n.º 2
0
    def wrapped(*args, **kwargs):
        auth_service = AuthService()
        auth_token = auth_service.extract_token(request)
        if not auth_token:
            message = "This resource cannot be accessed without a valid authentication token"
            source = auth_service.AUTH_HEADER_KEY
            return utils.make_error(
                errors.UnauthenticatedRequestError(message, source))

        payload = None
        try:
            payload = auth_service.validate_token(auth_token)
        except exceptions.TokenValidationException, e:
            message = e.message
            source = auth_service.AUTH_HEADER_KEY
            return utils.make_error(
                errors.UnauthenticatedRequestError(message, source))
Ejemplo n.º 3
0
    def wrapped(*args, **kwargs):
        data = args[0] if len(args) else None
        auth_token = None
        if data:
            data = loads(data)
            auth_token = data.get('token')
            kwargs['data'] = data

        if not auth_token:
            message = "This resource cannot be accessed without a valid authentication token"
            kwargs['error'] = message
        else:
            auth_service = AuthService()
            try:
                payload = auth_service.validate_token(auth_token)
                kwargs['user'] = payload
            except exceptions.TokenValidationException, e:
                message = e.message
                kwargs['error'] = message
Ejemplo n.º 4
0
    def wrapped(*args, **kwargs):
        data = args[0] if len(args) else None
        auth_token = None
        if data:
            data = loads(data)
            auth_token = data.get('token')
            kwargs['data'] = data

        if not auth_token:
            message = "This resource cannot be accessed without a valid authentication token"
            kwargs['error'] = message
        else:
            auth_service = AuthService()
            try:
                payload = auth_service.validate_token(auth_token)
                kwargs['user'] = payload
            except exceptions.TokenValidationException, e:
                message = e.message
                kwargs['error'] = message
Ejemplo n.º 5
0
from flask_restplus import Namespace, Resource
from flask_jwt_extended import jwt_required
from app import api, redis_store
from app.auth.models import login
from app.auth.service import AuthService
from app.common.models import auth_parser
from flask_jwt_extended import get_raw_jwt

auth_ns = Namespace('auth', description="User Authentication")

auth_service = AuthService()

@auth_ns.route('/login')
class AuthLogin(Resource):
    """
    Authentication APIs for Login
    """
    @auth_ns.expect(login)
    def post(self):
        """
        Login Request
        :return:
        """
        response = auth_service.login(api.payload)
        return response


@auth_ns.expect(auth_parser)
@auth_ns.route('/logout')
class AuthLogout(Resource):
    """