-rw-r--r-- | include/Makefile.am | 4 | ||||
-rw-r--r-- | include/opkele/oauth.h | 22 | ||||
-rw-r--r-- | include/opkele/oauth/consumer.h | 135 | ||||
-rw-r--r-- | include/opkele/types.h | 18 |
4 files changed, 178 insertions, 1 deletions
diff --git a/include/Makefile.am b/include/Makefile.am index f842bb9..2ae510d 100644 --- a/include/Makefile.am +++ b/include/Makefile.am | |||
@@ -11,23 +11,25 @@ nobase_include_HEADERS = \ | |||
11 | opkele/consumer.h \ | 11 | opkele/consumer.h \ |
12 | opkele/extension.h \ | 12 | opkele/extension.h \ |
13 | opkele/sreg.h \ | 13 | opkele/sreg.h \ |
14 | opkele/extension_chain.h \ | 14 | opkele/extension_chain.h \ |
15 | opkele/xconsumer.h \ | 15 | opkele/xconsumer.h \ |
16 | opkele/xserver.h \ | 16 | opkele/xserver.h \ |
17 | opkele/uris.h \ | 17 | opkele/uris.h \ |
18 | opkele/tr1-mem.h \ | 18 | opkele/tr1-mem.h \ |
19 | opkele/basic_rp.h opkele/prequeue_rp.h \ | 19 | opkele/basic_rp.h opkele/prequeue_rp.h \ |
20 | opkele/iterator.h \ | 20 | opkele/iterator.h \ |
21 | opkele/basic_op.h opkele/verify_op.h \ | 21 | opkele/basic_op.h opkele/verify_op.h \ |
22 | opkele/util.h \ | 22 | opkele/util.h \ |
23 | opkele/oauth.h opkele/oauth/consumer.h \ | ||
24 | opkele/curl.h \ | ||
23 | ${NODIST_HEADERS_} | 25 | ${NODIST_HEADERS_} |
24 | 26 | ||
25 | noinst_HEADERS = \ | 27 | noinst_HEADERS = \ |
26 | opkele/data.h \ | 28 | opkele/data.h \ |
27 | opkele/curl.h opkele/expat.h opkele/tidy.h \ | 29 | opkele/expat.h opkele/tidy.h \ |
28 | opkele/util-internal.h \ | 30 | opkele/util-internal.h \ |
29 | opkele/debug.h \ | 31 | opkele/debug.h \ |
30 | opkele/discovery.h | 32 | opkele/discovery.h |
31 | 33 | ||
32 | dist-hook: | 34 | dist-hook: |
33 | rm -f $(addprefix ${distdir}/,${NODIST_HEADERS_}) | 35 | rm -f $(addprefix ${distdir}/,${NODIST_HEADERS_}) |
diff --git a/include/opkele/oauth.h b/include/opkele/oauth.h new file mode 100644 index 0000000..14d0586 --- a/dev/null +++ b/include/opkele/oauth.h | |||
@@ -0,0 +1,22 @@ | |||
1 | #ifndef __OPKELE_OAUTH_H | ||
2 | #define __OPKELE_OAUTH_H | ||
3 | |||
4 | #include <string> | ||
5 | |||
6 | namespace opkele { | ||
7 | namespace oauth { | ||
8 | using std::string; | ||
9 | |||
10 | struct token_t { | ||
11 | string key; | ||
12 | string secret; | ||
13 | |||
14 | token_t() { } | ||
15 | token_t(const string& k,const string& s) | ||
16 | : key(k), secret(s) { } | ||
17 | }; | ||
18 | |||
19 | } | ||
20 | } | ||
21 | |||
22 | #endif /* __OPKELE_OAUTH_H */ | ||
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 | |||
9 | namespace 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 */ | ||
diff --git a/include/opkele/types.h b/include/opkele/types.h index f63bf5d..4471e6a 100644 --- a/include/opkele/types.h +++ b/include/opkele/types.h | |||
@@ -134,24 +134,42 @@ namespace opkele { | |||
134 | virtual const string& get_field(const string& n) const = 0; | 134 | virtual const string& get_field(const string& n) const = 0; |
135 | 135 | ||
136 | virtual fields_iterator fields_begin() const = 0; | 136 | virtual fields_iterator fields_begin() const = 0; |
137 | virtual fields_iterator fields_end() const = 0; | 137 | virtual fields_iterator fields_end() const = 0; |
138 | 138 | ||
139 | virtual string append_query(const string& url,const char *pfx=0) const; | 139 | virtual string append_query(const string& url,const char *pfx=0) const; |
140 | virtual string query_string(const char *pfx=0) const; | 140 | virtual string query_string(const char *pfx=0) const; |
141 | 141 | ||
142 | virtual void reset_fields(); | 142 | virtual void reset_fields(); |
143 | virtual void set_field(const string& n,const string& v); | 143 | virtual void set_field(const string& n,const string& v); |
144 | virtual void reset_field(const string& n); | 144 | virtual void reset_field(const string& n); |
145 | 145 | ||
146 | void from_query(const string& qs); | ||
147 | }; | ||
148 | |||
149 | class fields_t : public basic_fields, public map<string,string> { | ||
150 | public: | ||
151 | fields_t() { } | ||
152 | fields_t(const basic_fields& x) | ||
153 | : basic_fields(x) { } | ||
154 | |||
155 | bool has_field(const string& n) const; | ||
156 | const string& get_field(const string& n) const; | ||
157 | |||
158 | virtual fields_iterator fields_begin() const; | ||
159 | virtual fields_iterator fields_end() const; | ||
160 | |||
161 | virtual void reset_fields(); | ||
162 | virtual void set_field(const string& n,const string& v); | ||
163 | virtual void reset_field(const string& n); | ||
146 | }; | 164 | }; |
147 | 165 | ||
148 | class basic_openid_message : public basic_fields { | 166 | class basic_openid_message : public basic_fields { |
149 | public: | 167 | public: |
150 | 168 | ||
151 | basic_openid_message() { } | 169 | basic_openid_message() { } |
152 | basic_openid_message(const basic_openid_message& x); | 170 | basic_openid_message(const basic_openid_message& x); |
153 | 171 | ||
154 | virtual bool has_ns(const string& uri) const; | 172 | virtual bool has_ns(const string& uri) const; |
155 | virtual string get_ns(const string& uri) const; | 173 | virtual string get_ns(const string& uri) const; |
156 | 174 | ||
157 | virtual string append_query(const string& url,const char *pfx="openid.") const { | 175 | virtual string append_query(const string& url,const char *pfx="openid.") const { |