authentication problems with couchdb-glib

6 views
Skip to first unread message

Sam Thursfield

unread,
Feb 19, 2010, 9:59:07 PM2/19/10
to Desktop CouchDB
Hi mailing list!
I've been toying with desktopcouch today, it's been fun, but I cannot
get my head around actually inserting records into it, and a couple of
hours googling hasn't really turned up anything helpful

I have the following program, which is I think the shortest possible
really to demonstrate the problem:

#include <gnome-keyring.h>
#include <desktopcouch-glib.h>

#include <config.h>
#include <stdlib.h>

static DesktopcouchSession *dc = NULL;

int main (int argc, char *argv[]) {
g_type_init ();
g_thread_init (NULL);

g_set_application_name ("my-test");

dc = desktopcouch_session_new ();

GError *null_error = NULL;
CouchdbDatabaseInfo *info = couchdb_session_get_database_info
(COUCHDB_SESSION(dc), "my-test",

&null_error);

if (info == NULL) {
/* Database not found, create it */
GError *error = NULL;
gboolean result = couchdb_session_create_database
(COUCHDB_SESSION(dc), "my-test",
&error);
if (!result) {
g_print ("Error creating 'my-test' database in desktopcouch: %s",
error->message);
exit (1);
}
}

GnomeKeyringAttributeList *keyring_attr_list =
gnome_keyring_attribute_list_new ();
gnome_keyring_attribute_list_append_string (keyring_attr_list,
"desktopcouch", "oauth");

GnomeKeyringResult key_result;
GList *found = NULL;
key_result = gnome_keyring_find_items_sync
(GNOME_KEYRING_ITEM_GENERIC_SECRET,
keyring_attr_list, &found);
if (key_result != GNOME_KEYRING_RESULT_OK || found == NULL) {
g_print ("Error reading from keyring.\n");
exit (1);
}

GnomeKeyringFound *item = found->data;
char **oauth = g_strsplit (item->secret, ":", 4);

g_print ("Secret is: %s\n", item->secret);

CouchdbCredentials *credentials;
credentials = couchdb_credentials_new_with_oauth (oauth[0], oauth[1],
oauth[2], oauth[3]);

couchdb_session_enable_authentication (COUCHDB_SESSION (dc),
credentials);

gnome_keyring_found_list_free (found);

CouchdbDocument *doc = couchdb_document_new (COUCHDB_SESSION (dc));

couchdb_document_set_id (doc, "Test 1");
couchdb_document_set_string_field (doc, "foo", "Baaaaaaaaaa");

GError *error = NULL;
gboolean result = couchdb_document_put (doc, "my-test", &error);
g_assert_no_error (error);

g_object_unref (doc);

g_object_unref (dc);
}

I get the following output (after a couple of keyring prompts)

Secret is: ohYCEOAkIG:yQUtpMZpzr:nGUCMkecuX:TxZJPaRldd
**
ERROR:../src/main.c:75:main: assertion failed (error == NULL):
Unauthorized (couchdb_glib, 401)


Am I missing something really obvious here?
Thanks for any help!
sam

Reply all
Reply to author
Forward
0 new messages