summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2011-05-25 14:17:20 -0400
committerDavid Zeuthen <davidz@redhat.com>2011-05-25 14:17:20 -0400
commite5fb8e27bfc9dc70a132715e04823cdb563c65d9 (patch)
tree317f9304a5d1834b8555528f6906074a6850a170
parent0edfb2da8f0d221d718990899cb3b727caa83ffc (diff)
Introduce generation concept for credentials
This is needed to sanely handling added scopes in the future. Signed-off-by: David Zeuthen <davidz@redhat.com>
-rw-r--r--doc/goa-sections.txt1
-rw-r--r--src/goabackend/goaprovider.c42
-rw-r--r--src/goabackend/goaprovider.h4
3 files changed, 45 insertions, 2 deletions
diff --git a/doc/goa-sections.txt b/doc/goa-sections.txt
index f8a50f5..c253157 100644
--- a/doc/goa-sections.txt
+++ b/doc/goa-sections.txt
@@ -546,6 +546,7 @@ goa_provider_lookup_credentials_sync
goa_provider_ensure_credentials
goa_provider_ensure_credentials_finish
goa_provider_ensure_credentials_sync
+goa_provider_get_credentials_generation
GOA_PROVIDER_EXTENSION_POINT_NAME
goa_provider_get_all
goa_provider_get_for_provider_type
diff --git a/src/goabackend/goaprovider.c b/src/goabackend/goaprovider.c
index 706f067..d37b8e2 100644
--- a/src/goabackend/goaprovider.c
+++ b/src/goabackend/goaprovider.c
@@ -60,6 +60,8 @@ static void goa_provider_show_account_real (GoaProvider *provider,
GtkBox *vbox,
GtkTable *table);
+static guint goa_provider_get_credentials_generation_real (GoaProvider *provider);
+
G_DEFINE_ABSTRACT_TYPE (GoaProvider, goa_provider, G_TYPE_OBJECT);
static void
@@ -73,6 +75,7 @@ goa_provider_class_init (GoaProviderClass *klass)
klass->build_object = goa_provider_build_object_real;
klass->ensure_credentials_sync = goa_provider_ensure_credentials_sync_real;
klass->show_account = goa_provider_show_account_real;
+ klass->get_credentials_generation = goa_provider_get_credentials_generation_real;
}
/**
@@ -494,6 +497,39 @@ goa_provider_build_object_real (GoaProvider *provider,
/* ---------------------------------------------------------------------------------------------------- */
+/**
+ * goa_provider_get_credentials_generation:
+ * @provider: A #GoaProvider.
+ *
+ * Gets the generation of credentials being used for the provider.
+ *
+ * Implementations should bump this number when changes are introduced
+ * that may render existing credentials unusable.
+ *
+ * For example, if an additional scope is requested (e.g. access to
+ * contacts data) while obtaining credentials, then this number needs
+ * to be bumped since existing credentials are not good for the added
+ * scope.
+ *
+ * This is a virtual method where the default implemention returns 0.
+ *
+ * Returns: The current generation of credentials.
+ */
+guint
+goa_provider_get_credentials_generation (GoaProvider *provider)
+{
+ g_return_val_if_fail (GOA_IS_PROVIDER (provider), FALSE);
+ return GOA_PROVIDER_GET_CLASS (provider)->get_credentials_generation (provider);
+}
+
+static guint
+goa_provider_get_credentials_generation_real (GoaProvider *provider)
+{
+ return 0;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
static void
ensure_ep_and_builtins (void)
{
@@ -644,8 +680,9 @@ goa_provider_store_credentials_sync (GoaProvider *provider,
g_variant_ref_sink (credentials);
g_variant_unref (credentials);
- password_key = g_strdup_printf ("%s:%s",
+ password_key = g_strdup_printf ("%s:gen%d:%s",
goa_provider_get_provider_type (GOA_PROVIDER (provider)),
+ goa_provider_get_credentials_generation (GOA_PROVIDER (provider)),
identity);
password_description = g_strdup_printf (_("GOA %s credentials for identity %s"),
goa_provider_get_provider_type (GOA_PROVIDER (provider)),
@@ -718,8 +755,9 @@ goa_provider_lookup_credentials_sync (GoaProvider *provider,
identity = goa_account_get_id (goa_object_peek_account (object));
- password_key = g_strdup_printf ("%s:%s",
+ password_key = g_strdup_printf ("%s:gen%d:%s",
goa_provider_get_provider_type (GOA_PROVIDER (provider)),
+ goa_provider_get_credentials_generation (GOA_PROVIDER (provider)),
identity);
result = gnome_keyring_find_password_sync (&keyring_password_schema,
diff --git a/src/goabackend/goaprovider.h b/src/goabackend/goaprovider.h
index 3dbb888..472ec3e 100644
--- a/src/goabackend/goaprovider.h
+++ b/src/goabackend/goaprovider.h
@@ -63,6 +63,7 @@ struct _GoaProvider
* @refresh_account: Virtual function for goa_provider_refresh_account().
* @build_object: Virtual function for goa_provider_build_object().
* @ensure_credentials_sync: Virtual function for goa_provider_ensure_credentials_sync().
+ * @get_credentials_generation: Virtual function for goa_provider_get_credentials_generation().
*
* Class structure for #GoaProvider.
*/
@@ -100,6 +101,7 @@ struct _GoaProviderClass
GoaObject *object,
GtkBox *vbox,
GtkTable *table);
+ guint (*get_credentials_generation) (GoaProvider *provider);
/*< private >*/
/* Padding for future expansion */
@@ -152,6 +154,8 @@ gboolean goa_provider_ensure_credentials_sync (GoaProvider *provid
gint *out_expires_in,
GCancellable *cancellable,
GError **error);
+guint goa_provider_get_credentials_generation (GoaProvider *provider);
+
/**
* GOA_PROVIDER_EXTENSION_POINT_NAME: