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