mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
added OAuth20Credentials class, some minor OAuth10Credentials fixes
This commit is contained in:
@@ -102,12 +102,12 @@ public:
|
||||
/// Creates an empty OAuth10Credentials object.
|
||||
|
||||
OAuth10Credentials(const std::string& consumerKey, const std::string& consumerSecret);
|
||||
/// Creates an HTTPCredentials object with the given consumer key and consumer secret.
|
||||
/// Creates an OAuth10Credentials object with the given consumer key and consumer secret.
|
||||
///
|
||||
/// The token and tokenSecret will be left empty.
|
||||
|
||||
OAuth10Credentials(const std::string& consumerKey, const std::string& consumerSecret, const std::string& token, const std::string& tokenSecret);
|
||||
/// Creates an HTTPCredentials object with the given consumer key and
|
||||
/// Creates an OAuth10Credentials object with the given consumer key and
|
||||
/// consumer secret, as well as token and token secret.
|
||||
|
||||
explicit OAuth10Credentials(const HTTPRequest& request);
|
||||
@@ -119,7 +119,7 @@ public:
|
||||
/// not contain OAuth 1.0 credentials.
|
||||
|
||||
~OAuth10Credentials();
|
||||
/// Destroys the HTTPCredentials.
|
||||
/// Destroys the OAuth10Credentials.
|
||||
|
||||
void setConsumerKey(const std::string& consumerKey);
|
||||
/// Sets the consumer key.
|
||||
@@ -195,6 +195,8 @@ public:
|
||||
/// computed by createNonce() and the timestamp is taken
|
||||
/// from the system time.
|
||||
|
||||
static const std::string SCHEME;
|
||||
|
||||
protected:
|
||||
void signPlaintext(Poco::Net::HTTPRequest& request) const;
|
||||
/// Signs the given HTTP request according to OAuth 1.0A PLAINTEXT signature method.
|
||||
|
||||
121
Net/include/Poco/Net/OAuth20Credentials.h
Normal file
121
Net/include/Poco/Net/OAuth20Credentials.h
Normal file
@@ -0,0 +1,121 @@
|
||||
//
|
||||
// OAuth20Credentials.h
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Library: Net
|
||||
// Package: OAuth
|
||||
// Module: OAuth20Credentials
|
||||
//
|
||||
// Definition of the OAuth20Credentials class.
|
||||
//
|
||||
// Copyright (c) 2014, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Net_OAuth20Credentials_INCLUDED
|
||||
#define Net_OAuth20Credentials_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
|
||||
class HTTPRequest;
|
||||
|
||||
|
||||
class Net_API OAuth20Credentials
|
||||
/// This class implements OAuth 2.0 authentication for HTTP requests,
|
||||
/// via Bearer tokens in the Authorization header,
|
||||
/// according to RFC 6749 and RFC 6750.
|
||||
{
|
||||
public:
|
||||
OAuth20Credentials();
|
||||
/// Creates an empty OAuth20Credentials object.
|
||||
|
||||
explicit OAuth20Credentials(const std::string& bearerToken);
|
||||
/// Creates an OAuth20Credentials object with the given bearer token.
|
||||
|
||||
OAuth20Credentials(const std::string& bearerToken, const std::string& scheme);
|
||||
/// Creates an OAuth20Credentials object with the given bearer token
|
||||
/// and authorization scheme, which overrides the default scheme ("Bearer").
|
||||
///
|
||||
/// This is useful for services like GitHub, which use "token" as scheme.
|
||||
|
||||
explicit OAuth20Credentials(const HTTPRequest& request);
|
||||
/// Creates an OAuth20Credentials object from a HTTPRequest object.
|
||||
///
|
||||
/// Extracts bearer token from the Authorization header, which
|
||||
/// must use the "Bearer" authorization scheme.
|
||||
///
|
||||
/// Throws a NotAuthenticatedException if the request does
|
||||
/// not contain a bearer token in the Authorization header.
|
||||
|
||||
OAuth20Credentials(const HTTPRequest& request, const std::string& scheme);
|
||||
/// Creates an OAuth20Credentials object from a HTTPRequest object.
|
||||
///
|
||||
/// Extracts bearer token from the Authorization header, which must
|
||||
/// use the given authorization scheme.
|
||||
///
|
||||
/// Throws a NotAuthenticatedException if the request does
|
||||
/// not contain a bearer token in the Authorization header.
|
||||
|
||||
~OAuth20Credentials();
|
||||
/// Destroys the HTTPCredentials.
|
||||
|
||||
void setBearerToken(const std::string& bearerToken);
|
||||
/// Sets the bearer token.
|
||||
|
||||
const std::string& getBearerToken() const;
|
||||
/// Returns the bearer token.
|
||||
|
||||
void setScheme(const std::string& scheme);
|
||||
/// Sets the Authorization header scheme.
|
||||
|
||||
const std::string& getScheme() const;
|
||||
/// Returns the Authorization header scheme.
|
||||
|
||||
void authenticate(HTTPRequest& request);
|
||||
/// Adds an Authorization header containing the bearer token to
|
||||
/// the HTTPRequest.
|
||||
|
||||
static const std::string SCHEME;
|
||||
|
||||
protected:
|
||||
void extractBearerToken(const HTTPRequest& request);
|
||||
/// Extracts the bearer token from the HTTPRequest.
|
||||
|
||||
private:
|
||||
OAuth20Credentials(const OAuth20Credentials&);
|
||||
OAuth20Credentials& operator = (const OAuth20Credentials&);
|
||||
|
||||
std::string _bearerToken;
|
||||
std::string _scheme;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline const std::string& OAuth20Credentials::getBearerToken() const
|
||||
{
|
||||
return _bearerToken;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& OAuth20Credentials::getScheme() const
|
||||
{
|
||||
return _scheme;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
|
||||
#endif // Net_OAuth20Credentials_INCLUDED
|
||||
Reference in New Issue
Block a user