Ejemplo n.º 1
0
def auth_request_handle():
    data = request.get_json()
    username    = data.get(current_app.config.get('JWT_AUTH_USERNAME_KEY'), None)
    password    = data.get(current_app.config.get('JWT_AUTH_PASSWORD_KEY'), None)
    user_type   = data.get(current_app.config.get('JWT_AUTH_LOGIN_TYPE_KEY'), None)

    identity = _jwt.authentication_callback(username, password, user_type)

    if identity:
        access_token = _jwt.jwt_encode_callback(identity)
        return _jwt.auth_response_callback(access_token, identity)
    else:
        raise JWTError('Bad Request', 'Invalid credentials2')
Ejemplo n.º 2
0
    def post(self):
        """Authenticates and generates a token."""
        args = parser.parse_args()
        data = request.get_json(force=True)
        username = args.get('email')
        password = args.get('password')
        criterion = [username, password, len(data) == 2]

        if not all(criterion):
            raise JWTError('Bad Request', 'Invalid credentials')

        identity = _jwt.authentication_callback(username, password)
        if identity is not None:
            user = User.objects.get(id=identity.id)

        if identity and user and user.active:
            access_token = _jwt.jwt_encode_callback(identity)
            token = {"token": access_token}
            return token
        else:
            raise JWTError('Bad Request', 'Invalid credentials')
Ejemplo n.º 3
0
    def post(self):
        args = parser.parse_args()
        data = request.get_json(force=True)
        username = args.get('email')
        password = args.get('password')
        criterion = [username, password, len(data) == 2]

        if not all(criterion):
            raise JWTError(
                'Bad Request', 'Missing required credentials', status_code=400
            )

        user = _jwt.authentication_callback(username, password)

        if user:
            token = {
                "token": generate_token(user)
            }
            return token
        else:
            raise JWTError('Bad Request', 'Invalid credentials')
Ejemplo n.º 4
0
    def post(self):
        """Authenticates and generates a token."""
        args = parser.parse_args()
        data = request.get_json(force=True)
        username = args.get('email')
        password = args.get('password')
        criterion = [username, password, len(data) == 2]

        if not all(criterion):
            raise JWTError('Bad Request', 'Invalid credentials')

        identity = _jwt.authentication_callback(username, password)
        if identity is not None:
            user = User.objects.get(id=identity.id)

        if identity and user and user.active:
            access_token = _jwt.jwt_encode_callback(identity)
            token = {
                "token": access_token
            }
            return token
        else:
            raise JWTError('Bad Request', 'Invalid credentials')