예제 #1
0
def authenticate(user=None):  # noqa: E501
    """Authenticate

    Authenticate with the API # noqa: E501

    :param user: The user authentication object.
    :type user: dict | bytes

    :rtype: UserAuth
    """
    if connexion.request.is_json:
        user = UserAuth.from_dict(connexion.request.get_json())  # noqa: E501

    credentials = mapUserAuthToCredentials(user)
    auth = ApitaxAuthentication.login(credentials)
    if (not auth):
        return ErrorResponse(status=401, message="Invalid credentials")

    access_token = create_access_token(identity={
        'username': user.username,
        'role': auth['role']
    })
    refresh_token = create_refresh_token(identity={
        'username': user.username,
        'role': auth['role']
    })

    return AuthResponse(status=201,
                        message='User ' + user.username +
                        ' was authenticated as ' + auth['role'],
                        access_token=access_token,
                        refresh_token=refresh_token,
                        auth=UserAuth(username=auth['credentials'].username,
                                      api_token=auth['credentials'].token))
예제 #2
0
    def test_authenticate(self):
        """Test case for authenticate

        Authenticate
        """
        user = UserAuth()
        response = self.client.open('/apitax/2/auth',
                                    method='POST',
                                    data=json.dumps(user),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
예제 #3
0
    def test_endpoint_catalog(self):
        """Test case for endpoint_catalog

        Retrieve the endpoint catalog
        """
        catalog = UserAuth()
        response = self.client.open(
            '/apitax/2/system/endpoint/catalog',
            method='GET',
            data=json.dumps(catalog),
            content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
예제 #4
0
def authenticate(user=None):  # noqa: E501
    """Authenticate

    Authenticate with the API # noqa: E501

    :param user: The user authentication object.
    :type user: dict | bytes

    :rtype: AuthResponse
    """
    if connexion.request.is_json:
        user = UserAuth.from_dict(connexion.request.get_json())  # noqa: E501
    return 'do some magic!'
예제 #5
0
def endpoint_catalog(catalog=None):  # noqa: E501
    """Retrieve the endpoint catalog

    Retrieve the endpoint catalog # noqa: E501

    :param catalog: The data needed to get a catalog
    :type catalog: dict | bytes

    :rtype: Response
    """
    if connexion.request.is_json:
        catalog = UserAuth.from_dict(connexion.request.get_json())  # noqa: E501
    return 'do some magic!'
예제 #6
0
def refresh_token():  # noqa: E501
    """Refreshes login token using refresh token

    Refreshes login token using refresh token # noqa: E501


    :rtype: UserAuth
    """
    current_user = get_jwt_identity()
    if (not current_user):
        return ErrorResponse(status=401, message="Not logged in")
    access_token = create_access_token(identity=current_user)
    return AuthResponse(status=201,
                        message='Refreshed Access Token',
                        access_token=access_token,
                        auth=UserAuth())
예제 #7
0
def endpoint_catalog(catalog=None):  # noqa: E501
    """Retrieve the endpoint catalog

    Retrieve the endpoint catalog # noqa: E501

    :param catalog: The data needed to get a catalog
    :type catalog: dict | bytes

    :rtype: Response
    """
    if connexion.request.is_json:
        catalog = UserAuth.from_dict(
            connexion.request.get_json())  # noqa: E501

    if (not hasAccess()):
        return redirectUnauthorized()

    driver = LoadedDrivers.getDefaultDriver()
    auth = None
    if (catalog):
        auth = catalog
    return Response(status=200, body=driver.getCatalog(auth))