Google APIs Client Library for C++
http_authorization.h
Go to the documentation of this file.
00001 /*
00002  * \copyright Copyright 2013 Google Inc. All Rights Reserved.
00003  * \license @{
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  *
00017  * @}
00018  */
00019 
00020 
00021 #ifndef APISERVING_CLIENTS_CPP_TRANSPORT_HTTP_AUTHORIZATION_H_
00022 #define APISERVING_CLIENTS_CPP_TRANSPORT_HTTP_AUTHORIZATION_H_
00023 
00024 #include <string>
00025 using std::string;
00026 
00027 #include "googleapis/base/macros.h"
00028 #include "googleapis/base/scoped_ptr.h"
00029 #include "googleapis/strings/stringpiece.h"
00030 #include "googleapis/util/status.h"
00031 namespace googleapis {
00032 
00033 namespace client {
00034 
00035 class DataReader;
00036 class HttpRequest;
00037 
00038 /*
00039  * The abstraction used to pass credentials also contains knowledge about how
00040  * to use the credentials to authorize requests.
00041  * @ingroup TransportLayerCore
00042  *
00043  * In practice this is probably an OAuth2Credential, but this class provides
00044  * an abstract interface sufficient to keep OAuth 2.0 depedencies out of the
00045  * HTTP transport layer and core libraries that dont care about the mechanism
00046  * details.
00047  */
00048 class AuthorizationCredential {
00049  public:
00050   /*
00051    * Standard destructor.
00052    */
00053   virtual ~AuthorizationCredential();
00054 
00055   /*
00056    * Returns the type of credential for tracing/debug purposes.
00057    */
00058   virtual const StringPiece type() const = 0;
00059 
00060   /*
00061    * Refreshes credential.
00062    *
00063    * @return ok or reason for failure.
00064    */
00065   virtual util::Status Refresh() = 0;
00066 
00067   /*
00068    * Initialize the credential from a stream.
00069    *
00070    * @param[in] serialized_credential A serialized credential stream to
00071    *            load from.
00072    *
00073    * @see MakeDataReader
00074    */
00075   virtual util::Status Load(DataReader* serialized_credential) = 0;
00076 
00077   /*
00078    * Creates a DataReader stream serializing the credential.
00079    *
00080    * @return serialized stream suitable for Load.
00081    */
00082   virtual DataReader* MakeDataReader() const = 0;
00083 
00084   /*
00085    * Uses the credential to authorize a request.
00086    *
00087    * @param[in,out] request The request to authorized will be modified as
00088    *                needed depending on the specific class (e.g. adding an
00089    *                authoriation header).
00090    * @return failure if the request cannot be authorized. A success does
00091    *         not guarantee that the server will accept the authorization
00092    *         but a failure guarantees that it will not.
00093    */
00094   virtual util::Status AuthorizeRequest(HttpRequest* request) = 0;
00095 };
00096 
00097 }  // namespace client
00098 
00099 } // namespace googleapis
00100 #endif  // APISERVING_CLIENTS_CPP_TRANSPORT_HTTP_AUTHORIZATION_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines