curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fh_callback);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
-
res = curl_easy_perform(curl);
- if (res) {
- CtdlLogPrintf(CTDL_ALERT, "libcurl error %d: %s\n", res, errmsg);
- }
-
curl_easy_cleanup(curl);
return fh.total_bytes_received;
}
}
+/*
+ * Helper function for process_associate_response()
+ * (Delete function for hash table)
+ */
+void delete_assoc_handle(void *data) {
+ if (data) free(data);
+}
+
+
/*
* Process the response from an "associate" request
*/
} while (*ptr);
- // FIXME add this data structure into a hash table
+ /* Add this data structure into the hash table */
+ Put(HL, h->assoc_handle, strlen(h->assoc_handle), h, delete_assoc_handle);
- // FIXME periodically purge the hash table of expired handles
+ /* FIXME periodically purge the hash table of expired handles */
return h;
}
/*
- * Begin the first portion of an OpenID checkid_setup operation.
+ * Setup an OpenID authentication
*/
-void cmd_oid1(char *argbuf) {
+void cmd_oids(char *argbuf) {
char openid_url[1024];
char return_to[1024];
char trust_root[1024];
escaped_trust_root,
escaped_sreg_optional
);
+ CtdlLogPrintf(CTDL_DEBUG, "Telling client about assoc_handle <%s>\n", h->assoc_handle);
cprintf("%d %s\n", CIT_OK, redirect_string);
return;
}
+/*
+ * Finalize an OpenID authentication
+ */
+void cmd_oidf(char *argbuf) {
+ char assoc_handle[256];
+ struct associate_handle *h = NULL;
+
+ extract_token(assoc_handle, argbuf, 0, '|', sizeof assoc_handle);
+
+ if (GetHash(HL, assoc_handle, strlen(assoc_handle), (void *)&h)) {
+ cprintf("%d handle %s is good\n", CIT_OK, assoc_handle);
+
+ // FIXME now do something with it
+
+ }
+ else {
+ cprintf("%d handle %s not found\n", ERROR, assoc_handle);
+ }
+}
+
+
+
+
CTDL_MODULE_INIT(openid_rp)
{
if (!threading)
{
curl_global_init(CURL_GLOBAL_ALL);
HL = NewHash(1, NULL);
- CtdlRegisterProtoHook(cmd_oid1, "OID1", "Begin OpenID checkid_setup operation");
+ CtdlRegisterProtoHook(cmd_oids, "OIDS", "Setup OpenID authentication");
+ CtdlRegisterProtoHook(cmd_oidf, "OIDF", "Finalize OpenID authentication");
}
/* return our Subversion id for the Log */
}
if (havebstr("login_action")) {
snprintf(buf, sizeof buf,
- "OID1 %s|%s://%s/finish_openid_login|%s://%s",
+ "OIDS %s|%s://%s/finalize_openid_login|%s://%s",
bstr("openid_url"),
(is_https ? "https" : "http"), WC->http_host,
(is_https ? "https" : "http"), WC->http_host
* Complete the authentication using OpenID
* This function handles the positive or negative assertion from the user's Identity Provider
*/
-void finish_openid_login(void)
+void finalize_openid_login(void)
{
+ char buf[1024];
+
if (havebstr("openid.mode")) {
if (!strcasecmp(bstr("openid.mode"), "id_res")) {
- display_openid_login("FIXME id accepted but the code isn't finished");
- //FIXME finish this
+// openid.mode = [6] id_res
+// openid.identity = [50] http://uncensored.citadel.org/~ajc/MyID.config.php
+// openid.assoc_handle = [26] 6ekac3ju181tgepk7v4h9r7ui7
+// openid.return_to = [42] http://jemcaterers.net/finish_openid_login
+// openid.sreg.nickname = [17] IGnatius T Foobar
+// openid.sreg.email = [26] ajc@uncensored.citadel.org
+// openid.sreg.fullname = [10] Art Cancro
+// openid.sreg.postcode = [5] 10549
+// openid.sreg.country = [2] US
+// openid.signed = [102] mode,identity,assoc_handle,return_to,sreg.nickname,sreg.email,sreg.fullname,sreg.postcode,sreg.country
+// openid.sig = [28] vixxxU4MAqWfxxxxCfrHv3TxxxhEw=
+
+ // FIXME id accepted but the code isn't finished
+ serv_printf("OIDF %s", bstr("openid.assoc_handle"));
+ serv_getln(buf, sizeof buf);
+ display_openid_login(buf);
+ return;
}
}