How do you retrieve the authorization header in Casablanca REST API

1.7k Views Asked by At

I have the following function to check the authorization header.

bool is_authorized(http_request request)
{
    bool isAuthorized = false;
    int bitmask;
    int maskResult;
    ApplicationAuthorization returned_auth;
    ApplicationAuthorizations authorizations;
    char authHeader[255];

    if (!request.headers().has(header_names::authorization)) return false;



    returned_auth = authorizations.GetAuthorization(to_string_t("token {368EB89B-8A5E-5CF3-07AB-C16961D1A392}"));

    bitmask         = 1 << DATAENGINE;
    maskResult      = (returned_auth.GetApplicationId() & bitmask);

    isAuthorized     = maskResult;

    return isAuthorized;
}

At the moment I have put in a temporary token just for testing and while I can see how to check if the Authorization header is present - it is not clear how to retrieve the value of that header.

Anyone got an idea how using the Casablanca REST API you can retrieve the header.

1

There are 1 best solutions below

0
On BEST ANSWER

The headers are available by calling the headers() function of the request object. The following code puts the authorization header in the authHeader local variable.

string_t authHeader;

if (!request.headers().has(header_names::authorization)) return false;

headers = request.headers();
authHeader = headers[header_names::authorization];