-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added method for sns re-authentication.
- Loading branch information
Showing
13 changed files
with
562 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
packages/masamune_auth_apple/lib/provider/apple_auth_query.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
36 changes: 0 additions & 36 deletions
36
packages/masamune_auth_apple/lib/provider/apple_sign_in_auth_provider.dart
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.