summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2019-12-06 19:10:33 +0100
committerAlexander Larsson <alexander.larsson@gmail.com>2019-12-12 12:16:53 +0100
commit4dba1c389b00a86bc351b5702445dc798db99de7 (patch)
tree1514c5d2715cc0c4b31aa08affcb8568a25b88d2
parent976c88cf56b9c513a085d5dc32fb3734e3d3489f (diff)
downloadflatpak-4dba1c389b00a86bc351b5702445dc798db99de7.tar.gz
authenticator: Add more data to token request
This adds the remote uri, and the per-ref commit id, as well as extensible per-ref and per-request dicts we can add stuff to as needed. These will be used for the OCI case.
-rw-r--r--common/flatpak-auth-private.h2
-rw-r--r--common/flatpak-auth.c4
-rw-r--r--common/flatpak-transaction.c20
-rw-r--r--data/org.freedesktop.Flatpak.Authenticator.xml9
-rw-r--r--tests/test-authenticator.c12
5 files changed, 37 insertions, 10 deletions
diff --git a/common/flatpak-auth-private.h b/common/flatpak-auth-private.h
index fce34886..a9d2db94 100644
--- a/common/flatpak-auth-private.h
+++ b/common/flatpak-auth-private.h
@@ -52,7 +52,9 @@ FlatpakAuthenticatorRequest *flatpak_auth_create_request (FlatpakAuth
gboolean flatpak_auth_request_ref_tokens (FlatpakAuthenticator *authenticator,
FlatpakAuthenticatorRequest *request,
const char *remote,
+ const char *remote_uri,
GVariant *refs,
+ GVariant *extra_data,
const char *parent_window,
GCancellable *cancellable,
GError **error);
diff --git a/common/flatpak-auth.c b/common/flatpak-auth.c
index ac3c9632..406868b8 100644
--- a/common/flatpak-auth.c
+++ b/common/flatpak-auth.c
@@ -130,7 +130,9 @@ gboolean
flatpak_auth_request_ref_tokens (FlatpakAuthenticator *authenticator,
FlatpakAuthenticatorRequest *request,
const char *remote,
+ const char *remote_uri,
GVariant *refs,
+ GVariant *extra_data,
const char *parent_window,
GCancellable *cancellable,
GError **error)
@@ -143,7 +145,7 @@ flatpak_auth_request_ref_tokens (FlatpakAuthenticator *authenticator,
options = g_object_get_data (G_OBJECT (authenticator), "authenticator-options");
- if (!flatpak_authenticator_call_request_ref_tokens_sync (authenticator, token, options, remote, refs,
+ if (!flatpak_authenticator_call_request_ref_tokens_sync (authenticator, token, options, remote, remote_uri, refs, extra_data,
parent_window ? parent_window : "",
&handle, cancellable, error))
return FALSE;
diff --git a/common/flatpak-transaction.c b/common/flatpak-transaction.c
index dfa52021..6ab9658f 100644
--- a/common/flatpak-transaction.c
+++ b/common/flatpak-transaction.c
@@ -2847,14 +2847,22 @@ request_tokens_for_remote (FlatpakTransaction *self,
g_autoptr(GVariant) results = NULL;
g_autoptr(GVariant) refs = NULL;
GVariantBuilder refs_builder;
+ g_autofree char *remote_url = NULL;
+ g_autoptr(GVariantBuilder) extra_builder = NULL;
+ FlatpakRemoteState *state;
+
+ if (!ostree_repo_remote_get_url (flatpak_dir_get_repo (priv->dir), remote, &remote_url, error))
+ return FALSE;
- g_variant_builder_init (&refs_builder, G_VARIANT_TYPE ("a(si)"));
+ g_variant_builder_init (&refs_builder, G_VARIANT_TYPE ("a(ssia{sv})"));
for (l = ops; l != NULL; l = l->next)
{
FlatpakTransactionOperation *op = l->data;
- g_variant_builder_add (&refs_builder, "(si)", op->ref, (gint32)op->token_type);
- g_string_append_printf (refs_as_str, "(%s, %d)", op->ref, op->token_type);
+ g_autoptr(GVariantBuilder) metadata_builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
+
+ g_variant_builder_add (&refs_builder, "(ssi@a{sv})", op->ref, op->resolved_commit ? op->resolved_commit : "", (gint32)op->token_type, g_variant_builder_end (metadata_builder));
+ g_string_append_printf (refs_as_str, "(%s, %s %d)", op->ref, op->resolved_commit ? op->resolved_commit : "", op->token_type);
if (l->next != NULL)
g_string_append (refs_as_str, ", ");
}
@@ -2862,6 +2870,8 @@ request_tokens_for_remote (FlatpakTransaction *self,
g_debug ("Requesting tokens for remote %s: %s", remote, refs_as_str->str);
refs = g_variant_ref_sink (g_variant_builder_end (&refs_builder));
+ extra_builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
+
context = flatpak_main_context_new_default ();
authenticator = flatpak_auth_new_for_remote (priv->dir, remote, cancellable, error);
@@ -2878,8 +2888,10 @@ request_tokens_for_remote (FlatpakTransaction *self,
priv->active_webflow = &data;
+
data.request = request;
- if (!flatpak_auth_request_ref_tokens (authenticator, request, remote, refs, priv->parent_window, cancellable, error))
+ if (!flatpak_auth_request_ref_tokens (authenticator, request, remote, remote_url, refs, g_variant_builder_end (extra_builder),
+ priv->parent_window, cancellable, error))
return FALSE;
while (!data.done)
diff --git a/data/org.freedesktop.Flatpak.Authenticator.xml b/data/org.freedesktop.Flatpak.Authenticator.xml
index 6d182593..f7e8004a 100644
--- a/data/org.freedesktop.Flatpak.Authenticator.xml
+++ b/data/org.freedesktop.Flatpak.Authenticator.xml
@@ -75,7 +75,9 @@
more information about the @handle.
@authenticator_options: Data from the xa.authenticator-options key in the configuration for the remote, it is up to the authenticator to interpret this how it wants.
@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 refs that flatpak wants to pull and the token-type for each ref.
+ @extra_data: An extensible dict with extra data for the request.
@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.
@@ -88,7 +90,8 @@
<varlistentry>
<term>tokens a{sas}</term>
<listitem><para>
- A list of tokens (the first element of the struct), and the refs that it applies to (the second element of the struct).
+ A list of tokens (the first element of the struct), and the refs+commit that it applies to (the second and third element of the struct).
+ Each element also has an dict with extra data as element 4.
The returned token may be the empty string, to signal that flatpak doesn't need to use a token for these refs.
</para></listitem>
</varlistentry>
@@ -112,8 +115,10 @@
<arg type='s' name='handle_token' direction='in'/>
<arg type='a{sv}' name='authenticator_options' direction='in'/>
<arg type='s' name='remote' direction='in'/>
+ <arg type='s' name='remote_uri' direction='in'/>
<!-- This is the ref and its token-type -->
- <arg type='a(si)' name='refs' direction='in'/>
+ <arg type='a(ssia{sv})' name='refs' direction='in'/>
+ <arg type='a{sv}' name='extra_data' direction='in'/>
<arg type='s' name='parent_window' direction='in'/>
<arg type='o' name='handle' direction='out'/>
</method>
diff --git a/tests/test-authenticator.c b/tests/test-authenticator.c
index f6dc0a0a..e7fa7bb6 100644
--- a/tests/test-authenticator.c
+++ b/tests/test-authenticator.c
@@ -173,7 +173,10 @@ handle_request_ref_tokens (FlatpakAuthenticator *authenticator,
const gchar *arg_handle_token,
GVariant *arg_authenticator_option,
const gchar *arg_remote,
- GVariant *arg_refs)
+ const gchar *arg_remote_uri,
+ GVariant *arg_refs,
+ GVariant *arg_extra_data,
+ const gchar *arg_parent_window)
{
g_autoptr(GError) error = NULL;
g_autoptr(GSocketService) server = NULL;
@@ -219,9 +222,12 @@ handle_request_ref_tokens (FlatpakAuthenticator *authenticator,
n_refs = g_variant_n_children (arg_refs);
for (i = 0; i < n_refs; i++)
{
- const char *ref;
+ const char *ref, *commit;
gint32 token_type;
- g_variant_get_child (arg_refs, i, "(&si)", &ref, &token_type);
+ g_autoptr(GVariant) data = NULL;
+
+ g_variant_get_child (arg_refs, i, "(&s&si@a{sv})", &ref, &commit, &token_type, &data);
+
g_ptr_array_add (refs, g_strdup (ref));
}
g_ptr_array_add (refs, NULL);