Skip to content

Commit

Permalink
feat(auth, apple): Game Center sign-in support (#12228)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley committed Jan 31, 2024
1 parent 3c75bb5 commit ac625ec
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 135 deletions.
18 changes: 18 additions & 0 deletions docs/auth/federated-auth.md
Expand Up @@ -244,6 +244,24 @@ Future<UserCredential> signInWithApple() async {
}
```

## Apple Game Center (Apple only) {:#games}

Ensure the "Game Center" sign-in provider is enabled on the [Firebase Console](https://console.firebase.google.com/project/_/authentication/providers).
Follow these instructions for [Game Center Firebase project set-up](https://firebase.google.com/docs/auth/ios/game-center#before_you_begin).

You will need to login with Game Center before a Firebase Game Center credential can be issued and logged in via Firebase. [Here are some instructions](https://firebase.google.com/docs/auth/ios/game-center#integrate_game_center_sign-in_into_your_game)
on how that can be achieved.

* {iOS+}

```dart
Future<void> _signInWithGameCenter() async {
final credential = GameCenterAuthProvider.credential();
await FirebaseAuth.instance
.signInWithCredential(credential);
}
```

## Microsoft

* {iOS+}
Expand Down
Expand Up @@ -295,6 +295,7 @@
"${BUILT_PRODUCTS_DIR}/flutter_facebook_auth/flutter_facebook_auth.framework",
"${BUILT_PRODUCTS_DIR}/flutter_secure_storage/flutter_secure_storage.framework",
"${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework",
"${BUILT_PRODUCTS_DIR}/path_provider_foundation/path_provider_foundation.framework",
"${BUILT_PRODUCTS_DIR}/shared_preferences_foundation/shared_preferences_foundation.framework",
"${BUILT_PRODUCTS_DIR}/url_launcher_ios/url_launcher_ios.framework",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/FBAEMKit/FBAEMKit.framework/FBAEMKit",
Expand All @@ -321,6 +322,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_facebook_auth.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_secure_storage.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/nanopb.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider_foundation.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/shared_preferences_foundation.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/url_launcher_ios.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FBAEMKit.framework",
Expand Down
Expand Up @@ -8,5 +8,7 @@
<array>
<string>Default</string>
</array>
<key>com.apple.developer.game-center</key>
<true/>
</dict>
</plist>
409 changes: 274 additions & 135 deletions packages/firebase_auth/firebase_auth/ios/Classes/FLTFirebaseAuthPlugin.m

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/firebase_auth/firebase_auth/lib/firebase_auth.dart
Expand Up @@ -39,6 +39,8 @@ export 'package:firebase_auth_platform_interface/firebase_auth_platform_interfac
EmailAuthCredential,
FacebookAuthProvider,
FacebookAuthCredential,
GameCenterAuthProvider,
GameCenterAuthCredential,
PlayGamesAuthProvider,
PlayGamesAuthCredential,
GithubAuthProvider,
Expand Down
Expand Up @@ -28,6 +28,7 @@ export 'src/platform_interface/platform_interface_user_credential.dart';
export 'src/providers/apple_auth.dart';
export 'src/providers/email_auth.dart';
export 'src/providers/facebook_auth.dart';
export 'src/providers/game_center_auth.dart';
export 'src/providers/github_auth.dart';
export 'src/providers/google_auth.dart';
export 'src/providers/microsoft_auth.dart';
Expand Down
@@ -0,0 +1,68 @@
// Copyright 2024 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:firebase_auth_platform_interface/firebase_auth_platform_interface.dart';

const _kProviderId = 'gc.apple.com';

/// This class should be used to create a new Game Center credential
/// to trigger an authentication flow on Apple platform.
///
/// ```dart
/// // Requires authenticating with game center before proceeding with the below:
/// final gameCenterCredential = GameCenterAuthProvider.credential();
///
/// FirebaseAuth.instance.signInWithCredential(gameCenterCredential)
/// .then(...);
/// ```
class GameCenterAuthProvider extends AuthProvider {
/// Creates a new instance.
GameCenterAuthProvider() : super(_kProviderId);

/// Create a new [GameCenterAuthCredential] to be used on FlutterFire
/// Auth plugin only.
static OAuthCredential credential() {
return GameCenterAuthCredential._credential();
}

/// This corresponds to the sign-in method identifier.
static String get GAME_CENTER_SIGN_IN_METHOD {
return _kProviderId;
}

// ignore: public_member_api_docs
static String get PROVIDER_ID {
return _kProviderId;
}

Map<String, String> _parameters = {};

/// Returns the parameters for this provider instance.
Map<String, String> get parameters {
return _parameters;
}

/// Sets the OAuth custom parameters to pass in a Game Center OAuth request for
/// popup and redirect sign-in operations.
GameCenterAuthProvider setCustomParameters(
Map<String, String> customOAuthParameters,
) {
_parameters = customOAuthParameters;
return this;
}
}

/// The auth credential returned from calling
/// [GameCenterAuthProvider.credential].
class GameCenterAuthCredential extends OAuthCredential {
GameCenterAuthCredential._()
: super(
providerId: _kProviderId,
signInMethod: _kProviderId,
);

factory GameCenterAuthCredential._credential() {
return GameCenterAuthCredential._();
}
}

0 comments on commit ac625ec

Please sign in to comment.