-rw-r--r-- | lib/oauth_ext.cc | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/lib/oauth_ext.cc b/lib/oauth_ext.cc new file mode 100644 index 0000000..b728854 --- a/dev/null +++ b/lib/oauth_ext.cc | |||
@@ -0,0 +1,75 @@ | |||
1 | #include <opkele/exception.h> | ||
2 | #include <opkele/oauth_ext.h> | ||
3 | #include <opkele/uris.h> | ||
4 | #include <algorithm> | ||
5 | |||
6 | namespace opkele { | ||
7 | using std::find; | ||
8 | |||
9 | void oauth_ext_t::rp_checkid_hook(basic_openid_message& om) { | ||
10 | |||
11 | string pfx = om.allocate_ns(OIURI_OAUTH10,"oauth"); | ||
12 | //required: openid.oauth.consumer=www.plaxo.com | ||
13 | //optional: openid.oauth.scope=http://www.google.com/m8/feeds/ | ||
14 | if (m_consumer.empty()) throw bad_input(OPKELE_CP_ "Required consumer key is missing from OAuth extension"); | ||
15 | om.set_field(pfx+".consumer", m_consumer); | ||
16 | if (!m_scope.empty()) om.set_field(pfx+".scope", m_scope); | ||
17 | } | ||
18 | |||
19 | void oauth_ext_t::checkid_hook(basic_openid_message& om) { | ||
20 | rp_checkid_hook(om); } | ||
21 | |||
22 | void oauth_ext_t::rp_id_res_hook(const basic_openid_message& om, | ||
23 | const basic_openid_message& sp) { | ||
24 | string pfx; | ||
25 | try { | ||
26 | pfx = om.get_ns(OIURI_OAUTH10); | ||
27 | }catch(failed_lookup&) { | ||
28 | return; | ||
29 | } | ||
30 | pfx += '.'; | ||
31 | //required: openid.oauth.request_token=abcdefg | ||
32 | //optional: openid.oauth.consumer=www.plaxo.com | ||
33 | //optional: openid.oauth.scope=http://www.google.com/m8/feeds/ | ||
34 | string fn; | ||
35 | |||
36 | fn = pfx + "request_token"; | ||
37 | if (sp.has_field(fn)) { | ||
38 | m_request_token = sp.get_field(fn); | ||
39 | } else throw bad_input(OPKELE_CP_ "Missing required response field: "+fn); | ||
40 | |||
41 | fn = pfx + "consumer"; | ||
42 | if (sp.has_field(fn)) { | ||
43 | m_consumer = sp.get_field(fn); | ||
44 | } | ||
45 | |||
46 | fn = pfx + "scope"; | ||
47 | if (sp.has_field(fn)) { | ||
48 | m_scope = sp.get_field(fn); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | void oauth_ext_t::id_res_hook(const basic_openid_message& om, | ||
53 | const basic_openid_message& sp) { | ||
54 | rp_id_res_hook(om,sp); } | ||
55 | |||
56 | void oauth_ext_t::op_checkid_hook(const basic_openid_message& inm) { | ||
57 | } | ||
58 | |||
59 | void oauth_ext_t::op_id_res_hook(basic_openid_message& oum) { | ||
60 | } | ||
61 | |||
62 | void oauth_ext_t::checkid_hook(const basic_openid_message& inm, | ||
63 | basic_openid_message& oum) { | ||
64 | op_checkid_hook(inm); | ||
65 | setup_response(inm,oum); | ||
66 | op_id_res_hook(oum); | ||
67 | } | ||
68 | |||
69 | void oauth_ext_t::setup_response(const basic_openid_message& /* inm */,basic_openid_message& /* oum */) { | ||
70 | setup_response(); | ||
71 | } | ||
72 | void oauth_ext_t::setup_response() { | ||
73 | } | ||
74 | } | ||
75 | |||