getCurrentProfile function

Future<Profile> getCurrentProfile(
  1. AccessToken accessToken
)

Get's the Minecraft profile for the currently logged in user. This requires a valid access token.

Implementation

Future<Profile> getCurrentProfile(AccessToken accessToken) async {
  final response = await request(
      http.get, _minecraftServicesApi, 'minecraft/profile',
      headers: {
        'authorization': 'Bearer $accessToken',
      });
  if (response.statusCode == 401) {
    throw AuthException(AuthException.invalidCredentialsMessage);
  }

  final map = parseResponseMap(response);
  if (map['error'] != null) {
    if (map['error'] == 'NOT_FOUND') {
      throw Exception('The player does not own the game.');
    } else {
      throw Exception(map['error'] as String);
    }
  }
  return Profile.fromJson(map);
}