Skip to content

Commit

Permalink
feat: Added method for sns re-authentication.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Dec 28, 2023
1 parent ee53a04 commit 6689ef0
Show file tree
Hide file tree
Showing 13 changed files with 562 additions and 364 deletions.
2 changes: 1 addition & 1 deletion packages/masamune_auth_apple/lib/masamune_auth_apple.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ import 'package:masamune/masamune.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';

part 'adapter/apple_auth_masamune_adapter.dart';
part 'provider/apple_sign_in_auth_provider.dart';
part 'provider/apple_auth_query.dart';
96 changes: 96 additions & 0 deletions packages/masamune_auth_apple/lib/provider/apple_auth_query.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
part of '/masamune_auth_apple.dart';

const _kAppleAuthProviderId = "apple.com";

/// {@template apple_auth}
/// An `AuthQuery` to authenticate with your Apple account.
///
/// [signIn] and [reauth] are available.
///
/// Appleアカウントでの認証を行うための`AuthQuery`
///
/// [signIn]および[reauth]が利用可能です。
/// {@endtemplate}
class AppleAuthQuery {
const AppleAuthQuery._();

/// ID that defines the provider's process.
///
/// Basically, it is defined based on firebase's `PROVIDER_ID`.
///
/// プロバイダーの処理を定義したID。
///
/// 基本的にfirebaseの`PROVIDER_ID`をベースに定義されます。
static const String providerId = _kAppleAuthProviderId;

/// [AuthProvider] for performing [Authentication.signIn].
///
/// [Authentication.signIn]を実行するための[AuthProvider]
///
/// {@macro apple_auth}
static AppleSignInAuthProvider signIn() {
return const AppleSignInAuthProvider();
}

/// [AuthProvider] for performing [Authentication.reauth].
///
/// [Authentication.reauth]を実行するための[AuthProvider]
///
/// {@macro apple_auth}
static AppleReAuthProvider reauth() {
return const AppleReAuthProvider();
}
}

/// An `AuthQuery` for Apple's OAuth authentication.
///
/// AppleのOAuth認証を行うための`AuthQuery`
class AppleSignInAuthProvider extends SnsSignInAuthProvider {
/// An `AuthQuery` for Apple's OAuth authentication.
///
/// AppleのOAuth認証を行うための`AuthQuery`
const AppleSignInAuthProvider();

@override
String get providerId => _kAppleAuthProviderId;

@override
Future<Credential> credential() async {
// final adapter = AppleAuthMasamuneAdapter.primary;
final credentials = await SignInWithApple.getAppleIDCredential(
scopes: [
AppleIDAuthorizationScopes.email,
AppleIDAuthorizationScopes.fullName,
],
);
if (credentials.identityToken.isEmpty ||
credentials.authorizationCode.isEmpty) {
throw Exception(
"Login failed because the authentication information cannot be found.",
);
}
return Credential(
providerId: providerId,
idToken: credentials.identityToken,
accessToken: credentials.authorizationCode,
);
}
}

/// An `AuthQuery` for Apple's OAuth re-authentication.
///
/// AppleのOAuth再認証を行うための`AuthQuery`
class AppleReAuthProvider extends SnsReAuthProvider {
/// An `AuthQuery` for Apple's OAuth re-authentication.
///
/// AppleのOAuth再認証を行うための`AuthQuery`
const AppleReAuthProvider();

static const _signInProvider = AppleSignInAuthProvider();

@override
String get providerId => _signInProvider.providerId;

@override
Future<Credential> credential() => _signInProvider.credential();
}

This file was deleted.

Loading

0 comments on commit 6689ef0

Please sign in to comment.