diff options
author | Milan Crha <mcrha@redhat.com> | 2023-02-01 11:28:34 +0100 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2023-02-01 11:30:36 +0100 |
commit | b8e662bc105152ac430f9a4b8977a72d559e9483 (patch) | |
tree | f3d54a81b509025d1a48090af5caf5eb2f24726d | |
parent | 343ebd9a9a3b162dd37d09e229b729af7cfc8698 (diff) | |
download | evolution-data-server-b8e662bc105152ac430f9a4b8977a72d559e9483.tar.gz |
OAuth2: Extract returned information from URI query or fragment
The server can return requested information, or an error, either
in the URI's query or in the fragment. Let the code try both places.
-rw-r--r-- | src/libedataserver/e-oauth2-service.c | 69 |
1 files changed, 47 insertions, 22 deletions
diff --git a/src/libedataserver/e-oauth2-service.c b/src/libedataserver/e-oauth2-service.c index 61b3b964e..7eca355df 100644 --- a/src/libedataserver/e-oauth2-service.c +++ b/src/libedataserver/e-oauth2-service.c @@ -1931,6 +1931,42 @@ e_oauth2_service_util_take_to_form (GHashTable *form, g_hash_table_remove (form, name); } +static gboolean +eos_util_extract_from_form (GHashTable *form, + gchar **out_authorization_code, + gchar **out_error_code, + gchar **out_error_description) +{ + gboolean any_set = FALSE; + const gchar *value; + + if (!form) + return FALSE; + + value = g_hash_table_lookup (form, "code"); + + if (value && *value && out_authorization_code) { + any_set = TRUE; + *out_authorization_code = g_strdup (value); + } else { + value = g_hash_table_lookup (form, "error"); + + if (value && *value && out_error_code) { + any_set = TRUE; + *out_error_code = g_strdup (value); + } + + value = g_hash_table_lookup (form, "error_description"); + + if (value && *value && out_error_description) { + any_set = TRUE; + *out_error_description = g_strdup (value); + } + } + + return any_set; +} + /** * e_oauth2_service_util_extract_from_uri: * @in_uri: a URI returned from the server @@ -1963,33 +1999,22 @@ e_oauth2_service_util_extract_from_uri (const gchar *in_uri, return FALSE; if (g_uri_get_query (uri)) { - GHashTable *uri_query = soup_form_decode (g_uri_get_query (uri)); - - if (uri_query) { - const gchar *value; + GHashTable *form = soup_form_decode (g_uri_get_query (uri)); - value = g_hash_table_lookup (uri_query, "code"); + if (form) { + any_set = eos_util_extract_from_form (form, out_authorization_code, out_error_code, out_error_description); - if (value && *value && out_authorization_code) { - any_set = TRUE; - *out_authorization_code = g_strdup (value); - } else { - value = g_hash_table_lookup (uri_query, "error"); - - if (value && *value && out_error_code) { - any_set = TRUE; - *out_error_code = g_strdup (value); - } + g_hash_table_unref (form); + } + } - value = g_hash_table_lookup (uri_query, "error_description"); + if (!any_set && g_uri_get_fragment (uri)) { + GHashTable *form = soup_form_decode (g_uri_get_fragment (uri)); - if (value && *value && out_error_description) { - any_set = TRUE; - *out_error_description = g_strdup (value); - } - } + if (form) { + any_set = eos_util_extract_from_form (form, out_authorization_code, out_error_code, out_error_description); - g_hash_table_unref (uri_query); + g_hash_table_unref (form); } } |