getTokenOwner method

Future<TokenOwnerInfo> getTokenOwner()
inherited

Gets information about the owner of a given access token.

Note that, as with the rest of the Client-Server API, Application Services may masquerade as users within their namespace by giving a user_id query parameter. In this situation, the server should verify that the given user_id is registered by the appservice, and return it in the response body.

Implementation

Future<TokenOwnerInfo> getTokenOwner() async {
  final requestUri = Uri(path: '_api/client/v3/account/whoami');
  final request = Request('GET', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  final response = await httpClient.send(request);
  final responseBody = await response.stream.toBytes();
  if (response.statusCode != 200) unexpectedResponse(response, responseBody);
  final responseString = utf8.decode(responseBody);
  final json = jsonDecode(responseString);
  return TokenOwnerInfo.fromJson(json as Map<String, Object?>);
}