mirror of
https://github.com/flatpak/flatpak.git
synced 2026-05-24 16:57:42 -04:00
authenticator: Pass token-type for each ref
This allows the authenticator to handle each token type differently. For example, this allows a "purchase" type to run the donation webflow, but not require login (and then store the fact that this was run locally).
This commit is contained in:
committed by
Alexander Larsson
parent
e0cef17c0c
commit
90dc9ace2a
@@ -52,7 +52,7 @@ FlatpakAuthenticatorRequest *flatpak_auth_create_request (FlatpakAuth
|
||||
gboolean flatpak_auth_request_ref_tokens (FlatpakAuthenticator *authenticator,
|
||||
FlatpakAuthenticatorRequest *request,
|
||||
const char *remote,
|
||||
const char **refs,
|
||||
GVariant *refs,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
char * flatpak_auth_create_request_path (const char *peer,
|
||||
|
||||
@@ -130,7 +130,7 @@ gboolean
|
||||
flatpak_auth_request_ref_tokens (FlatpakAuthenticator *authenticator,
|
||||
FlatpakAuthenticatorRequest *request,
|
||||
const char *remote,
|
||||
const char **refs,
|
||||
GVariant *refs,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
|
||||
@@ -2773,25 +2773,30 @@ request_tokens_for_remote (FlatpakTransaction *self,
|
||||
GError **error)
|
||||
{
|
||||
FlatpakTransactionPrivate *priv = flatpak_transaction_get_instance_private (self);
|
||||
g_autofree char *refs_as_str = NULL;
|
||||
g_autoptr(GString) refs_as_str = g_string_new ("");
|
||||
GList *l;
|
||||
g_autoptr(GPtrArray) refs = g_ptr_array_new ();
|
||||
g_autoptr(AutoFlatpakAuthenticatorRequest) request = NULL;
|
||||
g_autoptr(AutoFlatpakAuthenticator) authenticator = NULL;
|
||||
g_autoptr(GMainContextPopDefault) context = NULL;
|
||||
RequestData data = { self, remote };
|
||||
g_autoptr(GVariant) tokens = NULL;
|
||||
g_autoptr(GVariant) results = NULL;
|
||||
g_autoptr(GVariant) refs = NULL;
|
||||
GVariantBuilder refs_builder;
|
||||
|
||||
g_variant_builder_init (&refs_builder, G_VARIANT_TYPE ("a(si)"));
|
||||
|
||||
for (l = ops; l != NULL; l = l->next)
|
||||
{
|
||||
FlatpakTransactionOperation *op = l->data;
|
||||
g_ptr_array_add (refs, op->ref);
|
||||
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);
|
||||
if (l->next != NULL)
|
||||
g_string_append (refs_as_str, ", ");
|
||||
}
|
||||
g_ptr_array_add (refs, NULL);
|
||||
|
||||
refs_as_str = g_strjoinv (", ", (char **)refs->pdata);
|
||||
g_debug ("Requesting tokens for remote %s, refs: %s", remote, refs_as_str);
|
||||
g_debug ("Requesting tokens for remote %s: %s", remote, refs_as_str->str);
|
||||
refs = g_variant_ref_sink (g_variant_builder_end (&refs_builder));
|
||||
|
||||
context = flatpak_main_context_new_default ();
|
||||
|
||||
@@ -2810,7 +2815,7 @@ request_tokens_for_remote (FlatpakTransaction *self,
|
||||
priv->active_webflow = &data;
|
||||
|
||||
data.request = request;
|
||||
if (!flatpak_auth_request_ref_tokens (authenticator, request, remote, (const char **)refs->pdata, cancellable, error))
|
||||
if (!flatpak_auth_request_ref_tokens (authenticator, request, remote, refs, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
while (!data.done)
|
||||
|
||||
@@ -176,7 +176,8 @@
|
||||
<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='as' name='refs' direction='in'/>
|
||||
<!-- This is the ref and its token-type -->
|
||||
<arg type='a(si)' name='refs' direction='in'/>
|
||||
<arg type='o' name='handle' direction='out'/>
|
||||
</method>
|
||||
</interface>
|
||||
|
||||
@@ -173,7 +173,7 @@ handle_request_ref_tokens (FlatpakAuthenticator *authenticator,
|
||||
const gchar *arg_handle_token,
|
||||
GVariant *arg_authenticator_option,
|
||||
const gchar *arg_remote,
|
||||
const gchar *const *arg_refs)
|
||||
GVariant *arg_refs)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GSocketService) server = NULL;
|
||||
@@ -182,6 +182,8 @@ handle_request_ref_tokens (FlatpakAuthenticator *authenticator,
|
||||
g_autofree char *request_path = NULL;
|
||||
guint16 port;
|
||||
TokenRequestData *data;
|
||||
g_autoptr(GPtrArray) refs = NULL;
|
||||
gsize n_refs, i;
|
||||
|
||||
g_debug ("handling RequestRefTokens");
|
||||
|
||||
@@ -213,7 +215,18 @@ handle_request_ref_tokens (FlatpakAuthenticator *authenticator,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
data = token_request_data_new (invocation, request, server, arg_refs);
|
||||
refs = g_ptr_array_new_with_free_func (g_free);
|
||||
n_refs = g_variant_n_children (arg_refs);
|
||||
for (i = 0; i < n_refs; i++)
|
||||
{
|
||||
const char *ref;
|
||||
gint32 token_type;
|
||||
g_variant_get_child (arg_refs, i, "(&si)", &ref, &token_type);
|
||||
g_ptr_array_add (refs, g_strdup (ref));
|
||||
}
|
||||
g_ptr_array_add (refs, NULL);
|
||||
|
||||
data = token_request_data_new (invocation, request, server, (const char *const*)refs->pdata);
|
||||
|
||||
g_signal_connect (server, "incoming", (GCallback)http_incoming, data);
|
||||
g_signal_connect (request, "handle-close", G_CALLBACK (handle_request_close), data);
|
||||
|
||||
Reference in New Issue
Block a user