PageRenderTime 72ms CodeModel.GetById 40ms app.highlight 10ms RepoModel.GetById 20ms app.codeStats 0ms

/mordor/http/oauth.h

http://github.com/mozy/mordor
C Header | 88 lines | 68 code | 16 blank | 4 comment | 0 complexity | 838d754c239806cbf53aaa05f4d4a18e MD5 | raw file
 1#ifndef __MORDOR_HTTP_OAUTH_H__
 2#define __MORDOR_HTTP_OAUTH_H__
 3// Copyright (c) 2009 - Mozy, Inc.
 4
 5#include <boost/function.hpp>
 6
 7#include "broker.h"
 8
 9namespace Mordor {
10namespace HTTP {
11namespace OAuth {
12
13std::pair<std::string, std::string>
14getTemporaryCredentials(RequestBroker::ptr requestBroker, const URI &uri,
15    const std::string &method, const std::string &signatureMethod,
16    const std::pair<std::string, std::string> &clientCredentials,
17    const URI &callbackUri = URI());
18
19std::pair<std::string, std::string>
20getTokenCredentials(RequestBroker::ptr requestBroker, const URI &uri,
21    const std::string &method, const std::string &signatureMethod,
22    const std::pair<std::string, std::string> &clientCredentials,
23    const std::pair<std::string, std::string> &temporaryCredentials,
24    const std::string &verifier);
25
26void authorize(Request &nextRequest,
27    const std::string &signatureMethod,
28    const std::pair<std::string, std::string> &clientCredentials,
29    const std::pair<std::string, std::string> &tokenCredentials,
30    const std::string &realm = std::string(),
31    const std::string &scheme = std::string());
32
33// Helpers for setting up an OAuth request
34template <class T>
35void nonceAndTimestamp(T &oauthParameters);
36
37// oauthParameters should *not* be empty; instead if oauth params are in the
38// POST body or in the querystring, those fields should be empty instead
39template <class T>
40std::string generateSignature(const URI &uri, const std::string &method,
41    const std::string &clientSecret, const std::string &tokenSecret,
42    const T &oauthParameters,
43    const URI::QueryString &postParameters = URI::QueryString());
44
45template <class T>
46void sign(const URI &uri, const std::string &method,
47    const std::string &signatureMethod, const std::string &clientSecret,
48    const std::string &tokenSecret, T &oauthParameters,
49    const URI::QueryString &postParameters = URI::QueryString());
50
51template <class T>
52bool validate(const URI &uri, const std::string &method,
53    const std::string &clientSecret, const std::string &tokenSecret,
54    const T &oauthParameters,
55    const URI::QueryString &postParameters = URI::QueryString());
56
57std::pair<std::string, std::string>
58extractCredentials(boost::shared_ptr<ClientRequest> request);
59
60class RequestBroker : public RequestBrokerFilter
61{
62public:
63    RequestBroker(HTTP::RequestBroker::ptr parent,
64        boost::function<bool (const URI &,
65            boost::shared_ptr<ClientRequest> /* priorRequest = ClientRequest::ptr() */,
66            std::string & /* signatureMethod */,
67            std::pair<std::string, std::string> & /* clientCredentials */,
68            std::pair<std::string, std::string> & /* tokenCredentials */,
69            std::string & /* realm */,
70            size_t /* attempts */)> getCredentialsDg)
71        : RequestBrokerFilter(parent),
72          m_getCredentialsDg(getCredentialsDg)
73    {}
74
75    boost::shared_ptr<ClientRequest> request(Request &requestHeaders,
76        bool forceNewConnection = false,
77        boost::function<void (boost::shared_ptr<ClientRequest>)> bodyDg = NULL);
78
79private:
80    boost::function<bool (const URI &, boost::shared_ptr<ClientRequest>, std::string &,
81        std::pair<std::string, std::string> &,
82        std::pair<std::string, std::string> &,
83        std::string &, size_t)> m_getCredentialsDg;
84};
85
86}}}
87
88#endif