Exemple #1
0
void HTTPCredentialsTest::testBasicCredentials()
{
	HTTPRequest request;
	assert (!request.hasCredentials());
	
	HTTPBasicCredentials cred("user", "secret");
	cred.authenticate(request);
	assert (request.hasCredentials());
	std::string scheme;
	std::string info;
	request.getCredentials(scheme, info);
	assert (scheme == "Basic");
	assert (info == "dXNlcjpzZWNyZXQ=");
	
	HTTPBasicCredentials cred2(request);
	assert (cred2.getUsername() == "user");
	assert (cred2.getPassword() == "secret");
}
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");
}