void OAuth20Credentials::extractBearerToken(const HTTPRequest& request)
{
    if (request.hasCredentials())
    {
        std::string authScheme;
        std::string authInfo;
        request.getCredentials(authScheme, authInfo);
        if (icompare(authScheme, _scheme) == 0)
        {
            _bearerToken = authInfo;
        }
        else throw NotAuthenticatedException("No bearer token in Authorization header", authScheme);
    }
    else throw NotAuthenticatedException("No Authorization header found");
}
HTTPBasicCredentials::HTTPBasicCredentials(const HTTPRequest& request)
{
	static const int eof = std::char_traits<char>::eof();

	std::string scheme;
	std::string info;
	request.getCredentials(scheme, info);
	if (icompare(scheme, SCHEME) == 0)
	{
		std::istringstream istr(info);
		Base64Decoder decoder(istr);
		int ch = decoder.get();
		while (ch != eof && ch != ':')
		{
			_username += (char) ch;
			ch = decoder.get();
		}
		if (ch == ':') ch = decoder.get();
		while (ch != eof)
		{
			_password += (char) ch;
			ch = decoder.get();
		}
	}
	else throw NotAuthenticatedException("Basic authentication expected");
}
示例#3
0
void HTTPRequest::getCredentials(const std::string& header, std::string& scheme, std::string& authInfo) const
{
	scheme.clear();
	authInfo.clear();
	if (has(header))
	{
		const std::string& auth = get(header);
		std::string::const_iterator it  = auth.begin();
		std::string::const_iterator end = auth.end();
		while (it != end && Poco::Ascii::isSpace(*it)) ++it;
		while (it != end && !Poco::Ascii::isSpace(*it)) scheme += *it++;
		while (it != end && Poco::Ascii::isSpace(*it)) ++it;
		while (it != end) authInfo += *it++;
	}
	else throw NotAuthenticatedException();
}