summaryrefslogtreecommitdiffabout
path: root/include/opkele/oauth/consumer.h
Unidiff
Diffstat (limited to 'include/opkele/oauth/consumer.h') (more/less context) (show whitespace changes)
-rw-r--r--include/opkele/oauth/consumer.h135
1 files changed, 135 insertions, 0 deletions
diff --git a/include/opkele/oauth/consumer.h b/include/opkele/oauth/consumer.h
new file mode 100644
index 0000000..eb4f753
--- a/dev/null
+++ b/include/opkele/oauth/consumer.h
@@ -0,0 +1,135 @@
1#ifndef __OPKELE_OAUTH_CONSUMER_H
2#define __OPKELE_OAUTH_CONSUMER_H
3
4#include <string>
5#include <opkele/types.h>
6#include <opkele/oauth.h>
7#include <opkele/curl.h>
8
9namespace opkele {
10 namespace oauth {
11 using std::string;
12
13 enum oauth_method_t {
14 oauth_auth_header, oauth_post_body, oauth_url_query,
15 oauth_method_default = oauth_auth_header
16 };
17
18 struct service_endpoint_t {
19 string url;
20 string signature_method;
21 oauth_method_t oauth_method;
22
23 service_endpoint_t() : oauth_method(oauth_method_default) { }
24 service_endpoint_t(const string& u,const string& sm,oauth_method_t om=oauth_method_default)
25 : url(u), signature_method(sm), oauth_method(om) { }
26 };
27
28 class basic_provider_endpoints {
29 public:
30
31 virtual ~basic_provider_endpoints() { }
32
33 virtual const service_endpoint_t& get_request_token_endpoint() const = 0;
34 virtual const service_endpoint_t& get_authorize_user_endpoint() const = 0;
35 virtual const service_endpoint_t& get_access_token_endpoint() const = 0;
36
37 virtual service_endpoint_t& get_url_endpoint(service_endpoint_t& sep,
38 const string& url) const = 0;
39 };
40
41 struct http_request_t {
42 string authorize_header;
43 string method;
44 string url;
45 string body;
46
47 util::curl_slist_t _curl_headers_list;
48
49 http_request_t(const string& m,const string& u)
50 : method(m), url(u) { }
51
52 void setup_curl(CURL *curl);
53 };
54
55 class basic_consumer {
56 public:
57 token_t consumer_token;
58
59 basic_consumer(const token_t& ct)
60 : consumer_token(ct) { }
61 virtual ~basic_consumer() { }
62
63 virtual const basic_provider_endpoints& get_endpoints() const = 0;
64 virtual const string allocate_nonce(time_t ts) = 0;
65
66 token_t get_request_token();
67 const string get_authorize_url(const token_t& rt,const string& callback="");
68 token_t get_access_token(const token_t& rt);
69
70 http_request_t& prepare_request(
71 http_request_t& req,
72 const basic_fields& qf,const basic_fields& pf,
73 oauth_method_t om,const string& sm,
74 const token_t *t=0,const string& realm="");
75 http_request_t& prepare_request(
76 http_request_t& req,
77 const basic_fields& qf,const basic_fields& pf,
78 const service_endpoint_t& sep,
79 const token_t *t=0,const string& realm="");
80 http_request_t& prepare_request(
81 http_request_t& req,
82 const basic_fields& qf,const basic_fields& pf,
83 const token_t *t=0,const string& realm="");
84
85 const string signature(
86 const string& method,
87 const string& url,
88 const basic_fields& fields,
89 const token_t* rt=0);
90
91 token_t acquire_token(
92 const service_endpoint_t& sep,
93 const token_t* rt=0);
94 };
95
96 class simple_provider_endpoints : public basic_provider_endpoints {
97 public:
98 service_endpoint_t sep_request_token;
99 service_endpoint_t sep_authorize_user;
100 service_endpoint_t sep_access_token;
101 service_endpoint_t sep_generic;
102
103 simple_provider_endpoints(
104 const string& rt,const string& au,const string& at,
105 const string& sm,
106 oauth_method_t ams=oauth_post_body,
107 oauth_method_t amr=oauth_auth_header )
108 : sep_request_token(rt,sm,ams),
109 sep_authorize_user(au,sm,oauth_url_query),
110 sep_access_token(at,sm,ams),
111 sep_generic("",sm,amr) { }
112
113 const service_endpoint_t& get_request_token_endpoint() const;
114 const service_endpoint_t& get_authorize_user_endpoint() const;
115 const service_endpoint_t& get_access_token_endpoint() const;
116 service_endpoint_t& get_url_endpoint(service_endpoint_t& sep,
117 const string& url) const;
118 };
119
120 class simple_consumer : public basic_consumer {
121 public:
122 simple_provider_endpoints peps;
123
124 simple_consumer(const simple_provider_endpoints& eps,
125 const token_t& ct)
126 : basic_consumer(ct), peps(eps) { }
127
128 const basic_provider_endpoints& get_endpoints() const;
129 const string allocate_nonce(time_t ts);
130 };
131
132 }
133}
134
135#endif /* __OPKELE_OAUTH_CONSUMER_H */