More work on OpenID 1.1 support
authorArt Cancro <ajc@citadel.org>
Thu, 22 May 2008 16:45:07 +0000 (16:45 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 22 May 2008 16:45:07 +0000 (16:45 +0000)
citadel/modules/openid/serv_openid_rp.c
webcit/auth.c
webcit/webcit.c
webcit/webcit.h

index f12dddfd18ff9947b1c23915dc56db7c96243376..9727a08a5fd3ecc8d1b2bb2bf94ecdc4b23165fa 100644 (file)
@@ -177,12 +177,7 @@ int fetch_http(char *url, char *target_buf, int maxbytes)
        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;
 }
@@ -208,6 +203,15 @@ size_t associate_callback(void *ptr, size_t size, size_t nmemb, void *stream)
 }
 
 
+/*
+ * 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
  */
@@ -242,9 +246,10 @@ struct associate_handle *process_associate_response(char *claimed_id, char *asso
 
        } 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;
 }
@@ -305,9 +310,9 @@ struct associate_handle *prepare_openid_associate_request(
 
 
 /*
- * 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];
@@ -380,6 +385,7 @@ void cmd_oid1(char *argbuf) {
                        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;
        }
@@ -389,13 +395,37 @@ void cmd_oid1(char *argbuf) {
 
 
 
+/*
+ * 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 */
index 94abedfbeead97d3fbc9817c78fdc106cd4706f0..eb18ed39b4907cd66783a94acd1c2798809f9931 100644 (file)
@@ -278,7 +278,7 @@ void do_openid_login(void)
        }
        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
@@ -305,13 +305,30 @@ void do_openid_login(void)
  * 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;
 
                }
        }
index 258bdce1507f330a6c013dffe2c6591011e2de5c..1ca47ad9e116b73d885496cf847e866c08cff766 100644 (file)
@@ -1720,8 +1720,8 @@ void session_loop(struct httprequest *req)
                display_openid_login(NULL);
        } else if ((!WC->logged_in) && (!strcasecmp(action, "openid_login"))) {
                do_openid_login();
-       } else if ((!WC->logged_in) && (!strcasecmp(action, "finish_openid_login"))) {
-               finish_openid_login();
+       } else if ((!WC->logged_in) && (!strcasecmp(action, "finalize_openid_login"))) {
+               finalize_openid_login();
        } else if (!WC->logged_in) {
                display_login(NULL);
        }
index d1fc1b1884b9aac04ac206a6ad44f7318bab622c..5f2551484fce433e2bff8bc196fbba61dfc5da53 100644 (file)
@@ -485,7 +485,7 @@ void locate_host(char *, int);
 void become_logged_in(char *, char *, char *);
 void do_login(void);
 void do_openid_login(void);
-void finish_openid_login(void);
+void finalize_openid_login(void);
 void display_login(char *mesg);
 void display_openid_login(char *mesg);
 void do_welcome(void);