Commit 145bb821 authored by Robert Ancell's avatar Robert Ancell Committed by Richard Hughes

Remove GsAuth support.

This used to be used in the Snap and Ubuntu Reviews plugins, but is now no
longer required. The remaining usage in the Snap plugin is not a common
case on desktop and not necessary to support anymore.
parent b2846d8b
Pipeline #94662 passed with stage
in 17 minutes and 23 seconds
......@@ -603,7 +603,6 @@ gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
<xi:include href="xml/gs-app-list.xml"/>
<xi:include href="xml/gs-app.xml"/>
<xi:include href="xml/gs-category.xml"/>
<xi:include href="xml/gs-auth.xml"/>
<xi:include href="xml/gs-os-release.xml"/>
<xi:include href="xml/gs-plugin.xml"/>
<xi:include href="xml/gs-plugin-event.xml"/>
......
......@@ -14,7 +14,6 @@
#include <gs-app.h>
#include <gs-app-list.h>
#include <gs-app-collation.h>
#include <gs-auth.h>
#include <gs-autocleanups.h>
#include <gs-category.h>
#include <gs-os-release.h>
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2016 Richard Hughes <richard@hughsie.com>
* Copyright (C) 2018 Canonical Ltd
*
* SPDX-License-Identifier: GPL-2.0+
*/
/**
* SECTION:gs-auth
* @title: GsAuth
* @include: gnome-software.h
* @stability: Unstable
* @short_description: User data used for authentication
*
* This object represents user data used for authentication.
* This data is shared between all plugins.
*/
#include "config.h"
#include "gs-auth.h"
#include "gs-plugin.h"
struct _GsAuth
{
GObject parent_instance;
gchar *header_none;
gchar *header_single;
gchar *header_multiple;
gchar *auth_id;
gchar *provider_name;
gchar *provider_type;
GoaClient *goa_client;
GoaObject *goa_object;
GSettings *settings;
};
static void gs_auth_initable_iface_init (GInitableIface *iface);
G_DEFINE_TYPE_WITH_CODE (GsAuth, gs_auth, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE(G_TYPE_INITABLE, gs_auth_initable_iface_init))
enum {
SIGNAL_CHANGED,
SIGNAL_LAST
};
enum {
PROP_0,
PROP_AUTH_ID,
PROP_PROVIDER_TYPE,
PROP_GOA_OBJECT,
PROP_LAST
};
static guint signals [SIGNAL_LAST] = { 0 };
/**
* gs_auth_get_header:
* @auth: a #GsAuth
* @n: the number of accounts
*
* Gets the header to be used in the authentication dialog in case there are @n
* available accounts.
*
* Returns: (transfer none) : a string
*/
const gchar *
gs_auth_get_header (GsAuth *auth, guint n)
{
g_return_val_if_fail (GS_IS_AUTH (auth), NULL);
if (n == 0)
return auth->header_none;
else if (n == 1)
return auth->header_single;
else
return auth->header_multiple;
}
/**
* gs_auth_set_header:
* @auth: a #GsAuth
* @header_none: the header to be used if no account is present
* @header_single: the header to be used if one account is present
* @header_multiple: the header to be used if two or more accounts are present
*
* Sets the headers to be used for the authentication dialog.
*/
void
gs_auth_set_header (GsAuth *auth,
const gchar *header_none,
const gchar *header_single,
const gchar *header_multiple)
{
g_return_if_fail (GS_IS_AUTH (auth));
g_return_if_fail (header_none != NULL);
g_return_if_fail (header_single != NULL);
g_return_if_fail (header_multiple != NULL);
g_free (auth->header_none);
auth->header_none = g_strdup (header_none);
g_free (auth->header_single);
auth->header_single = g_strdup (header_single);
g_free (auth->header_multiple);
auth->header_multiple = g_strdup (header_multiple);
}
/**
* gs_auth_get_auth_id:
* @auth: a #GsAuth
*
* Gets the authentication service ID.
*
* Returns: (transfer none): a string
*/
const gchar *
gs_auth_get_auth_id (GsAuth *auth)
{
g_return_val_if_fail (GS_IS_AUTH (auth), NULL);
return auth->auth_id;
}
/**
* gs_auth_get_provider_name:
* @auth: a #GsAuth
*
* Gets the authentication service name.
*
* Returns: (transfer none): a string
*/
const gchar *
gs_auth_get_provider_name (GsAuth *auth)
{
g_return_val_if_fail (GS_IS_AUTH (auth), NULL);
return auth->provider_name;
}
/**
* gs_auth_set_provider_name:
* @auth: a #GsAuth
* @provider_name: a service name, e.g. "Snap Store"
*
* Sets the name to be used for the authentication dialog.
*/
void
gs_auth_set_provider_name (GsAuth *auth, const gchar *provider_name)
{
g_return_if_fail (GS_IS_AUTH (auth));
g_return_if_fail (provider_name != NULL);
g_free (auth->provider_name);
auth->provider_name = g_strdup (provider_name);
}
/**
* gs_auth_get_provider_type:
* @auth: a #GsAuth
*
* Gets the GoaProvider type to be used for the authentication dialog.
*
* Returns: (transfer none): a string
*/
const gchar *
gs_auth_get_provider_type (GsAuth *auth)
{
g_return_val_if_fail (GS_IS_AUTH (auth), NULL);
return auth->provider_type;
}
/**
* gs_auth_peek_goa_object:
* @auth: a #GsAuth
*
* Gets the logged #GoaObject if any.
*
* Returns: (transfer none) (nullable): a #GoaObject, or %NULL
*/
GoaObject *
gs_auth_peek_goa_object (GsAuth *auth)
{
g_return_val_if_fail (GS_IS_AUTH (auth), NULL);
return auth->goa_object;
}
static gboolean
gs_auth_goa_account_equal (GoaAccount *acc1, GoaAccount *acc2)
{
if (acc1 == acc2)
return TRUE;
if (acc1 == NULL || acc2 == NULL)
return FALSE;
return !g_strcmp0 (goa_account_get_id (acc1),
goa_account_get_id (acc2));
}
static gboolean
gs_auth_goa_object_equal (GoaObject *obj1, GoaObject *obj2)
{
if (obj1 == obj2)
return TRUE;
if (obj1 == NULL || obj2 == NULL)
return FALSE;
return gs_auth_goa_account_equal(goa_object_peek_account (obj1),
goa_object_peek_account (obj2));
}
static void
gs_auth_account_changed_cb (GoaClient *client,
GoaObject *goa_object,
GsAuth *auth)
{
if (!gs_auth_goa_object_equal (auth->goa_object, goa_object))
return;
g_signal_emit (auth, signals[SIGNAL_CHANGED], 0);
}
static void
gs_auth_account_removed_cb (GoaClient *client,
GoaObject *goa_object,
GsAuth *auth)
{
if (!gs_auth_goa_object_equal (auth->goa_object, goa_object))
return;
gs_auth_set_goa_object (auth, NULL);
}
/**
* gs_auth_set_goa_object:
* @auth: a #GsAuth
* @goa_object: (nullable) a #GoaObject
*
* Set the #GoaObject used to login in.
*/
void
gs_auth_set_goa_object (GsAuth *auth,
GoaObject *goa_object)
{
g_return_if_fail (GS_IS_AUTH (auth));
if (gs_auth_goa_object_equal (auth->goa_object, goa_object))
return;
g_clear_object (&auth->goa_object);
if (goa_object)
auth->goa_object = g_object_ref (goa_object);
g_object_notify (G_OBJECT (auth), "goa-object");
g_signal_emit (auth, signals[SIGNAL_CHANGED], 0);
}
static gboolean
string_to_goa_object (GValue *value,
GVariant *variant,
gpointer user_data)
{
GsAuth *auth = GS_AUTH (user_data);
GoaObject *goa_object;
const gchar *account_id;
account_id = g_variant_get_string (variant, NULL);
goa_object = goa_client_lookup_by_id (auth->goa_client, account_id);
if (!goa_object)
return TRUE;
g_value_take_object (value, goa_object);
return TRUE;
}
static GVariant *
goa_object_to_string (const GValue *value,
const GVariantType *expected_type,
gpointer user_data)
{
GObject *object = g_value_get_object (value);
GoaObject *goa_object = object != NULL ? GOA_OBJECT (object) : NULL;
GoaAccount *goa_account = goa_object != NULL ? goa_object_peek_account (goa_object) : NULL;
if (goa_account != NULL)
return g_variant_new_string (goa_account_get_id (goa_account));
else
return g_variant_new_string ("");
}
/* GObject */
static void
gs_auth_init (GsAuth *auth)
{
}
static void
gs_auth_get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
GsAuth *auth = GS_AUTH (object);
switch (prop_id) {
case PROP_AUTH_ID:
g_value_set_string (value, auth->auth_id);
break;
case PROP_PROVIDER_TYPE:
g_value_set_string (value, auth->provider_type);
break;
case PROP_GOA_OBJECT:
g_value_set_object (value, auth->goa_object);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gs_auth_set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
GsAuth *auth = GS_AUTH (object);
switch (prop_id) {
case PROP_AUTH_ID:
auth->auth_id = g_value_dup_string (value);
break;
case PROP_PROVIDER_TYPE:
auth->provider_type = g_value_dup_string (value);
break;
case PROP_GOA_OBJECT:
gs_auth_set_goa_object (auth, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gs_auth_finalize (GObject *object)
{
GsAuth *auth = GS_AUTH (object);
g_free (auth->header_none);
g_free (auth->header_single);
g_free (auth->header_multiple);
g_free (auth->auth_id);
g_free (auth->provider_name);
g_clear_object (&auth->goa_client);
g_clear_object (&auth->goa_object);
g_clear_object (&auth->settings);
G_OBJECT_CLASS (gs_auth_parent_class)->finalize (object);
}
static void
gs_auth_class_init (GsAuthClass *klass)
{
GParamSpec *pspec;
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gs_auth_finalize;
object_class->get_property = gs_auth_get_property;
object_class->set_property = gs_auth_set_property;
pspec = g_param_spec_string ("auth-id", NULL, NULL, NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_AUTH_ID, pspec);
pspec = g_param_spec_string ("provider-type", NULL, NULL, NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_PROVIDER_TYPE, pspec);
pspec = g_param_spec_object ("goa-object", NULL, NULL,
GOA_TYPE_OBJECT,
G_PARAM_READWRITE |
G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_property (object_class, PROP_GOA_OBJECT, pspec);
signals [SIGNAL_CHANGED] =
g_signal_new ("changed",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
0, NULL, NULL, g_cclosure_marshal_generic,
G_TYPE_NONE, 0);
}
/* GInitable */
static gboolean
gs_auth_initable_init (GInitable *initable,
GCancellable *cancellable,
GError **error)
{
GsAuth *self;
g_autofree gchar *path = NULL;
g_return_val_if_fail (GS_IS_AUTH (initable), FALSE);
self = GS_AUTH (initable);
self->goa_client = goa_client_new_sync (NULL, error);
if (self->goa_client == NULL)
return FALSE;
g_signal_connect (self->goa_client, "account-changed",
G_CALLBACK (gs_auth_account_changed_cb), self);
g_signal_connect (self->goa_client, "account-removed",
G_CALLBACK (gs_auth_account_removed_cb), self);
path = g_strdup_printf ("/org/gnome/software/auth/%s/", self->auth_id);
self->settings = g_settings_new_with_path ("org.gnome.software.auth", path);
g_settings_bind_with_mapping (self->settings, "account-id",
self, "goa-object",
G_SETTINGS_BIND_DEFAULT,
string_to_goa_object,
goa_object_to_string,
self, NULL);
return TRUE;
}
static void
gs_auth_initable_iface_init (GInitableIface *iface)
{
iface->init = gs_auth_initable_init;
}
/**
* gs_auth_new:
* @auth_id: an identifier used for mapping, e.g. "snapd"
* @provider_type: the name of the GoaProvider466 to be used, e.g. "ubuntusso"
* @error: A #GError
*
* Return value: (transfer full) (nullable): a new #GsAuth object.
**/
GsAuth *
gs_auth_new (const gchar *auth_id,
const gchar *provider_type,
GError **error)
{
GsAuth *auth;
g_return_val_if_fail (auth_id != NULL, NULL);
g_return_val_if_fail (provider_type != NULL, NULL);
auth = g_initable_new (GS_TYPE_AUTH, NULL, error,
"auth-id", auth_id,
"provider-type", provider_type,
NULL);
return GS_AUTH (auth);
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2016 Richard Hughes <richard@hughsie.com>
* Copyright (C) 2018 Canonical Ltd
*
* SPDX-License-Identifier: GPL-2.0+
*/
#pragma once
#include <glib-object.h>
#include <gio/gio.h>
#define GOA_API_IS_SUBJECT_TO_CHANGE
#include <goa/goa.h>
G_BEGIN_DECLS
#define GS_TYPE_AUTH (gs_auth_get_type ())
G_DECLARE_FINAL_TYPE (GsAuth, gs_auth, GS, AUTH, GObject)
GsAuth *gs_auth_new (const gchar *auth_id,
const gchar *provider_type,
GError **error);
const gchar *gs_auth_get_header (GsAuth *auth,
guint n);
void gs_auth_set_header (GsAuth *auth,
const gchar *header_none,
const gchar *header_single,
const gchar *header_multiple);
const gchar *gs_auth_get_auth_id (GsAuth *auth);
const gchar *gs_auth_get_provider_name (GsAuth *auth);
void gs_auth_set_provider_name (GsAuth *auth,
const gchar *provider_name);
const gchar *gs_auth_get_provider_type (GsAuth *auth);
GoaObject *gs_auth_peek_goa_object (GsAuth *auth);
void gs_auth_set_goa_object (GsAuth *auth,
GoaObject *goa_object);
G_END_DECLS
......@@ -30,7 +30,6 @@ guint64 gs_plugin_job_get_age (GsPluginJob *self);
GsAppListSortFunc gs_plugin_job_get_sort_func (GsPluginJob *self);
gpointer gs_plugin_job_get_sort_func_data (GsPluginJob *self);
const gchar *gs_plugin_job_get_search (GsPluginJob *self);
GsAuth *gs_plugin_job_get_auth (GsPluginJob *self);
GsApp *gs_plugin_job_get_app (GsPluginJob *self);
GsAppList *gs_plugin_job_get_list (GsPluginJob *self);
GFile *gs_plugin_job_get_file (GsPluginJob *self);
......
......@@ -28,7 +28,6 @@ struct _GsPluginJob
GsAppListSortFunc sort_func;
gpointer sort_func_data;
gchar *search;
GsAuth *auth;
GsApp *app;
GsAppList *list;
GFile *file;
......@@ -46,7 +45,6 @@ enum {
PROP_FILTER_FLAGS,
PROP_DEDUPE_FLAGS,
PROP_INTERACTIVE,
PROP_AUTH,
PROP_APP,
PROP_LIST,
PROP_FILE,
......@@ -109,10 +107,6 @@ gs_plugin_job_to_string (GsPluginJob *self)
g_string_append_printf (str, " with review=%s",
as_review_get_id (self->review));
}
if (self->auth != NULL) {
g_string_append_printf (str, " with auth=%s",
gs_auth_get_auth_id (self->auth));
}
if (self->file != NULL) {
g_autofree gchar *path = g_file_get_path (self->file);
g_string_append_printf (str, " with file=%s", path);
......@@ -315,20 +309,6 @@ gs_plugin_job_get_search (GsPluginJob *self)
return self->search;
}
void
gs_plugin_job_set_auth (GsPluginJob *self, GsAuth *auth)
{
g_return_if_fail (GS_IS_PLUGIN_JOB (self));
g_set_object (&self->auth, auth);
}
GsAuth *
gs_plugin_job_get_auth (GsPluginJob *self)
{
g_return_val_if_fail (GS_IS_PLUGIN_JOB (self), NULL);
return self->auth;
}
void
gs_plugin_job_set_app (GsPluginJob *self, GsApp *app)
{
......@@ -446,9 +426,6 @@ gs_plugin_job_get_property (GObject *obj, guint prop_id, GValue *value, GParamSp
case PROP_SEARCH:
g_value_set_string (value, self->search);
break;
case PROP_AUTH:
g_value_set_object (value, self->auth);
break;
case PROP_APP:
g_value_set_object (value, self->app);
break;
......@@ -503,9 +480,6 @@ gs_plugin_job_set_property (GObject *obj, guint prop_id, const GValue *value, GP
case PROP_SEARCH:
gs_plugin_job_set_search (self, g_value_get_string (value));
break;
case PROP_AUTH:
gs_plugin_job_set_auth (self, g_value_get_object (value));
break;
case PROP_APP:
gs_plugin_job_set_app (self, g_value_get_object (value));
break;
......@@ -538,7 +512,6 @@ gs_plugin_job_finalize (GObject *obj)
{
GsPluginJob *self = GS_PLUGIN_JOB (obj);
g_free (self->search);
g_clear_object (&self->auth);
g_clear_object (&self->app);
g_clear_object (&self->list);
g_clear_object (&self->file);
......@@ -595,11 +568,6 @@ gs_plugin_job_class_init (GsPluginJobClass *klass)
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_SEARCH, pspec);
pspec = g_param_spec_object ("auth", NULL, NULL,
GS_TYPE_AUTH,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_AUTH, pspec);
pspec = g_param_spec_object ("app", NULL, NULL,
GS_TYPE_APP,
G_PARAM_READWRITE);
......
......@@ -10,7 +10,6 @@
#include <glib-object.h>
#include "gs-app-list-private.h"
#include "gs-auth.h"
#include "gs-category.h"
#include "gs-plugin-types.h"
......@@ -40,8 +39,6 @@ void gs_plugin_job_set_sort_func_data (GsPluginJob *self,
gpointer sort_func_data);
void gs_plugin_job_set_search (GsPluginJob *self,
const gchar *search);
void gs_plugin_job_set_auth (GsPluginJob *self,
GsAuth *auth);
void gs_plugin_job_set_app (GsPluginJob *self,
GsApp *app);
void gs_plugin_job_set_list (GsPluginJob *self,
......
......@@ -36,7 +36,6 @@ typedef struct
gchar *language;
gboolean plugin_dir_dirty;
SoupSession *soup_session;
GPtrArray *auth_array;
GPtrArray *file_monitors;
GsPluginStatus global_status_last;
......@@ -127,10 +126,6 @@ typedef gboolean (*GsPluginReviewFunc) (GsPlugin *plugin,
AsReview *review,
GCancellable *cancellable,
GError **error);
typedef gboolean (*GsPluginAuthFunc) (GsPlugin *plugin,
GsAuth *auth,
GCancellable *cancellable,
GError **error);
typedef gboolean (*GsPluginRefineFunc) (GsPlugin *plugin,
GsAppList *list,
GsPluginRefineFlags refine_flags,
......@@ -2074,7 +2069,6 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
G_CALLBACK (gs_plugin_loader_allow_updates_cb),