Skip to content
Draft
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
302720b
boilerplate remote config
TimWhiting Apr 24, 2022
e7fb658
start of dart
TimWhiting Apr 24, 2022
bff7c98
add in todos, fix static errors
TimWhiting Apr 24, 2022
dec2ddd
start on storage
TimWhiting Apr 24, 2022
e00a5d0
start on storage
TimWhiting Apr 24, 2022
de2506d
clean up some things
TimWhiting Apr 24, 2022
faa19a6
finish basic storage, move on to rest api
TimWhiting Apr 26, 2022
943ed17
finish dart package implementation
TimWhiting Apr 27, 2022
093c6e7
- move json serialization to dataclass
TimWhiting Apr 27, 2022
be121f0
start working on tests
TimWhiting Apr 27, 2022
76832c6
basic tests
TimWhiting Apr 28, 2022
dc87e69
start on example continue testing
TimWhiting Apr 28, 2022
11c44dd
get working with example app
TimWhiting May 14, 2022
5299781
remove firebaseapis
TimWhiting May 14, 2022
56401b6
remove reference to firebaseapis
TimWhiting May 14, 2022
ecdeec2
chore: upgrade `desktop_webview_auth` to v0.0.7
pr-Mais Apr 25, 2022
0d775b0
chore(release): publish packages
pr-Mais Apr 25, 2022
112e1f1
feat(firebase_auth_dart): web support (#72)
pr-Mais Apr 28, 2022
fe8d56b
feat(firebase_auth): Github auth provider (#74)
pr-Mais May 6, 2022
b71229a
chore(release): publish packages
pr-Mais May 6, 2022
e771a3f
refactor!: remove macOS support
pr-Mais May 9, 2022
9bbe72b
chore(release): publish packages
pr-Mais May 9, 2022
b45df7d
ci: remove macos tests job
pr-Mais May 9, 2022
1bfb131
fix(firebase_core): return existing app if options are matching if th…
pr-Mais May 11, 2022
6f6741c
chore(release): publish packages
pr-Mais May 11, 2022
f09fe11
firebaseapis
TimWhiting May 19, 2022
fb8efa7
some more attempts at fixing
TimWhiting May 19, 2022
3478130
fix using clientViaApiKey
TimWhiting May 20, 2022
5cb057c
Merge remote-tracking branch 'upstream/main' into remote_config
TimWhiting May 20, 2022
841ccdb
fix analyzer errors and pubspec
TimWhiting May 20, 2022
cf4c71b
start on fixing tests
TimWhiting May 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 52 additions & 52 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,55 +89,55 @@ jobs:
working-directory: tests
run: cmd /c flutter drive -d windows --no-pub --target=./test_driver/driver_e2e.dart --dart-define=CI=true

test_macos:
runs-on: macos-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-node@v2
name: Install Node.js 12
with:
node-version: '12'
- uses: hendrikmuhs/ccache-action@v1
name: Xcode Compile Cache
with:
key: ${{ runner.os }}-macos-v2
max-size: 700M
- uses: actions/cache@v2
name: Pods Cache
id: pods-cache
with:
path: tests/macos/Pods
key: ${{ runner.os }}-pods-v2-${{ hashFiles('tests/macos/Podfile.lock') }}
restore-keys: ${{ runner.os }}-macos-pods-v1
- name: Cache Firebase Emulator
uses: actions/cache@v2
with:
path: ~/.cache/firebase/emulators
key: firebase-emulators-v1-${{ github.run_id }}
restore-keys: firebase-emulators-v1
- name: 'Install Flutter'
run: ./.github/workflows/scripts/install-flutter.sh stable
- name: 'Install Tools'
run: |
./.github/workflows/scripts/install-tools.sh
flutter config --enable-macos-desktop
sudo npm i -g firebase-tools
- name: 'Build Application'
working-directory: tests
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
export CCACHE_SLOPPINESS=clang_index_store,file_stat_matches,include_file_ctime,include_file_mtime,ivfsoverlay,pch_defines,modules,system_headers,time_macros
export CCACHE_FILECLONE=true
export CCACHE_DEPEND=true
export CCACHE_INODECACHE=true
ccache -s
flutter build macos --debug --target=./test_driver/driver_e2e.dart --device-id=macos --dart-define=CI=true
ccache -s
- name: Start Firebase Emulator
run: cd ./.github/workflows/scripts && ./start-firebase-emulator.sh
- name: 'Run Tests'
working-directory: tests
run: flutter drive -d macos --no-pub --target=./test_driver/driver_e2e.dart --dart-define=CI=true
# test_macos:
# runs-on: macos-latest
# timeout-minutes: 20
# steps:
# - uses: actions/checkout@v2
# with:
# fetch-depth: 0
# - uses: actions/setup-node@v2
# name: Install Node.js 12
# with:
# node-version: '12'
# - uses: hendrikmuhs/ccache-action@v1
# name: Xcode Compile Cache
# with:
# key: ${{ runner.os }}-macos-v2
# max-size: 700M
# - uses: actions/cache@v2
# name: Pods Cache
# id: pods-cache
# with:
# path: tests/macos/Pods
# key: ${{ runner.os }}-pods-v2-${{ hashFiles('tests/macos/Podfile.lock') }}
# restore-keys: ${{ runner.os }}-macos-pods-v1
# - name: Cache Firebase Emulator
# uses: actions/cache@v2
# with:
# path: ~/.cache/firebase/emulators
# key: firebase-emulators-v1-${{ github.run_id }}
# restore-keys: firebase-emulators-v1
# - name: 'Install Flutter'
# run: ./.github/workflows/scripts/install-flutter.sh stable
# - name: 'Install Tools'
# run: |
# ./.github/workflows/scripts/install-tools.sh
# flutter config --enable-macos-desktop
# sudo npm i -g firebase-tools
# - name: 'Build Application'
# working-directory: tests
# run: |
# export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
# export CCACHE_SLOPPINESS=clang_index_store,file_stat_matches,include_file_ctime,include_file_mtime,ivfsoverlay,pch_defines,modules,system_headers,time_macros
# export CCACHE_FILECLONE=true
# export CCACHE_DEPEND=true
# export CCACHE_INODECACHE=true
# ccache -s
# flutter build macos --debug --target=./test_driver/driver_e2e.dart --device-id=macos --dart-define=CI=true
# ccache -s
# - name: Start Firebase Emulator
# run: cd ./.github/workflows/scripts && ./start-firebase-emulator.sh
# - name: 'Run Tests'
# working-directory: tests
# run: flutter drive -d macos --no-pub --target=./test_driver/driver_e2e.dart --dart-define=CI=true
16 changes: 16 additions & 0 deletions packages/firebase_auth/firebase_auth_dart/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## 1.0.0

- First stable release.

## 0.1.3

- **FEAT**: Github auth provider (#74).
- **FEAT**: web support (#72).

## 0.1.2

- **REFACTOR**: errors (#64).
- **REFACTOR**: 🔨 identity toolkit api layer (#61).
- **FEAT**: OAuth providers support (#65).
- **DOCS**: fix typo in import.

## 0.1.1

- Graduate package to a stable release. See pre-releases prior to this version for changelog entries.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ dependencies:
ansicolor: ^2.0.1
args: ^2.3.0
cli_util: ^0.3.5
firebase_auth_dart: ^0.1.1
firebase_core_dart: ^0.1.1
firebase_auth_dart: ^1.0.0
firebase_core_dart: ^1.0.0
dependency_overrides:
firebase_auth_dart:
path: ../
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
library firebase_auth_dart;

import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'dart:io';

import 'package:firebase_core_dart/firebase_core_dart.dart';
import 'package:http/http.dart' as http;
import 'package:meta/meta.dart';
import 'package:storagebox/storagebox.dart';

import 'src/api/api.dart';
import 'src/api/errors.dart';
Expand All @@ -32,6 +32,7 @@ export 'src/auth_provider.dart';
export 'src/firebase_auth_exception.dart';
export 'src/providers/email_auth.dart';
export 'src/providers/facebook_auth.dart';
export 'src/providers/github_auth.dart';
export 'src/providers/google_auth.dart';
export 'src/providers/oauth.dart';
export 'src/providers/phone_auth.dart';
Expand All @@ -46,4 +47,3 @@ part 'src/user.dart';
part 'src/user_credential.dart';
part 'src/user_info.dart';
part 'src/user_metadata.dart';
part 'src/utils/persistence.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ part 'authentication/sms.dart';
part 'authentication/token.dart';
part 'emulator.dart';

/// All API classes calling to IDP API must extend this template.
/// All API classes calling to Identity Toolkit API must extend this template.
abstract class APIDelegate {
/// Construct a new [APIDelegate].
const APIDelegate(this.api);

/// The [API] instance containing required configurations to make the requests.
final API api;

/// Convert [DetailedApiRequestError] thrown by idp to [FirebaseAuthException].
/// Convert [DetailedApiRequestError] thrown by Identity Toolkit to [FirebaseAuthException].
FirebaseAuthException makeAuthException(DetailedApiRequestError apiError) {
try {
final json = apiError.jsonResponse;
Expand Down Expand Up @@ -83,7 +83,7 @@ abstract class APIDelegate {
}
}

/// Configurations necessary for making all idp requests.
/// Configurations necessary for making all Identity Toolkit requests.
@protected
class APIConfig {
/// Construct [APIConfig].
Expand Down Expand Up @@ -133,7 +133,7 @@ abstract class SignInResponse {
}
}

/// A return type from Idp authentication requests, must be extended by any other response
/// A return type from Identity Toolkit authentication requests, must be extended by any other response
/// type for any operation that requires idToken.
@protected
abstract class IdTokenResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ part of api;
/// A return type from Idp phone authentication requests.
@internal
class SignInWithPhoneNumberResponse extends SignInResponse {
/// Construct a new [IdTokenResponse].
/// Construct a new [SignInWithPhoneNumberResponse].
SignInWithPhoneNumberResponse._({
required String idToken,
required String refreshToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ class IdToken extends APIDelegate {
// ignore: public_member_api_docs
IdToken(API api) : super(api);

/// Refresh a user ID token using the refreshToken,
/// Refresh a user's IdToken using a `refreshToken`,
/// will refresh even if the token hasn't expired.
///
/// Common error codes:
/// - `TOKEN_EXPIRED`: The user's credential is no longer valid. The user must sign in again.
/// - `USER_DISABLED`: The user account has been disabled by an administrator.
/// - `USER_NOT_FOUND`: The user corresponding to the refresh token was not found. It is likely the user was deleted.
/// - `INVALID_REFRESH_TOKEN`: An invalid refresh token is provided.
/// - `INVALID_GRANT_TYPE`: the grant type specified is invalid.
/// - `MISSING_REFRESH_TOKEN`: no refresh token provided.
/// - API key not valid. Please pass a valid API key. (invalid API key provided)
Future<String?> refreshIdToken(String? refreshToken) async {
try {
return await _exchangeRefreshWithIdToken(refreshToken);
} on HttpException catch (_) {
rethrow;
} catch (_) {
rethrow;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ class FirebaseAuth {
_api.client = client;
}

StorageBox<Object> get _userStorage =>
StorageBox.instanceOf(app.options.projectId);
StorageBox get _userStorage => StorageBox(
app.options.projectId,
configPathPrefix: '.firebase-auth',
);

Map<String, dynamic>? _localUser() {
try {
return (_userStorage.getValue('${app.options.apiKey}:${app.name}')
as Map<String, dynamic>)['currentUser'];
return (_userStorage['${app.options.apiKey}:${app.name}']
as Map<String, dynamic>?)?['currentUser'];
} catch (e) {
return null;
}
Expand Down Expand Up @@ -109,10 +111,11 @@ class FirebaseAuth {
@protected
void _updateCurrentUserAndEvents(User? user,
[bool authStateChanged = false]) {
_userStorage.putValue(
'${app.options.apiKey}:${app.name}',
{'currentUser': user?.toMap()},
);
_userStorage.addAll({
'${app.options.apiKey}:${app.name}': {
'currentUser': user?.toMap(),
},
});

_currentUser = user;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.

// ignore_for_file: require_trailing_commas, non_constant_identifier_names, prefer_relative_imports
// ignore_for_file: require_trailing_commas, non_constant_identifier_names, prefer_relative_imports, avoid_returning_this

import 'package:firebase_auth_dart/firebase_auth_dart.dart';

Expand Down Expand Up @@ -71,15 +71,13 @@ class FacebookAuthProvider extends AuthProvider {
}

/// Adds Facebook OAuth scope.
// ignore: avoid_returning_this
FacebookAuthProvider addScope(String scope) {
_scopes.add(scope);
return this;
}

/// Sets the OAuth custom parameters to pass in a Facebook OAuth
/// request for popup and redirect sign-in operations.
// ignore: avoid_returning_this
FacebookAuthProvider setCustomParameters(
Map<dynamic, dynamic> customOAuthParameters,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright 2021 Invertase Limited. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.

// ignore_for_file: require_trailing_commas, non_constant_identifier_names, prefer_relative_imports, avoid_returning_this

import 'package:firebase_auth_dart/firebase_auth_dart.dart';

const _kProviderId = 'github.com';

/// This class should be used to either create a new GitHub credential with an
/// access code, or use the provider to trigger user authentication flows.
///
/// If authenticating with GitHub via a 3rd party, use the returned
/// `accessToken` to sign-in or link the user with the created credential, for
/// example:
///
/// ```dart
/// String accessToken = '...'; // From 3rd party provider
/// var githubAuthCredential = GithubAuthProvider.credential(accessToken);
///
/// FirebaseAuth.instance.signInWithCredential(githubAuthCredential)
/// .then(...);
/// ```
class GithubAuthProvider extends AuthProvider {
/// Creates a new instance.
GithubAuthProvider() : super(_kProviderId);

/// Create a new [GithubAuthCredential] from a provided [accessToken];
static OAuthCredential credential(String accessToken) {
return GithubAuthCredential._credential(
accessToken,
);
}

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

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

final List<String> _scopes = [];
Map<dynamic, dynamic> _parameters = {};

/// Returns the currently assigned scopes to this provider instance.
List<String> get scopes {
return _scopes;
}

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

/// Adds GitHub OAuth scope.
GithubAuthProvider addScope(String scope) {
_scopes.add(scope);
return this;
}

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

/// The auth credential returned from calling
/// [GithubAuthProvider.credential].
class GithubAuthCredential extends OAuthCredential {
GithubAuthCredential._({
required String accessToken,
}) : super(
providerId: _kProviderId,
signInMethod: _kProviderId,
accessToken: accessToken);

factory GithubAuthCredential._credential(String accessToken) {
return GithubAuthCredential._(accessToken: accessToken);
}
}
Loading