Skip to content

Commit

Permalink
Implements authenticateGameCenter
Browse files Browse the repository at this point in the history
  • Loading branch information
obrunsmann committed Jun 3, 2021
1 parent eca603e commit f4bb443
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/src/nakama_client/nakama_api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,43 @@ class NakamaRestApiClient extends NakamaBaseClient {
);
}

@override
Future<model.Session> authenticateGameCenter({
required String playerId,
required String bundleId,
required int timestampSeconds,
required String salt,
required String signature,
required String publicKeyUrl,
bool create = true,
String? username,
}) async {
final res = await _api.nakamaAuthenticateGameCenter(
body: ApiAccountGameCenter(
playerId: playerId,
bundleId: bundleId,
timestampSeconds: timestampSeconds.toString(),
salt: salt,
signature: signature,
publicKeyUrl: publicKeyUrl,
),
create: create,
username: username,
);

if (res.body == null) {
throw Exception('Authentication failed.');
}

final data = res.body!;

return model.Session(
created: data.created ?? false,
token: data.token!,
refreshToken: data.refreshToken,
);
}

@override
Future<Account> getAccount(model.Session session) async {
_session = session;
Expand Down
11 changes: 11 additions & 0 deletions lib/src/nakama_client/nakama_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,16 @@ abstract class NakamaBaseClient {
String? username,
});

Future<model.Session> authenticateGameCenter({
required String playerId,
required String bundleId,
required int timestampSeconds,
required String salt,
required String signature,
required String publicKeyUrl,
bool create = true,
String? username,
});

Future<Account> getAccount(model.Session session);
}
35 changes: 35 additions & 0 deletions lib/src/nakama_client/nakama_grpc_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:nakama/api/apigrpc.pbgrpc.dart';
import 'package:grpc/grpc.dart';
import 'package:nakama/api/google/protobuf/empty.pb.dart';
import 'package:nakama/api/google/protobuf/wrappers.pbserver.dart';
import 'package:nakama/nakama.dart';
import 'package:nakama/src/session.dart' as model;

import 'nakama_client.dart';
Expand Down Expand Up @@ -190,6 +191,40 @@ class NakamaGrpcClient extends NakamaBaseClient {
);
}

@override
Future<model.Session> authenticateGameCenter({
required String playerId,
required String bundleId,
required int timestampSeconds,
required String salt,
required String signature,
required String publicKeyUrl,
bool create = true,
String? username,
}) async {
final request = AuthenticateGameCenterRequest()
..create_2 = BoolValue(value: create)
..account = (AccountGameCenter()
..playerId = playerId
..bundleId = bundleId
..timestampSeconds = Int64(timestampSeconds)
..salt = salt
..signature = signature
..publicKeyUrl = publicKeyUrl);

if (username != null) {
request.username = username;
}

final res = await _client.authenticateGameCenter(request);

return model.Session(
created: res.created,
token: res.token,
refreshToken: res.refreshToken,
);
}

@override
Future<Account> getAccount(model.Session session) {
return _client.getAccount(
Expand Down

0 comments on commit f4bb443

Please sign in to comment.