-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
586 additions
and
4 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
Empty file.
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,30 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
/pubspec.lock | ||
**/doc/api/ | ||
.dart_tool/ | ||
.packages | ||
build/ |
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,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: ffccd96b62ee8cec7740dab303538c5fc26ac543 | ||
channel: stable | ||
|
||
project_type: package |
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,3 @@ | ||
## 0.1.0 | ||
|
||
* initial release. |
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,39 @@ | ||
<!-- | ||
This README describes the package. If you publish this package to pub.dev, | ||
this README's contents appear on the landing page for your package. | ||
For information about how to write a good package README, see the guide for | ||
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages). | ||
For general information about developing packages, see the Dart guide for | ||
[creating packages](https://dart.dev/guides/libraries/create-library-packages) | ||
and the Flutter guide for | ||
[developing packages and plugins](https://flutter.dev/developing-packages). | ||
--> | ||
|
||
TODO: Put a short description of the package here that helps potential users | ||
know whether this package might be useful for them. | ||
|
||
## Features | ||
|
||
TODO: List what your package can do. Maybe include images, gifs, or videos. | ||
|
||
## Getting started | ||
|
||
TODO: List prerequisites and provide or point to information on how to | ||
start using the package. | ||
|
||
## Usage | ||
|
||
TODO: Include short and useful examples for package users. Add longer examples | ||
to `/example` folder. | ||
|
||
```dart | ||
const like = 'sample'; | ||
``` | ||
|
||
## Additional information | ||
|
||
TODO: Tell users more about the package: where to find more information, how to | ||
contribute to the package, how to file issues, what response they can expect | ||
from the package authors, and more. |
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 @@ | ||
include: package:altive_lints/altive_lints.yaml |
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,15 @@ | ||
/// flutterfire_authenticator with FlutterFire Authentication. | ||
library flutterfire_authenticator; | ||
|
||
export 'package:firebase_auth/firebase_auth.dart' | ||
show | ||
AuthCredential, | ||
OAuthCredential, | ||
OAuthProvider, | ||
PhoneAuthProvider, | ||
UserCredential; | ||
|
||
export 'src/auth_exception.dart'; | ||
export 'src/authenticator.dart'; | ||
export 'src/signing_method.dart'; | ||
export 'src/user_extension.dart'; |
45 changes: 45 additions & 0 deletions
45
packages/flutterfire_authenticator/lib/src/apple_authenticator.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,45 @@ | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
|
||
import '../authenticator.dart'; | ||
import 'authenticatable.dart'; | ||
|
||
class AppleAuthenticator implements Authenticatable { | ||
AppleAuthenticator(this._auth); | ||
|
||
final FirebaseAuth _auth; | ||
|
||
final authProvider = AppleAuthProvider(); | ||
|
||
User get _user => _auth.currentUser!; | ||
|
||
/// 既にAppleでサインイン済みなら`true` | ||
@override | ||
bool get alreadySigned => _auth.currentUser?.hasAppleSigning ?? false; | ||
|
||
@override | ||
Future<UserCredential> signIn([AuthCredential? credential]) async { | ||
if (kIsWeb) { | ||
final userCredential = await _auth.signInWithPopup(authProvider); | ||
return userCredential; | ||
} else { | ||
final userCredential = await _auth.signInWithProvider(authProvider); | ||
return userCredential; | ||
} | ||
} | ||
|
||
@override | ||
Future<UserCredential> reauthenticate([AuthCredential? credential]) async { | ||
return _auth.currentUser!.reauthenticateWithProvider(authProvider); | ||
} | ||
|
||
@override | ||
Future<UserCredential> link([AuthCredential? credential]) async { | ||
return _user.linkWithProvider(authProvider); | ||
} | ||
|
||
@override | ||
Future<User> unlink() async { | ||
return _user.unlink(SigningMethod.apple.providerId); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
packages/flutterfire_authenticator/lib/src/auth_exception.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,71 @@ | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
|
||
/// 認証で発生したエラーを判別するためのエラークラス。 | ||
/// FirebaseAuthExceptionから生成する。 | ||
sealed class AuthException implements Exception { | ||
factory AuthException.fromError(FirebaseAuthException e) { | ||
return switch (e.code) { | ||
// Google認証でキャンセルした場合は「cancel」が返ってくる | ||
// Apple認証でキャンセルした場合は「canceled」が返ってくる | ||
'cancel' || 'canceled' => const AuthCancelled(), | ||
'requires-recent-login' => const AuthRequiresReLogin(), | ||
'invalid-phone-number' => const AuthInvalidPhoneNumber(), | ||
'credential-already-in-use' => const AuthCredentialAlreadyInUse(), | ||
'network-request-failed' => const AuthNetworkError(), | ||
// 'email-already-in-use' => const , | ||
// 'provider-already-linked' => const , | ||
// 'too-many-requests' => const , | ||
// 'account-exists-with-different-credential' => const , | ||
// 'invalid-credential' => const , | ||
// 'user-disabled' => const , | ||
_ => const AuthUndefinedError(), | ||
}; | ||
} | ||
|
||
@override | ||
String toString() => message; | ||
|
||
String get message; | ||
} | ||
|
||
class AuthCancelled implements AuthException { | ||
const AuthCancelled(); | ||
|
||
@override | ||
String get message => '認証がキャンセルされました'; | ||
} | ||
|
||
class AuthRequiresReLogin implements AuthException { | ||
const AuthRequiresReLogin(); | ||
|
||
@override | ||
String get message => '再ログインが必要です'; | ||
} | ||
|
||
class AuthInvalidPhoneNumber implements AuthException { | ||
const AuthInvalidPhoneNumber(); | ||
|
||
@override | ||
String get message => '電話番号が不正です'; | ||
} | ||
|
||
class AuthCredentialAlreadyInUse implements AuthException { | ||
const AuthCredentialAlreadyInUse(); | ||
|
||
@override | ||
String get message => 'この認証情報はすでに使用されています'; | ||
} | ||
|
||
class AuthNetworkError implements AuthException { | ||
const AuthNetworkError(); | ||
|
||
@override | ||
String get message => 'ネットワークエラーが発生しました'; | ||
} | ||
|
||
class AuthUndefinedError implements AuthException { | ||
const AuthUndefinedError(); | ||
|
||
@override | ||
String get message => '予期せぬエラーが発生しました'; | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/flutterfire_authenticator/lib/src/authenticatable.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,30 @@ | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
|
||
abstract class Authenticatable { | ||
/// すでにサインイン済みかどうか。 | ||
bool get alreadySigned; | ||
|
||
/// サインイン。 | ||
/// | ||
/// 電話番号認証ではサインイン処理が2STEPに分かれており、 | ||
/// [AuthCredential]を外から渡す必要があるため、 | ||
/// オプショナル引数として[AuthCredential]を受け取る形にしている。 | ||
Future<UserCredential> signIn([AuthCredential? credential]); | ||
|
||
/// 再認証する。 | ||
/// | ||
/// 電話番号認証ではサインイン処理が2STEPに分かれており、 | ||
/// [AuthCredential]を外から渡す必要があるため、 | ||
/// オプショナル引数として[AuthCredential]を受け取る形にしている。 | ||
Future<UserCredential> reauthenticate([AuthCredential? credential]); | ||
|
||
/// ユーザーにAppleを紐付ける。 | ||
/// | ||
/// 電話番号認証ではサインイン処理が2STEPに分かれており、 | ||
/// [AuthCredential]を外から渡す必要があるため、 | ||
/// オプショナル引数として[AuthCredential]を受け取る形にしている。 | ||
Future<UserCredential> link([AuthCredential? credential]); | ||
|
||
/// Apple IDをリンク解除。 | ||
Future<User> unlink(); | ||
} |
Oops, something went wrong.