Implement token_refresh
This commit is contained in:
parent
46b5f5d918
commit
8b332eaaea
@ -1707,11 +1707,15 @@ matrix_api_login(MatrixAPI *api,
|
||||
* finished
|
||||
* @user_data: (closure): user data to pass to the callback function
|
||||
* @callback
|
||||
* @refresh_token: the refresh token that was issued by the server
|
||||
* @refresh_token: (allow-none): the refresh token that was issued by
|
||||
* the server
|
||||
* @error: return location for a #GError, or %NULL
|
||||
*
|
||||
* Exchanges a refresh token for a new access token. This is intended
|
||||
* to be used if the access token has expired.
|
||||
* to be used if the access token has expired. If @refresh_token is
|
||||
* %NULL, iplementations MUST send the stored refresh token. If it is
|
||||
* not pesent (e.g. because login hasn’t happened yet), this function
|
||||
* MUST yield an error.
|
||||
*/
|
||||
void
|
||||
matrix_api_token_refresh(MatrixAPI *api,
|
||||
|
@ -2245,6 +2245,48 @@ i_whois(MatrixAPI *api,
|
||||
g_free(path);
|
||||
}
|
||||
|
||||
static void
|
||||
i_token_refresh(MatrixAPI *api,
|
||||
MatrixAPICallback callback,
|
||||
gpointer user_data,
|
||||
const gchar *refresh_token,
|
||||
GError **error)
|
||||
{
|
||||
MatrixHTTPAPIPrivate *priv = matrix_http_api_get_instance_private(
|
||||
MATRIX_HTTP_API(api));
|
||||
JsonBuilder *builder;
|
||||
JsonNode *body;
|
||||
|
||||
if (!refresh_token && !priv->token) {
|
||||
g_set_error(error,
|
||||
MATRIX_API_ERROR, MATRIX_API_ERROR_MISSING_TOKEN,
|
||||
"No token available");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
builder = json_builder_new();
|
||||
json_builder_begin_object(builder);
|
||||
|
||||
json_builder_set_member_name(builder, "refresh_token");
|
||||
|
||||
if (!refresh_token) {
|
||||
json_builder_add_string_value(builder, priv->refresh_token);
|
||||
} else {
|
||||
json_builder_add_string_value(builder, refresh_token);
|
||||
}
|
||||
|
||||
json_builder_end_object(builder);
|
||||
body = json_builder_get_root(builder);
|
||||
g_object_unref(builder);
|
||||
|
||||
_send(MATRIX_HTTP_API(api),
|
||||
callback, user_data,
|
||||
CALL_API,
|
||||
"POST", "tokenreresh", NULL, NULL, body, NULL,
|
||||
FALSE, error);
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_http_api_matrix_api_init(MatrixAPIInterface *iface)
|
||||
{
|
||||
@ -2319,7 +2361,7 @@ matrix_http_api_matrix_api_init(MatrixAPIInterface *iface)
|
||||
|
||||
/* Session management */
|
||||
iface->login = i_login;
|
||||
iface->token_refresh = NULL;
|
||||
iface->token_refresh = i_token_refresh;
|
||||
|
||||
/* User data */
|
||||
iface->get_3pids = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user