mirror of
https://github.com/flatpak/flatpak.git
synced 2026-02-23 10:25:13 -05:00
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.
This commit is contained in:
committed by
Alexander Larsson
parent
976c88cf56
commit
4dba1c389b
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
g_variant_builder_init (&refs_builder, G_VARIANT_TYPE ("a(si)"));
|
||||
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(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)
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user