|
|
|
@@ -1,40 +1,41 @@ |
1 | #include <uuid/uuid.h> |
1 | #include <uuid/uuid.h> |
2 | #include <iostream> |
2 | #include <iostream> |
3 | #include <cassert> |
3 | #include <cassert> |
4 | #include <string> |
4 | #include <string> |
5 | #include <ext/algorithm> |
5 | #include <ext/algorithm> |
6 | using namespace std; |
6 | using namespace std; |
7 | #include <kingate/exception.h> |
7 | #include <kingate/exception.h> |
8 | #include <kingate/plaincgi.h> |
8 | #include <kingate/plaincgi.h> |
9 | #include <kingate/cgi_gateway.h> |
9 | #include <kingate/cgi_gateway.h> |
10 | #include <opkele/exception.h> |
10 | #include <opkele/exception.h> |
11 | #include <opkele/util.h> |
11 | #include <opkele/util.h> |
12 | #include <opkele/uris.h> |
12 | #include <opkele/uris.h> |
13 | #include <opkele/extension.h> |
13 | #include <opkele/extension.h> |
14 | #include <opkele/association.h> |
14 | #include <opkele/association.h> |
15 | #include <opkele/debug.h> |
15 | #include <opkele/debug.h> |
16 | #include <opkele/verify_op.h> |
16 | #include <opkele/verify_op.h> |
| |
17 | #include <opkele/sreg.h> |
17 | |
18 | |
18 | #include "sqlite.h" |
19 | #include "sqlite.h" |
19 | #include "kingate_openid_message.h" |
20 | #include "kingate_openid_message.h" |
20 | |
21 | |
21 | static const string get_self_url(const kingate::cgi_gateway& gw) { |
22 | static const string get_self_url(const kingate::cgi_gateway& gw) { |
22 | bool s = gw.has_meta("SSL_PROTOCOL_VERSION"); |
23 | bool s = gw.has_meta("SSL_PROTOCOL_VERSION"); |
23 | string rv = s?"https://":"http://"; |
24 | string rv = s?"https://":"http://"; |
24 | rv += gw.http_request_header("Host"); |
25 | rv += gw.http_request_header("Host"); |
25 | const string& port = gw.get_meta("SERVER_PORT"); |
26 | const string& port = gw.get_meta("SERVER_PORT"); |
26 | if( port!=(s?"443":"80") ) { |
27 | if( port!=(s?"443":"80") ) { |
27 | rv += ':'; rv += port; |
28 | rv += ':'; rv += port; |
28 | } |
29 | } |
29 | rv += gw.get_meta("REQUEST_URI"); |
30 | rv += gw.get_meta("REQUEST_URI"); |
30 | string::size_type q = rv.find('?'); |
31 | string::size_type q = rv.find('?'); |
31 | if(q!=string::npos) |
32 | if(q!=string::npos) |
32 | rv.erase(q); |
33 | rv.erase(q); |
33 | return rv; |
34 | return rv; |
34 | } |
35 | } |
35 | |
36 | |
36 | class opdb_t : public sqlite3_t { |
37 | class opdb_t : public sqlite3_t { |
37 | public: |
38 | public: |
38 | opdb_t() |
39 | opdb_t() |
39 | : sqlite3_t("/tmp/OP.db") { |
40 | : sqlite3_t("/tmp/OP.db") { |
40 | assert(_D); |
41 | assert(_D); |
@@ -248,60 +249,65 @@ int main(int argc,char *argv[]) { |
248 | if(op=="xrds") { |
249 | if(op=="xrds") { |
249 | cout << |
250 | cout << |
250 | "Content-type: application/xrds+xml\n\n" |
251 | "Content-type: application/xrds+xml\n\n" |
251 | "<?xml version='1.0' encoding='utf-8'?>" |
252 | "<?xml version='1.0' encoding='utf-8'?>" |
252 | "<xrds:XRDS xmlns:xrds='xri://$xrds' xmlns='xri://$xrd*($v*2.0)'>" |
253 | "<xrds:XRDS xmlns:xrds='xri://$xrds' xmlns='xri://$xrd*($v*2.0)'>" |
253 | "<XRD>" |
254 | "<XRD>" |
254 | "<Service>" |
255 | "<Service>" |
255 | "<Type>" STURI_OPENID20 "</Type>" |
256 | "<Type>" STURI_OPENID20 "</Type>" |
256 | "<URI>" << get_self_url(gw) << "</URI>" |
257 | "<URI>" << get_self_url(gw) << "</URI>" |
257 | "</Service>"; |
258 | "</Service>"; |
258 | if(gw.has_param("idsel")){ |
259 | if(gw.has_param("idsel")){ |
259 | cout << |
260 | cout << |
260 | "<Service>" |
261 | "<Service>" |
261 | "<Type>" STURI_OPENID20_OP "</Type>" |
262 | "<Type>" STURI_OPENID20_OP "</Type>" |
262 | "<URI>" << get_self_url(gw) << "</URI>"; |
263 | "<URI>" << get_self_url(gw) << "</URI>"; |
263 | } |
264 | } |
264 | cout << |
265 | cout << |
265 | "</XRD>" |
266 | "</XRD>" |
266 | "</xrds:XRDS>"; |
267 | "</xrds:XRDS>"; |
267 | }else if(op=="id_res" || op=="cancel") { |
268 | }else if(op=="id_res" || op=="cancel") { |
268 | kingate_openid_message_t inm(gw); |
269 | kingate_openid_message_t inm(gw); |
269 | example_op_t OP(gw); |
270 | example_op_t OP(gw); |
270 | if(gw.get_param("hts_id")!=OP.htc.get_value()) |
271 | if(gw.get_param("hts_id")!=OP.htc.get_value()) |
271 | throw opkele::exception(OPKELE_CP_ "toying around, huh?"); |
272 | throw opkele::exception(OPKELE_CP_ "toying around, huh?"); |
272 | OP.checkid_(inm,0); |
273 | opkele::sreg_t sreg; |
| |
274 | OP.checkid_(inm,sreg); |
273 | OP.cookie_header(cout); |
275 | OP.cookie_header(cout); |
274 | opkele::openid_message_t om; |
276 | opkele::openid_message_t om; |
275 | if(op=="id_res") { |
277 | if(op=="id_res") { |
276 | if(!OP.get_authorized()) |
278 | if(!OP.get_authorized()) |
277 | throw opkele::exception(OPKELE_CP_ "not logged in"); |
279 | throw opkele::exception(OPKELE_CP_ "not logged in"); |
278 | if(OP.is_id_select()) { |
280 | if(OP.is_id_select()) { |
279 | OP.select_identity( get_self_url(gw), get_self_url(gw) ); |
281 | OP.select_identity( get_self_url(gw), get_self_url(gw) ); |
280 | } |
282 | } |
| |
283 | sreg.set_field(opkele::sreg_t::field_nickname,"anonymous"); |
| |
284 | sreg.set_field(opkele::sreg_t::field_fullname,"Ann O'Nymus"); |
| |
285 | sreg.set_field(opkele::sreg_t::field_gender,"F"); |
| |
286 | sreg.setup_response(); |
281 | cout << |
287 | cout << |
282 | "Status: 302 Going back to RP with id_res\n" |
288 | "Status: 302 Going back to RP with id_res\n" |
283 | "Location: " << OP.id_res(om).append_query(OP.get_return_to()) |
289 | "Location: " << OP.id_res(om,sreg).append_query(OP.get_return_to()) |
284 | << "\n\n"; |
290 | << "\n\n"; |
285 | }else{ |
291 | }else{ |
286 | cout << |
292 | cout << |
287 | "Status: 302 Going back to RP with cancel\n" |
293 | "Status: 302 Going back to RP with cancel\n" |
288 | "Location: " << OP.cancel(om).append_query(OP.get_return_to()) |
294 | "Location: " << OP.cancel(om).append_query(OP.get_return_to()) |
289 | << "\n\n"; |
295 | << "\n\n"; |
290 | } |
296 | } |
291 | om.to_keyvalues(clog); |
297 | om.to_keyvalues(clog); |
292 | }else if(om=="associate") { |
298 | }else if(om=="associate") { |
293 | kingate_openid_message_t inm(gw); |
299 | kingate_openid_message_t inm(gw); |
294 | opkele::openid_message_t oum; |
300 | opkele::openid_message_t oum; |
295 | example_op_t OP(gw); |
301 | example_op_t OP(gw); |
296 | OP.associate(oum,inm); |
302 | OP.associate(oum,inm); |
297 | cout << "Content-type: text/plain\n\n"; |
303 | cout << "Content-type: text/plain\n\n"; |
298 | oum.to_keyvalues(cout); |
304 | oum.to_keyvalues(cout); |
299 | }else if(om=="checkid_setup") { |
305 | }else if(om=="checkid_setup") { |
300 | kingate_openid_message_t inm(gw); |
306 | kingate_openid_message_t inm(gw); |
301 | example_op_t OP(gw); |
307 | example_op_t OP(gw); |
302 | OP.checkid_(inm,0); |
308 | OP.checkid_(inm,0); |
303 | OP.cookie_header(cout) << |
309 | OP.cookie_header(cout) << |
304 | "Content-type: text/html\n" |
310 | "Content-type: text/html\n" |
305 | "\n" |
311 | "\n" |
306 | |
312 | |
307 | "<html>" |
313 | "<html>" |
|