void DefaultClientAuthorizationFacade::makeAuthorizationRequestPage(const Grant &grant, const IHttpRequest &request,IHttpResponse &response) const
{
    string msg = DefaultClientAuthorizationFacade::_authzPageBody;

    //HACK: <<CONST>> should be moved to static const; clientId, scope, userId should be moved to <<params>> instead of text
    std::ostringstream ostr;
    ostr << "Client '" << grant.clientId << "' requested access to '" << grant.scope.str() << "' for logged user " << grant.userId;

    msg = std::regex_replace(msg, std::regex("<<Text>>"), ostr.str());
    msg = std::regex_replace(msg, std::regex("<<Action>>"), request.getRequestTarget()); //HACK: We don't need parameters consider using getHost+getPath

    // copy all request parameters to hidden form fields
    ostr.str("");
    ostr.clear();
    map<string,string> params = request.getParams();

    for (map<string,string>::const_iterator it = params.begin(); it != params.end(); ++it)
        ostr << "<input type='hidden' name='" << it->first << "' value='" << it->second << "'>";

    ostr << "<input type='hidden' name='" << _userIdFieldName << "' value='" << grant.userId << "'>";
    ostr << "<input type='hidden' name='" << authorizationFormMarker << "'>";

    msg = std::regex_replace(msg, std::regex("<<HiddenFormValues>>"), ostr.str());
    msg = std::regex_replace(msg, std::regex("<<AcceptFieldName>>"), _acceptedFieldName);

    response.setBody(msg);
};
Exemplo n.º 2
0
void make_error_response(const Errors::Code error, const string &msg, const IHttpRequest &request, IHttpResponse &response)
{
    typedef std::pair<string, string> jsonpair_t;

    response.setStatus(400);
    response.addHeader("Content-type","application/json; charset=utf-8");
    
    std::map<string, string> map;
    map.insert(jsonpair_t(Params::error,Errors::getText(error)));
    map.insert(jsonpair_t(Params::error_description,msg));

    response.setBody(mapToJSON(map));
};