From fa4d969ac6d8b6303b5501c993523d344a0ac183 Mon Sep 17 00:00:00 2001 From: Miguel Medeiros <31278849+miguelcmedeiros@users.noreply.github.com> Date: Fri, 21 May 2021 15:19:30 +0100 Subject: [PATCH 1/2] upgrade dependencies --- google_sign_in_dart/pubspec.lock | 143 ++++++++++++++++++------------- google_sign_in_dart/pubspec.yaml | 22 ++--- 2 files changed, 93 insertions(+), 72 deletions(-) diff --git a/google_sign_in_dart/pubspec.lock b/google_sign_in_dart/pubspec.lock index 2c1c10a0..7a713f80 100644 --- a/google_sign_in_dart/pubspec.lock +++ b/google_sign_in_dart/pubspec.lock @@ -7,70 +7,70 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.2" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.2" - convert: - dependency: transitive - description: - name: convert - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.1" + version: "1.15.0" crypto: dependency: "direct main" description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.1.5" + version: "3.0.1" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety" + version: "1.2.0" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" file: dependency: transitive description: name: file url: "https://pub.dartlang.org" source: hosted - version: "5.2.1" + version: "6.1.1" flutter: dependency: "direct main" description: flutter @@ -92,161 +92,168 @@ packages: name: google_sign_in url: "https://pub.dartlang.org" source: hosted - version: "4.5.3" + version: "5.0.3" google_sign_in_platform_interface: dependency: "direct main" description: name: google_sign_in_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "2.0.1" google_sign_in_web: dependency: transitive description: name: google_sign_in_web url: "https://pub.dartlang.org" source: hosted - version: "0.9.1+1" + version: "0.10.0" html_unescape: dependency: "direct main" description: name: html_unescape url: "https://pub.dartlang.org" source: hosted - version: "1.0.1+3" + version: "2.0.0" http: dependency: "direct main" description: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.12.2" + version: "0.13.3" http_parser: dependency: transitive description: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "3.1.3" - intl: - dependency: transitive - description: - name: intl - url: "https://pub.dartlang.org" - source: hosted - version: "0.16.1" + version: "4.0.0" js: dependency: transitive description: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.1+1" + version: "0.6.3" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety" + version: "0.12.10" meta: dependency: "direct main" description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.2" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety" + version: "1.8.0" path_provider_linux: dependency: transitive description: name: path_provider_linux url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+2" + version: "2.0.0" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "2.0.1" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" pedantic: dependency: transitive description: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.9.0" + version: "1.11.0" platform: dependency: transitive description: name: platform url: "https://pub.dartlang.org" source: hosted - version: "2.2.1" + version: "3.0.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "2.0.0" process: dependency: transitive description: name: process url: "https://pub.dartlang.org" source: hosted - version: "3.0.13" + version: "4.2.1" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "3.0.1" shared_preferences: dependency: "direct main" description: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "0.5.10" + version: "2.0.5" shared_preferences_linux: dependency: "direct main" description: name: shared_preferences_linux url: "https://pub.dartlang.org" source: hosted - version: "0.0.2+2" + version: "2.0.0" shared_preferences_macos: dependency: "direct main" description: name: shared_preferences_macos url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+10" + version: "2.0.0" shared_preferences_platform_interface: dependency: transitive description: name: shared_preferences_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "2.0.0" shared_preferences_web: dependency: transitive description: name: shared_preferences_web url: "https://pub.dartlang.org" source: hosted - version: "0.1.2+4" + version: "2.0.0" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" sky_engine: dependency: transitive description: flutter @@ -258,98 +265,112 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.2" + version: "1.3.0" url_launcher: dependency: "direct main" description: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "5.5.0" + version: "6.0.4" url_launcher_linux: dependency: transitive description: name: url_launcher_linux url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+1" + version: "2.0.0" url_launcher_macos: dependency: "direct main" description: name: url_launcher_macos url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+7" + version: "2.0.0" url_launcher_platform_interface: dependency: transitive description: name: url_launcher_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.6" + version: "2.0.3" url_launcher_web: dependency: transitive description: name: url_launcher_web url: "https://pub.dartlang.org" source: hosted - version: "0.1.1+1" + version: "2.0.0" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.2" + version: "2.1.0" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" xdg_directories: dependency: transitive description: name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "0.1.2" + version: "0.2.0" sdks: - dart: ">=2.10.0-0.0.dev <2.10.0" - flutter: ">=1.12.13+hotfix.5 <2.0.0" + dart: ">=2.12.0 <3.0.0" + flutter: ">=1.22.0" diff --git a/google_sign_in_dart/pubspec.yaml b/google_sign_in_dart/pubspec.yaml index 2084ac8b..066c70a1 100644 --- a/google_sign_in_dart/pubspec.yaml +++ b/google_sign_in_dart/pubspec.yaml @@ -10,17 +10,17 @@ environment: dependencies: flutter: sdk: flutter - google_sign_in: ^4.5.3 - google_sign_in_platform_interface: ^1.1.2 - shared_preferences: ^0.5.10 - shared_preferences_macos: ^0.0.1+10 - shared_preferences_linux: ^0.0.2+2 - url_launcher: ^5.5.0 - url_launcher_macos: ^0.0.1+7 - meta: ^1.2.2 - crypto: ^2.1.5 - http: ^0.12.2 - html_unescape: ^1.0.1+3 + google_sign_in: ^5.0.3 + google_sign_in_platform_interface: ^2.0.1 + shared_preferences: ^2.0.5 + shared_preferences_macos: ^2.0.0 + shared_preferences_linux: ^2.0.0 + url_launcher: ^6.0.4 + url_launcher_macos: ^2.0.0 + meta: ^1.3.0 + crypto: ^3.0.1 + http: ^0.13.3 + html_unescape: ^2.0.0 dev_dependencies: flutter_test: From 4f88c3fc6f5a262824fc6dd82b7e4050466c0f02 Mon Sep 17 00:00:00 2001 From: Miguel Medeiros <31278849+miguelcmedeiros@users.noreply.github.com> Date: Fri, 21 May 2021 17:26:15 +0200 Subject: [PATCH 2/2] Migrate to null safety --- .../lib/google_sign_in_dartio.dart | 96 +++++++++---------- .../lib/src/code_exchange_sing_in.dart | 49 +++++----- google_sign_in_dart/lib/src/crypto.dart | 5 +- google_sign_in_dart/lib/src/data_storage.dart | 48 +++++----- .../lib/src/token_sign_in.dart | 40 ++++---- google_sign_in_dart/pubspec.yaml | 2 +- 6 files changed, 113 insertions(+), 127 deletions(-) diff --git a/google_sign_in_dart/lib/google_sign_in_dartio.dart b/google_sign_in_dart/lib/google_sign_in_dartio.dart index 0b06b945..2be4426f 100644 --- a/google_sign_in_dart/lib/google_sign_in_dartio.dart +++ b/google_sign_in_dart/lib/google_sign_in_dartio.dart @@ -13,7 +13,6 @@ import 'package:google_sign_in/google_sign_in.dart'; import 'package:google_sign_in_platform_interface/google_sign_in_platform_interface.dart' as platform; import 'package:http/http.dart'; -import 'package:meta/meta.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -30,16 +29,13 @@ typedef UrlPresenter = void Function(Uri uri); /// Implementation of the google_sign_in plugin in pure dart. class GoogleSignInDart extends platform.GoogleSignInPlatform { GoogleSignInDart._({ - @required DataStorage storage, - @required String clientId, - @required UrlPresenter presenter, - String exchangeEndpoint, - String successUrl, - String failUrl, - }) : assert(storage != null), - assert(clientId != null), - assert(presenter != null), - _storage = storage, + required DataStorage storage, + required String clientId, + required UrlPresenter presenter, + String? exchangeEndpoint, + String? successUrl, + String? failUrl, + }) : _storage = storage, _clientId = clientId, _presenter = presenter, _exchangeEndpoint = exchangeEndpoint, @@ -52,12 +48,12 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform { /// the tokens is a secure, long-lived location that is accessible between /// different invocations of your application. static Future register({ - @required String clientId, - String exchangeEndpoint, - DataStorage storage, - UrlPresenter presenter, - String successUrl, - String failUrl, + required String clientId, + String? exchangeEndpoint, + DataStorage? storage, + UrlPresenter? presenter, + String? successUrl, + String? failUrl, }) async { presenter ??= (Uri uri) => launch(uri.toString()); @@ -87,19 +83,19 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform { ); } - final String _exchangeEndpoint; + final String? _exchangeEndpoint; final String _clientId; final DataStorage _storage; - final String _successUrl; - final String _failUrl; + final String? _successUrl; + final String? _failUrl; UrlPresenter _presenter; - List _scopes; - String _hostedDomain; + List? _scopes; + String? _hostedDomain; - platform.GoogleSignInTokenData _tokenData; - String _refreshToken; - DateTime _expiresAt; + platform.GoogleSignInTokenData? _tokenData; + String? _refreshToken; + DateTime? _expiresAt; /// Used by the sign in flow to allow opening of a browser in a platform /// specific way. @@ -109,16 +105,15 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform { UrlPresenter get presenter => _presenter; set presenter(UrlPresenter value) { - assert(value != null); _presenter = value; } @override Future init({ - @required String hostedDomain, + String? hostedDomain, List scopes = const [], platform.SignInOption signInOption = platform.SignInOption.standard, - String clientId, + String? clientId, }) async { assert(clientId == null || clientId == _clientId, 'ClientID ($clientId) does not match the one used to register the plugin $_clientId.'); @@ -128,7 +123,7 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform { 'Check https://developers.google.com/identity/protocols/googlescopes ' 'for a list of valid OAuth 2.0 scopes.'); - if (scopes == null || scopes.isEmpty) { + if (scopes.isEmpty) { _scopes = const ['openid', 'email', 'profile']; } else { _scopes = scopes; @@ -138,7 +133,7 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform { } @override - Future signInSilently() async { + Future signInSilently() async { if (_haveValidToken) { return _storage.userData; } else if (_refreshToken != null) { @@ -155,9 +150,9 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform { } @override - Future signIn() async { + Future signIn() async { if (_haveValidToken) { - final platform.GoogleSignInUserData userData = _storage.userData; + final platform.GoogleSignInUserData? userData = _storage.userData; if (userData == null) { await _fetchUserProfile(); } @@ -170,21 +165,21 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform { @override Future getTokens( - {String email, bool shouldRecoverAuth}) async { + {required String email, bool? shouldRecoverAuth}) async { if (_haveValidToken) { - return _tokenData; + return _tokenData!; } else if (_refreshToken != null) { // if refreshing the token fails, and shouldRecoverAuth is true, then we // will prompt the user to login again try { await _doTokenRefresh(); - return _tokenData; + return _tokenData!; } catch (_) {} } - if (shouldRecoverAuth) { + if (shouldRecoverAuth!) { await _performSignIn(_scopes); - return _tokenData; + return _tokenData!; } else { throw PlatformException( code: GoogleSignInAccount.kUserRecoverableAuthError); @@ -219,7 +214,7 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform { } @override - Future clearAuthCache({String token}) async { + Future clearAuthCache({String? token}) async { await _revokeToken(); _storage.clear(); _initFromStore(); @@ -244,7 +239,8 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform { Future _revokeToken() async { if (_haveValidToken) { await get( - 'https://oauth2.googleapis.com/revoke?token=${_tokenData.accessToken}', + Uri.parse( + 'https://oauth2.googleapis.com/revoke?token=${_tokenData!.accessToken}'), headers: { 'content-type': 'application/x-www-form-urlencoded' }, @@ -254,9 +250,9 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform { Future _fetchUserProfile() async { if (_haveValidToken) { - final String token = _tokenData.accessToken; + final String? token = _tokenData!.accessToken; final Response response = await get( - 'https://openidconnect.googleapis.com/v1/userinfo', + Uri.parse('https://openidconnect.googleapis.com/v1/userinfo'), headers: { 'Authorization': 'Bearer $token', }, @@ -278,23 +274,23 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform { } bool get _haveValidToken { - return _expiresAt != null && DateTime.now().isBefore(_expiresAt); + return _expiresAt != null && DateTime.now().isBefore(_expiresAt!); } - Future _performSignIn(List scopes) async { + Future _performSignIn(List? scopes) async { Future> future; if (_exchangeEndpoint != null) { future = _codeExchangeSignIn( - scope: scopes.join(' '), + scope: scopes!.join(' '), clientId: _clientId, hostedDomains: _hostedDomain, presenter: presenter, - exchangeEndpoint: _exchangeEndpoint, + exchangeEndpoint: _exchangeEndpoint!, uid: _storage.id, ); } else { future = _tokenSignIn( - scope: scopes.join(' '), + scope: scopes!.join(' '), clientId: _clientId, hostedDomains: _hostedDomain, presenter: presenter, @@ -318,13 +314,13 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform { await _fetchUserProfile(); } - Future _doTokenRefresh() async { + Future> _doTokenRefresh() async { assert(_exchangeEndpoint != null); assert(_refreshToken != null); final Response response = await post( - _exchangeEndpoint, - body: json.encode({ + Uri.parse(_exchangeEndpoint!), + body: json.encode({ 'refreshToken': _refreshToken, 'clientId': _clientId, }), @@ -339,6 +335,8 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform { } else { return Future>.error(response.body); } + + throw Exception('Error refreshing token'); } void _initFromStore() { diff --git a/google_sign_in_dart/lib/src/code_exchange_sing_in.dart b/google_sign_in_dart/lib/src/code_exchange_sing_in.dart index ab4e7895..ffdd74cd 100644 --- a/google_sign_in_dart/lib/src/code_exchange_sing_in.dart +++ b/google_sign_in_dart/lib/src/code_exchange_sing_in.dart @@ -10,18 +10,13 @@ part of '../google_sign_in_dartio.dart'; /// Once the auth code comes back it make a post to [exchangeEndpoint] for /// to obtain the access and refresh tokens. Future> _codeExchangeSignIn({ - @required String clientId, - @required String exchangeEndpoint, - @required String scope, - @required UrlPresenter presenter, - String hostedDomains, - String uid, + required String clientId, + required String exchangeEndpoint, + required String scope, + required UrlPresenter presenter, + String? hostedDomains, + String? uid, }) async { - assert(clientId != null); - assert(exchangeEndpoint != null); - assert(presenter != null); - assert(scope != null); - final Completer> completer = Completer>(); @@ -84,18 +79,18 @@ Future> _codeExchangeSignIn({ } Future> _validateAndExchangeCodeResponse({ - @required HttpRequest request, - @required String state, - @required String exchangeEndpoint, - @required String redirectUrl, - @required String clientId, - @required String codeVerifier, + required HttpRequest request, + required String state, + required String exchangeEndpoint, + required String redirectUrl, + required String clientId, + required String codeVerifier, }) { final Map authResponse = request.requestedUri.queryParameters; - final String returnedState = authResponse['state']; - final String code = authResponse['code']; + final String? returnedState = authResponse['state']; + final String? code = authResponse['code']; - String message; + String? message; if (state != returnedState) { message = 'Invalid response from server (state did not match).'; } @@ -124,15 +119,15 @@ Future> _validateAndExchangeCodeResponse({ } Future> _exchangeCode({ - @required String exchangeEndpoint, - @required String redirectUrl, - @required String clientId, - @required String code, - @required String codeVerifier, + required String exchangeEndpoint, + required String redirectUrl, + required String clientId, + required String? code, + required String codeVerifier, }) async { final Response response = await post( - exchangeEndpoint, - body: json.encode({ + Uri.parse(exchangeEndpoint), + body: json.encode({ 'code': code, 'codeVerifier': codeVerifier, 'clientId': clientId, diff --git a/google_sign_in_dart/lib/src/crypto.dart b/google_sign_in_dart/lib/src/crypto.dart index a1c2396c..2dd29107 100644 --- a/google_sign_in_dart/lib/src/crypto.dart +++ b/google_sign_in_dart/lib/src/crypto.dart @@ -13,11 +13,8 @@ const String _charset = /// See "Proof Key for Code Exchange by OAuth Public Clients (RFC 7636) /// " String _generateSecureRandomString( - [Random entropySource, int entropyBytes = 64]) { + [Random? entropySource, int entropyBytes = 64]) { entropySource ??= Random.secure(); - assert(entropySource != null, 'entropySource cannot be null'); - assert(entropyBytes != null, 'entropyBytes cannot be null'); - final StringBuffer buffer = StringBuffer(); int remainingLength = entropyBytes; while (remainingLength > 0) { diff --git a/google_sign_in_dart/lib/src/data_storage.dart b/google_sign_in_dart/lib/src/data_storage.dart index b9204275..186c5c03 100644 --- a/google_sign_in_dart/lib/src/data_storage.dart +++ b/google_sign_in_dart/lib/src/data_storage.dart @@ -7,10 +7,8 @@ part of '../google_sign_in_dartio.dart'; /// Helper class for persisting tokens between sessions class DataStorage { /// Create an instance that will persist the values using [store]. - const DataStorage._({@required Store store, @required String clientId}) - : assert(store != null), - assert(clientId != null), - _store = store, + const DataStorage._({required Store store, required String clientId}) + : _store = store, _clientId = clientId; final Store _store; @@ -31,27 +29,27 @@ class DataStorage { /// In case there is no user logged in this value is the id of the last user /// that was logged in. This id can be used as a hint when the user tries to /// login again. - String get id => _store.get(_getKey(_kIdKey)); + String? get id => _store.get(_getKey(_kIdKey)); /// Saves the JSON Web Token (JWT) that contains digitally signed identity /// information about the user. - String get idToken => _store.get(_getKey(_kIdTokenKey)); + String? get idToken => _store.get(_getKey(_kIdTokenKey)); - set idToken(String value) => _setValue(_kIdTokenKey, value); + set idToken(String? value) => _setValue(_kIdTokenKey, value); /// Saves the token that your application sends to authorize a Google API /// request. - String get accessToken => _store.get(_getKey(_kAccessTokenKey)); + String? get accessToken => _store.get(_getKey(_kAccessTokenKey)); - set accessToken(String value) => _setValue(_kAccessTokenKey, value); + set accessToken(String? value) => _setValue(_kAccessTokenKey, value); /// Saves the remaining lifetime of the access token. - DateTime get expiresAt { - final String date = _store.get(_getKey(_kExpirationAtKey)); + DateTime? get expiresAt { + final String? date = _store.get(_getKey(_kExpirationAtKey)); return date != null ? DateTime.parse(date) : null; } - set expiresAt(DateTime value) { + set expiresAt(DateTime? value) { _setValue(_kExpirationAtKey, value?.toIso8601String()); } @@ -60,18 +58,20 @@ class DataStorage { /// Refresh tokens are present if you provided a /// [GoogleSignInDart._exchangeEndpoint] value and are valid until the /// user revokes access. - String get refreshToken => _store.get(_getKey(_kRefreshTokenKey)); + String? get refreshToken => _store.get(_getKey(_kRefreshTokenKey)); - set refreshToken(String value) => _setValue(_kRefreshTokenKey, value); + set refreshToken(String? value) => _setValue(_kRefreshTokenKey, value); /// Retrieve the authentication data after sign in. platform.GoogleSignInTokenData get tokenData { if (idToken != null || accessToken != null) { return platform.GoogleSignInTokenData( - idToken: idToken, accessToken: accessToken); + idToken: idToken, + accessToken: accessToken, + ); } - return null; + return platform.GoogleSignInTokenData(); } set tokenData(platform.GoogleSignInTokenData data) { @@ -83,7 +83,7 @@ class DataStorage { /// /// Returns an empty list if no authorization has take place yet. List get scopes { - final String value = _store.get(_getKey(_kScopeKey)); + final String? value = _store.get(_getKey(_kScopeKey)); if (value == null || value.isEmpty) { return []; } @@ -136,12 +136,12 @@ class DataStorage { } /// Retrieve information about this signed in user based on the id_token. - platform.GoogleSignInUserData get userData { + platform.GoogleSignInUserData? get userData { if (idToken != null) { return platform.GoogleSignInUserData( - id: _store.get(_getKey(_kIdKey)), + id: _store.get(_getKey(_kIdKey))!, displayName: _store.get(_getKey(_kNameKey)), - email: _store.get(_getKey(_kEmailKey)), + email: _store.get(_getKey(_kEmailKey))!, photoUrl: _store.get(_getKey(_kPictureKey)), idToken: idToken, ); @@ -150,7 +150,7 @@ class DataStorage { return null; } - void _setValue(String key, String value) { + void _setValue(String key, String? value) { if (value == null) { _store.remove(_getKey(key)); } else { @@ -170,7 +170,7 @@ abstract class Store { void remove(String key); /// Get the value at specified [key] or nul if it doesn't exists. - String get(String key); + String? get(String key); /// Remove all the values store. void clearAll(); @@ -182,8 +182,8 @@ class _SharedPreferencesStore extends Store { final SharedPreferences _preferences; @override - String get(String key) { - return _preferences.get(key); + String? get(String key) { + return _preferences.get(key) as String?; } @override diff --git a/google_sign_in_dart/lib/src/token_sign_in.dart b/google_sign_in_dart/lib/src/token_sign_in.dart index 1ace7c22..361ecad6 100644 --- a/google_sign_in_dart/lib/src/token_sign_in.dart +++ b/google_sign_in_dart/lib/src/token_sign_in.dart @@ -10,18 +10,14 @@ part of '../google_sign_in_dartio.dart'; /// Using this implementation will not provide a refresh token, that means that /// the user will need to login again after the access token expires (~1 hour) Future> _tokenSignIn({ - @required String clientId, - @required String scope, - @required UrlPresenter presenter, - String hostedDomains, - String uid, - String successUrl, - String failUrl, + required String clientId, + required String scope, + required UrlPresenter presenter, + String? hostedDomains, + String? uid, + String? successUrl, + String? failUrl, }) async { - assert(presenter != null); - assert(clientId != null); - assert(scope != null); - final Completer> completer = Completer>(); @@ -40,7 +36,7 @@ Future> _tokenSignIn({ if (uri.path == '/') { return _sendData(request, _verifyFragmentHtml); } else if (uri.path == '/response') { - if (successUrl.isNotEmpty && failUrl.isNotEmpty) { + if (successUrl!.isNotEmpty && failUrl!.isNotEmpty) { await _validateTokenWithCustomScreen( request, state, successUrl, failUrl) .then(completer.complete) @@ -86,10 +82,10 @@ Future> _tokenSignIn({ Future> _validateTokenResponse( HttpRequest request, String state) async { final Map authResponse = request.requestedUri.queryParameters; - final String returnedState = authResponse['state']; - final String accessToken = authResponse['access_token']; - final String idToken = authResponse['id_token']; - String message; + final String? returnedState = authResponse['state']; + final String? accessToken = authResponse['access_token']; + final String? idToken = authResponse['id_token']; + String? message; if (state != returnedState) { message = 'Invalid response from server (state did not match).'; } @@ -109,11 +105,11 @@ Future> _validateTokenResponse( } Future> _validateTokenWithCustomScreen(HttpRequest request, - String state, String successUrl, String failUrl) async { + String state, String? successUrl, String? failUrl) async { final Map authResponse = request.requestedUri.queryParameters; - final String returnedState = authResponse['state']; - final String accessToken = authResponse['access_token']; - final String idToken = authResponse['id_token']; + final String? returnedState = authResponse['state']; + final String? accessToken = authResponse['access_token']; + final String? idToken = authResponse['id_token']; if (state != returnedState || accessToken == null || accessToken.isEmpty || @@ -123,12 +119,12 @@ Future> _validateTokenWithCustomScreen(HttpRequest request, ..statusCode = 500 ..headers.set('content-type', 'text/plain') ..write(''); - await launch(failUrl); + await launch(failUrl!); } else { request.response ..statusCode = 200 ..write(''); - await launch(successUrl); + await launch(successUrl!); } await request.response.close(); return authResponse; diff --git a/google_sign_in_dart/pubspec.yaml b/google_sign_in_dart/pubspec.yaml index 066c70a1..0baf027b 100644 --- a/google_sign_in_dart/pubspec.yaml +++ b/google_sign_in_dart/pubspec.yaml @@ -5,7 +5,7 @@ homepage: https://github.com/fluttercommunity/firebase_dart_sdk/tree/develop/goo commit: 89794a635a5efad6705e3d7ccc29e8139318d947 environment: - sdk: ">=2.8.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: flutter: