如何在卡萨布兰卡 REST API 中检索授权标头

How do you retrieve the authorization header in Casablanca REST API

本文关键字:检索 授权 权标 API 卡萨布兰卡 REST      更新时间:2023-10-16

>我有以下函数来检查授权标头。

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;
}

目前,我已经放置了一个临时令牌仅用于测试,虽然我可以看到如何检查授权标头是否存在 - 目前尚不清楚如何检索该标头的值。

任何人都知道如何使用Casablanca REST API检索标头。

标头可通过调用请求对象的 headers() 函数获得。以下代码将授权标头放在 authHeader 局部变量中。

string_t authHeader;
if (!request.headers().has(header_names::authorization)) return false;
headers = request.headers();
authHeader = headers[header_names::authorization];