From e5fb8e27bfc9dc70a132715e04823cdb563c65d9 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Wed, 25 May 2011 14:17:20 -0400 Subject: Introduce generation concept for credentials This is needed to sanely handling added scopes in the future. Signed-off-by: David Zeuthen --- doc/goa-sections.txt | 1 + src/goabackend/goaprovider.c | 42 ++++++++++++++++++++++++++++++++++++++++-- src/goabackend/goaprovider.h | 4 ++++ 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: -- cgit v1.2.3