aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDr. David Alan Gilbert <dave@treblig.org>2018-04-02 22:08:46 +0100
committerDr. David Alan Gilbert <dave@treblig.org>2019-12-28 18:41:04 +0000
commit32995caa9606c80a1752ae54fa4a9250a60ccde3 (patch)
tree3cd5f2d870021cf56607ef2e09b3587e68d482a1
parent13e8a553d1e8ab49be446a90b2adf8762bbbafe6 (diff)
downloadpurple-matrix-32995caa9606c80a1752ae54fa4a9250a60ccde3.tar.gz
api: Add whoami
Add the 'whoami' api call, as a means to validate an access token Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
-rw-r--r--matrix-api.c25
-rw-r--r--matrix-api.h21
2 files changed, 46 insertions, 0 deletions
diff --git a/matrix-api.c b/matrix-api.c
index fb80cb9..7f52d7f 100644
--- a/matrix-api.c
+++ b/matrix-api.c
@@ -1011,6 +1011,31 @@ MatrixApiRequestData *matrix_api_download_thumb(MatrixConnectionData *conn,
return fetch_data;
}
+/**
+ * Returns the userid for our access token, mostly as a check our token
+ * is valid.
+ */
+MatrixApiRequestData *matrix_api_whoami(MatrixConnectionData *conn,
+ MatrixApiCallback callback,
+ MatrixApiErrorCallback error_callback,
+ MatrixApiBadResponseCallback bad_response_callback,
+ gpointer user_data)
+{
+ GString *url;
+ MatrixApiRequestData *fetch_data;
+
+ url = g_string_new(conn->homeserver);
+ g_string_append_printf(url,
+ "_matrix/client/r0/account/whoami?access_token=%s",
+ purple_url_encode(conn->access_token));
+
+ fetch_data = matrix_api_start(url->str, "GET", NULL, conn, callback,
+ error_callback, bad_response_callback, user_data, 10*1024);
+ g_string_free(url, TRUE);
+
+ return fetch_data;
+}
+
MatrixApiRequestData *matrix_api_upload_keys(MatrixConnectionData *conn,
JsonObject *device_keys, JsonObject *one_time_keys,
MatrixApiCallback callback,
diff --git a/matrix-api.h b/matrix-api.h
index 763f587..6a22a40 100644
--- a/matrix-api.h
+++ b/matrix-api.h
@@ -363,6 +363,27 @@ MatrixApiRequestData *matrix_api_download_thumb(MatrixConnectionData *conn,
gpointer user_data);
/**
+ * Returns the userid for our access token, mostly as a check our token
+ * is valid.
+ *
+ * @param conn The connection with which to make the request
+ * @param callback Function to be called when the request completes
+ * @param error_callback Function to be called if there is an error making
+ * the request. If NULL, matrix_api_error will be
+ * used.
+ * @param bad_response_callback Function to be called if the API gives a non-200
+ * response. If NULL, matrix_api_bad_response will be
+ * used.
+ * @param user_data Opaque data to be passed to the callbacks
+ *
+ */
+MatrixApiRequestData *matrix_api_whoami(MatrixConnectionData *conn,
+ MatrixApiCallback callback,
+ MatrixApiErrorCallback error_callback,
+ MatrixApiBadResponseCallback bad_response_callback,
+ gpointer user_data);
+
+/**
* e2e: Upload keys; one or more of the device keys and the one time keys
* @param conn The connection with which to make the request
* @param device_keys (optional) Json Object with the signed device keys