Skip to content

Commit

Permalink
Authenticator: Add extra a{sv} args for future use
Browse files Browse the repository at this point in the history
These are not used atm, but make the APIs future proof.
  • Loading branch information
alexlarsson committed Dec 12, 2019
1 parent 134e01f commit 38c86bd
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 32 deletions.
5 changes: 4 additions & 1 deletion app/flatpak-cli-transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ static gboolean
webflow_start (FlatpakTransaction *transaction,
const char *remote,
const char *url,
GVariant *options,
guint id)
{
FlatpakCliTransaction *self = FLATPAK_CLI_TRANSACTION (transaction);
Expand Down Expand Up @@ -541,6 +542,7 @@ webflow_start (FlatpakTransaction *transaction,

static void
webflow_done (FlatpakTransaction *transaction,
GVariant *options,
guint id)
{
g_print ("Browser done\n");
Expand All @@ -550,6 +552,7 @@ static gboolean
basic_auth_start (FlatpakTransaction *transaction,
const char *remote,
const char *realm,
GVariant *options,
guint id)
{
FlatpakCliTransaction *self = FLATPAK_CLI_TRANSACTION (transaction);
Expand All @@ -569,7 +572,7 @@ basic_auth_start (FlatpakTransaction *transaction,
if (password == NULL)
return FALSE;

flatpak_transaction_complete_basic_auth (transaction, id, user, password);
flatpak_transaction_complete_basic_auth (transaction, id, user, password, NULL);
return TRUE;
}

Expand Down
11 changes: 7 additions & 4 deletions common/flatpak-auth-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ gboolean flatpak_auth_request_ref_tokens (FlatpakAuth
const char *remote,
const char *remote_uri,
GVariant *refs,
GVariant *extra_data,
GVariant *options,
const char *parent_window,
GCancellable *cancellable,
GError **error);
Expand All @@ -67,11 +67,14 @@ void flatpak_auth_request_emit_response (FlatpakAuth
GVariant *arg_results);
void flatpak_auth_request_emit_webflow (FlatpakAuthenticatorRequest *request,
const gchar *destination_bus_name,
const char *arg_uri);
const char *arg_uri,
GVariant *options);
void flatpak_auth_request_emit_webflow_done (FlatpakAuthenticatorRequest *request,
const gchar *destination_bus_name);
const gchar *destination_bus_name,
GVariant *options);
void flatpak_auth_request_emit_basic_auth (FlatpakAuthenticatorRequest *request,
const char *destination_bus_name,
const char *arg_realm);
const char *arg_realm,
GVariant *options);

#endif /* __FLATPAK_AUTH_H__ */
47 changes: 37 additions & 10 deletions common/flatpak-auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,20 @@ flatpak_auth_request_ref_tokens (FlatpakAuthenticator *authenticator,
const char *remote,
const char *remote_uri,
GVariant *refs,
GVariant *extra_data,
GVariant *options,
const char *parent_window,
GCancellable *cancellable,
GError **error)
{
const char *token;
GVariant *options;
GVariant *auth_options;
g_autofree char *handle = NULL;

token = strrchr (g_dbus_proxy_get_object_path (G_DBUS_PROXY (request)), '/') + 1;

options = g_object_get_data (G_OBJECT (authenticator), "authenticator-options");
auth_options = g_object_get_data (G_OBJECT (authenticator), "authenticator-options");

if (!flatpak_authenticator_call_request_ref_tokens_sync (authenticator, token, options, remote, remote_uri, refs, extra_data,
if (!flatpak_authenticator_call_request_ref_tokens_sync (authenticator, token, auth_options, remote, remote_uri, refs, options,
parent_window ? parent_window : "",
&handle, cancellable, error))
return FALSE;
Expand Down Expand Up @@ -187,14 +187,23 @@ flatpak_auth_request_emit_response (FlatpakAuthenticatorRequest *request,
void
flatpak_auth_request_emit_webflow (FlatpakAuthenticatorRequest *request,
const gchar *destination_bus_name,
const char *arg_uri)
const char *arg_uri,
GVariant *options)
{
FlatpakAuthenticatorRequestSkeleton *skeleton = FLATPAK_AUTHENTICATOR_REQUEST_SKELETON (request);
GList *connections, *l;
g_autoptr(GVariant) signal_variant = NULL;
g_autoptr(GVariant) default_options = NULL;

if (options == NULL)
{
default_options = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0));
options = default_options;
}

connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));

signal_variant = g_variant_ref_sink (g_variant_new ("(s)", arg_uri));
signal_variant = g_variant_ref_sink (g_variant_new ("(s@a{sv})", arg_uri, options));
for (l = connections; l != NULL; l = l->next)
{
GDBusConnection *connection = l->data;
Expand All @@ -208,14 +217,23 @@ flatpak_auth_request_emit_webflow (FlatpakAuthenticatorRequest *request,

void
flatpak_auth_request_emit_webflow_done (FlatpakAuthenticatorRequest *request,
const gchar *destination_bus_name)
const gchar *destination_bus_name,
GVariant *options)
{
FlatpakAuthenticatorRequestSkeleton *skeleton = FLATPAK_AUTHENTICATOR_REQUEST_SKELETON (request);
GList *connections, *l;
g_autoptr(GVariant) signal_variant = NULL;
g_autoptr(GVariant) default_options = NULL;

if (options == NULL)
{
default_options = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0));
options = default_options;
}

connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));

signal_variant = g_variant_ref_sink (g_variant_new ("()"));
signal_variant = g_variant_ref_sink (g_variant_new ("(@a{sv})", options));
for (l = connections; l != NULL; l = l->next)
{
GDBusConnection *connection = l->data;
Expand All @@ -230,14 +248,23 @@ flatpak_auth_request_emit_webflow_done (FlatpakAuthenticatorRequest *request,
void
flatpak_auth_request_emit_basic_auth (FlatpakAuthenticatorRequest *request,
const char *destination_bus_name,
const char *arg_realm)
const char *arg_realm,
GVariant *options)
{
FlatpakAuthenticatorRequestSkeleton *skeleton = FLATPAK_AUTHENTICATOR_REQUEST_SKELETON (request);
GList *connections, *l;
g_autoptr(GVariant) signal_variant = NULL;
g_autoptr(GVariant) default_options = NULL;

if (options == NULL)
{
default_options = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0));
options = default_options;
}

connections = g_dbus_interface_skeleton_get_connections (G_DBUS_INTERFACE_SKELETON (skeleton));

signal_variant = g_variant_ref_sink (g_variant_new ("(s)", arg_realm));
signal_variant = g_variant_ref_sink (g_variant_new ("(s@a{sv})", arg_realm, options));
for (l = connections; l != NULL; l = l->next)
{
GDBusConnection *connection = l->data;
Expand Down
30 changes: 23 additions & 7 deletions common/flatpak-transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,7 @@ flatpak_transaction_class_init (FlatpakTransactionClass *klass)
* @object: A #FlatpakTransaction
* @remote: The remote we're authenticating with
* @url: The url to show
* @options: Extra options, currently unused
* @id: The id of the operation, can be used to cancel it
*
* The ::webflow-start signal gets emitted when some kind of user
Expand Down Expand Up @@ -1177,10 +1178,11 @@ flatpak_transaction_class_init (FlatpakTransactionClass *klass)
G_STRUCT_OFFSET (FlatpakTransactionClass, webflow_start),
NULL, NULL,
NULL,
G_TYPE_BOOLEAN, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
G_TYPE_BOOLEAN, 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_VARIANT, G_TYPE_INT);
/**
* FlatpakTransaction::webflow-done:
* @object: A #FlatpakTransaction
* @options: Extra options, currently unused
* @id: The id of the operation
*
* The ::webflow-done signal gets emitted when the authentication
Expand All @@ -1196,12 +1198,13 @@ flatpak_transaction_class_init (FlatpakTransactionClass *klass)
G_STRUCT_OFFSET (FlatpakTransactionClass, webflow_done),
NULL, NULL,
NULL,
G_TYPE_NONE, 1, G_TYPE_INT);
G_TYPE_NONE, 2, G_TYPE_VARIANT, G_TYPE_INT);
/**
* FlatpakTransaction::basic-auth-start:
* @object: A #FlatpakTransaction
* @remote: The remote we're authenticating with
* @realm: The url to show
* @options: Extra options, currently unused
* @id: The id of the operation, can be used to finish it
*
* The ::basic-auth-start signal gets emitted when a basic user/password
Expand All @@ -1224,7 +1227,7 @@ flatpak_transaction_class_init (FlatpakTransactionClass *klass)
G_STRUCT_OFFSET (FlatpakTransactionClass, basic_auth_start),
NULL, NULL,
NULL,
G_TYPE_BOOLEAN, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
G_TYPE_BOOLEAN, 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_VARIANT, G_TYPE_INT);

}

Expand Down Expand Up @@ -2784,6 +2787,7 @@ request_tokens_response (FlatpakAuthenticatorRequest *object,
static void
request_tokens_webflow (FlatpakAuthenticatorRequest *object,
const gchar *arg_uri,
GVariant *options,
RequestData *data)
{
g_autoptr(FlatpakTransaction) transaction = g_object_ref (data->transaction);
Expand All @@ -2797,7 +2801,7 @@ request_tokens_webflow (FlatpakAuthenticatorRequest *object,
priv->active_request_id = ++priv->next_request_id;

g_debug ("Webflow start %s", arg_uri);
g_signal_emit (transaction, signals[WEBFLOW_START], 0, data->remote, arg_uri, priv->active_request_id, &retval);
g_signal_emit (transaction, signals[WEBFLOW_START], 0, data->remote, arg_uri, options, priv->active_request_id, &retval);
if (!retval)
{
g_autoptr(GError) local_error = NULL;
Expand All @@ -2812,6 +2816,7 @@ request_tokens_webflow (FlatpakAuthenticatorRequest *object,

static void
request_tokens_webflow_done (FlatpakAuthenticatorRequest *object,
GVariant *options,
RequestData *data)
{
g_autoptr(FlatpakTransaction) transaction = g_object_ref (data->transaction);
Expand All @@ -2826,12 +2831,13 @@ request_tokens_webflow_done (FlatpakAuthenticatorRequest *object,
priv->active_request_id = 0;

g_debug ("Webflow done");
g_signal_emit (transaction, signals[WEBFLOW_DONE], 0, id);
g_signal_emit (transaction, signals[WEBFLOW_DONE], 0, options, id);
}

static void
request_tokens_basic_auth (FlatpakAuthenticatorRequest *object,
const gchar *arg_realm,
GVariant *options,
RequestData *data)
{
g_autoptr(FlatpakTransaction) transaction = g_object_ref (data->transaction);
Expand All @@ -2845,7 +2851,7 @@ request_tokens_basic_auth (FlatpakAuthenticatorRequest *object,
priv->active_request_id = ++priv->next_request_id;

g_debug ("BasicAuth start %s", arg_realm);
g_signal_emit (transaction, signals[BASIC_AUTH_START], 0, data->remote, arg_realm, priv->active_request_id, &retval);
g_signal_emit (transaction, signals[BASIC_AUTH_START], 0, data->remote, arg_realm, options, priv->active_request_id, &retval);
if (!retval)
{
g_autoptr(GError) local_error = NULL;
Expand Down Expand Up @@ -2902,6 +2908,7 @@ flatpak_transaction_abort_webflow (FlatpakTransaction *self,
* @id: The webflow id, as passed into the webflow-start signal
* @user: The user name, or %NULL if aborting request
* @password: The password
* @options: Extra a{sv] variant with options (or %NULL), currently unused.
*
* Finishes (or aborts) an ongoing basic auth request.
*
Expand All @@ -2911,10 +2918,18 @@ void
flatpak_transaction_complete_basic_auth (FlatpakTransaction *self,
guint id,
const char *user,
const char *password)
const char *password,
GVariant *options)
{
FlatpakTransactionPrivate *priv = flatpak_transaction_get_instance_private (self);
g_autoptr(GError) local_error = NULL;
g_autoptr(GVariant) default_options = NULL;

if (options == NULL)
{
default_options = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0));
options = default_options;
}

if (priv->active_request_id == id)
{
Expand All @@ -2932,6 +2947,7 @@ flatpak_transaction_complete_basic_auth (FlatpakTransaction *self,
{
if (!flatpak_authenticator_request_call_basic_auth_reply_sync (data->request,
user, password,
options,
NULL, &local_error))
g_debug ("Failed to reply to basic auth request: %s", local_error->message);
}
Expand Down
6 changes: 5 additions & 1 deletion common/flatpak-transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,16 @@ struct _FlatpakTransactionClass
gboolean (*webflow_start) (FlatpakTransaction *transaction,
const char *remote,
const char *url,
GVariant *options,
guint id);
void (*webflow_done) (FlatpakTransaction *transaction,
GVariant *options,
guint id);

gboolean (*basic_auth_start) (FlatpakTransaction *transaction,
const char *remote,
const char *realm,
GVariant *options,
guint id);
gpointer padding[5];
};
Expand Down Expand Up @@ -246,7 +249,8 @@ FLATPAK_EXTERN
void flatpak_transaction_complete_basic_auth (FlatpakTransaction *self,
guint id,
const char *user,
const char *password);
const char *password,
GVariant *options);

FLATPAK_EXTERN
gboolean flatpak_transaction_add_install (FlatpakTransaction *self,
Expand Down
15 changes: 12 additions & 3 deletions data/org.freedesktop.Flatpak.Authenticator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
@remote: The name of the remote we're pulling from.
@remote_uri: The uri of the remote we're pulling from.
@refs: An array of ref that flatpak wants to pull and info about each ref.
@extra_data: An extensible dict with extra data for the request.
@options: An extensible dict with extra options.
@parent_window: Identifier for the application window, see <link linkend="https://flatpak.github.io/xdg-desktop-portal/portal-docs.html#parent_window">xdg-desktop-portal docs</link> for details on its format.
@handle: Object path for the #org.freedesktop.Flatpak.AuthenticatorRequest object representing this call.
Expand Down Expand Up @@ -124,7 +124,7 @@
that can be used to get the user to interactively authenticate. This kind of authentication is quite limited, but
if used it can allow nice interactive authentication even in the command line case.
Currently used keys in the @extra_data argument:
Currently used keys in the @options argument:
<variablelist>
<varlistentry>
<term>xa.oci-registry-uri s</term>
Expand All @@ -142,7 +142,7 @@
<arg type='s' name='remote_uri' direction='in'/>
<!-- This is the ref and its token-type -->
<arg type='a(ssia{sv})' name='refs' direction='in'/>
<arg type='a{sv}' name='extra_data' direction='in'/>
<arg type='a{sv}' name='options' direction='in'/>
<arg type='s' name='parent_window' direction='in'/>
<arg type='o' name='handle' direction='out'/>
</method>
Expand Down Expand Up @@ -187,6 +187,8 @@
</method>
<!--
Webflow:
@uri: The uri to show
@options: An extensible dict with extra options.
Emitted by the authenticator when it needs to do web-based interaction. The
client handles this by showing the URI in a graphical web view. Typically the uri
Expand All @@ -200,18 +202,22 @@
-->
<signal name="Webflow">
<arg type="s" name="uri"/>
<arg type="a{sv}" name="options" direction="in"/>
</signal>
<!--
WebflowDone:
@options: An extensible dict with extra options.
Emitted by the authenticator when the web view is done, at this point the client
can close the WebView.
-->
<signal name="WebflowDone">
<arg type="a{sv}" name="options" direction="in"/>
</signal>
<!--
BasicAuth:
@realm: String showing what the auth is for, similar to http basic auth realm.
@options: An extensible dict with extra options.
Emitted by the authenticator when it needs to do a simple user + password authentication.
This is only useful for very simple authentication interaction, but this is still used (for
Expand All @@ -220,17 +226,20 @@
-->
<signal name="BasicAuth">
<arg type="s" name="realm"/>
<arg type="a{sv}" name="options" direction="in"/>
</signal>
<!--
BasicAuthReply:
@user: The user
@password: The password
@options: An extensible dict with extra options.
Call to finish the request started with the BasicAuth signal.
-->
<method name="BasicAuthReply">
<arg type="s" name="user"/>
<arg type="s" name="password"/>
<arg type="a{sv}" name="options" direction="in"/>
</method>
<!--
Response:
Expand Down

0 comments on commit 38c86bd

Please sign in to comment.