From c3cf7b8a970fcee40355a6e00217fc86f935e5c3 Mon Sep 17 00:00:00 2001 From: Michael Bui <25263378+MaikuB@users.noreply.github.com> Date: Sun, 21 Feb 2021 10:47:49 +1100 Subject: [PATCH] migrate platform interface to null safety --- .../CHANGELOG.md | 7 ++++++- .../lib/src/authorization_parameters.dart | 6 +++--- .../lib/src/authorization_request.dart | 14 ++++++------- .../lib/src/authorization_response.dart | 8 ++++---- .../authorization_service_configuration.dart | 5 ++--- .../lib/src/authorization_token_request.dart | 16 +++++++-------- .../lib/src/authorization_token_response.dart | 14 ++++++------- .../lib/src/common_request_details.dart | 16 +++++++-------- .../lib/src/flutter_appauth_platform.dart | 6 +++--- .../src/method_channel_flutter_appauth.dart | 12 +++++------ .../lib/src/method_channel_mappers.dart | 20 +++++++++---------- .../lib/src/token_request.dart | 20 +++++++++---------- .../lib/src/token_response.dart | 12 +++++------ .../pubspec.yaml | 8 ++++---- .../method_channel_flutter_appauth_test.dart | 10 +++++----- 15 files changed, 89 insertions(+), 85 deletions(-) diff --git a/flutter_appauth_platform_interface/CHANGELOG.md b/flutter_appauth_platform_interface/CHANGELOG.md index e9eae000..665d1c90 100644 --- a/flutter_appauth_platform_interface/CHANGELOG.md +++ b/flutter_appauth_platform_interface/CHANGELOG.md @@ -1,6 +1,11 @@ +## [3.0.0-nullsafety.0] + +* Migrated to null safety +* `AuthorizationServiceConfiguration` and `AuthorizationResponse` now have `const` constructors + ## [2.0.0] -* **BREAKING CHANGE** Removed the `toMap` methods so that it's not part of the public API surface. This was done as these methods were for internal use. Currently `flutter_appauth` (version 0.8.3) is constrained to depend on versions >= 1.0.2 and < 2.0.0. As it's possible that plugin consumers were calling the methods via the plugin, where the platform interface is a transitive dependency, the platform interface has been bumped to version 2.0.0 instead of 1.1.0 to be safe. +* **Breaking change** Removed the `toMap` methods so that it's not part of the public API surface. This was done as these methods were for internal use. Currently `flutter_appauth` (version 0.8.3) is constrained to depend on versions >= 1.0.2 and < 2.0.0. As it's possible that plugin consumers were calling the methods via the plugin, where the platform interface is a transitive dependency, the platform interface has been bumped to version 2.0.0 instead of 1.1.0 to be safe. * Added `preferEphemeralSession` to `AuthorizationRequest` and `AuthorizationTokenRequest` classes. Thanks to the PR from [Matthew Smith](https://github.com/matthewtsmith). ## [1.0.2] diff --git a/flutter_appauth_platform_interface/lib/src/authorization_parameters.dart b/flutter_appauth_platform_interface/lib/src/authorization_parameters.dart index 2cea12ce..173116bf 100644 --- a/flutter_appauth_platform_interface/lib/src/authorization_parameters.dart +++ b/flutter_appauth_platform_interface/lib/src/authorization_parameters.dart @@ -1,12 +1,12 @@ mixin AuthorizationParameters { /// Hint to the Authorization Server about the login identifier the End-User might use to log in. - String loginHint; + String? loginHint; /// List of ASCII string values that specifies whether the Authorization Server prompts the End-User for reauthentication and consent. - List promptValues; + List? promptValues; /// Whether to use an ephemeral session that prevents cookies and other browser data being shared with the user's normal browser session. /// /// This property is only applicable to iOS versions 13 and above. - bool preferEphemeralSession; + bool? preferEphemeralSession; } diff --git a/flutter_appauth_platform_interface/lib/src/authorization_request.dart b/flutter_appauth_platform_interface/lib/src/authorization_request.dart index 9cb8683d..0b57f32d 100644 --- a/flutter_appauth_platform_interface/lib/src/authorization_request.dart +++ b/flutter_appauth_platform_interface/lib/src/authorization_request.dart @@ -8,13 +8,13 @@ class AuthorizationRequest extends CommonRequestDetails AuthorizationRequest( String clientId, String redirectUrl, { - String loginHint, - List scopes, - AuthorizationServiceConfiguration serviceConfiguration, - Map additionalParameters, - String issuer, - String discoveryUrl, - List promptValues, + String? loginHint, + List? scopes, + AuthorizationServiceConfiguration? serviceConfiguration, + Map? additionalParameters, + String? issuer, + String? discoveryUrl, + List? promptValues, bool allowInsecureConnections = false, bool preferEphemeralSession = false, }) { diff --git a/flutter_appauth_platform_interface/lib/src/authorization_response.dart b/flutter_appauth_platform_interface/lib/src/authorization_response.dart index bd6daa8e..193e5127 100644 --- a/flutter_appauth_platform_interface/lib/src/authorization_response.dart +++ b/flutter_appauth_platform_interface/lib/src/authorization_response.dart @@ -1,17 +1,17 @@ /// Contains the response from making an authorization request. class AuthorizationResponse { - AuthorizationResponse( + const AuthorizationResponse( this.authorizationCode, this.codeVerifier, this.authorizationAdditionalParameters, ); /// The authorization code. - final String authorizationCode; + final String? authorizationCode; /// The code verifier generated by AppAuth when issue the authorization request. Use this when exchanging the [authorizationCode] for a token. - final String codeVerifier; + final String? codeVerifier; /// Additional parameters included in the response. - final Map authorizationAdditionalParameters; + final Map? authorizationAdditionalParameters; } diff --git a/flutter_appauth_platform_interface/lib/src/authorization_service_configuration.dart b/flutter_appauth_platform_interface/lib/src/authorization_service_configuration.dart index f3a5b7d6..f0f8c5e0 100644 --- a/flutter_appauth_platform_interface/lib/src/authorization_service_configuration.dart +++ b/flutter_appauth_platform_interface/lib/src/authorization_service_configuration.dart @@ -1,9 +1,8 @@ class AuthorizationServiceConfiguration { - AuthorizationServiceConfiguration( + const AuthorizationServiceConfiguration( this.authorizationEndpoint, this.tokenEndpoint, - ) : assert(tokenEndpoint != null && authorizationEndpoint != null, - 'Must specify both the authorization and token endpoints'); + ); final String authorizationEndpoint; diff --git a/flutter_appauth_platform_interface/lib/src/authorization_token_request.dart b/flutter_appauth_platform_interface/lib/src/authorization_token_request.dart index 0eaea507..85a0d4c9 100644 --- a/flutter_appauth_platform_interface/lib/src/authorization_token_request.dart +++ b/flutter_appauth_platform_interface/lib/src/authorization_token_request.dart @@ -9,14 +9,14 @@ class AuthorizationTokenRequest extends TokenRequest AuthorizationTokenRequest( String clientId, String redirectUrl, { - String loginHint, - String clientSecret, - List scopes, - AuthorizationServiceConfiguration serviceConfiguration, - Map additionalParameters, - String issuer, - String discoveryUrl, - List promptValues, + String? loginHint, + String? clientSecret, + List? scopes, + AuthorizationServiceConfiguration? serviceConfiguration, + Map? additionalParameters, + String? issuer, + String? discoveryUrl, + List? promptValues, bool allowInsecureConnections = false, bool preferEphemeralSession = false, }) : super( diff --git a/flutter_appauth_platform_interface/lib/src/authorization_token_response.dart b/flutter_appauth_platform_interface/lib/src/authorization_token_response.dart index e5e9fbef..a5692d94 100644 --- a/flutter_appauth_platform_interface/lib/src/authorization_token_response.dart +++ b/flutter_appauth_platform_interface/lib/src/authorization_token_response.dart @@ -3,16 +3,16 @@ import 'token_response.dart'; /// The details from making a successful combined authorization and token exchange request. class AuthorizationTokenResponse extends TokenResponse { AuthorizationTokenResponse( - String accessToken, - String refreshToken, - DateTime accessTokenExpirationDateTime, - String idToken, - String tokenType, + String? accessToken, + String? refreshToken, + DateTime? accessTokenExpirationDateTime, + String? idToken, + String? tokenType, this.authorizationAdditionalParameters, - Map tokenAdditionalParameters, + Map? tokenAdditionalParameters, ) : super(accessToken, refreshToken, accessTokenExpirationDateTime, idToken, tokenType, tokenAdditionalParameters); /// Contains additional parameters returned by the authorization server from making the authorization request. - final Map authorizationAdditionalParameters; + final Map? authorizationAdditionalParameters; } diff --git a/flutter_appauth_platform_interface/lib/src/common_request_details.dart b/flutter_appauth_platform_interface/lib/src/common_request_details.dart index 45f22e8a..4c07ae42 100644 --- a/flutter_appauth_platform_interface/lib/src/common_request_details.dart +++ b/flutter_appauth_platform_interface/lib/src/common_request_details.dart @@ -2,28 +2,28 @@ import 'authorization_service_configuration.dart'; class CommonRequestDetails { /// The client id. - String clientId; + String? clientId; /// The issuer. - String issuer; + String? issuer; /// The URL of where the discovery document can be found. - String discoveryUrl; + String? discoveryUrl; /// The redirect URL. - String redirectUrl; + String? redirectUrl; /// The request scopes. - List scopes; + List? scopes; /// The details of the OAuth 2.0 endpoints that can be explicitly when discovery isn't used or not possible. - AuthorizationServiceConfiguration serviceConfiguration; + AuthorizationServiceConfiguration? serviceConfiguration; /// Additional parameters to include in the request. - Map additionalParameters; + Map? additionalParameters; /// Whether to allow non-HTTPS endpoints. /// /// This property is only applicable to Android. - bool allowInsecureConnections; + bool? allowInsecureConnections; } diff --git a/flutter_appauth_platform_interface/lib/src/flutter_appauth_platform.dart b/flutter_appauth_platform_interface/lib/src/flutter_appauth_platform.dart index 65def2cf..d6cf61b0 100644 --- a/flutter_appauth_platform_interface/lib/src/flutter_appauth_platform.dart +++ b/flutter_appauth_platform_interface/lib/src/flutter_appauth_platform.dart @@ -29,19 +29,19 @@ abstract class FlutterAppAuthPlatform extends PlatformInterface { } /// Convenience method for authorizing and then exchanges the authorization grant code. - Future authorizeAndExchangeCode( + Future authorizeAndExchangeCode( AuthorizationTokenRequest request) { throw UnimplementedError( 'authorizeAndExchangeCode() has not been implemented'); } /// Sends an authorization request. - Future authorize(AuthorizationRequest request) { + Future authorize(AuthorizationRequest request) { throw UnimplementedError('authorize() has not been implemented'); } /// For exchanging tokens. - Future token(TokenRequest request) { + Future token(TokenRequest request) { throw UnimplementedError('token() has not been implemented'); } } diff --git a/flutter_appauth_platform_interface/lib/src/method_channel_flutter_appauth.dart b/flutter_appauth_platform_interface/lib/src/method_channel_flutter_appauth.dart index 1c917f62..00612c64 100644 --- a/flutter_appauth_platform_interface/lib/src/method_channel_flutter_appauth.dart +++ b/flutter_appauth_platform_interface/lib/src/method_channel_flutter_appauth.dart @@ -14,8 +14,8 @@ const MethodChannel _channel = class MethodChannelFlutterAppAuth extends FlutterAppAuthPlatform { @override - Future authorize(AuthorizationRequest request) async { - final Map result = + Future authorize(AuthorizationRequest request) async { + final Map? result = await _channel.invokeMethod('authorize', request.toMap()); if (result == null) { return null; @@ -27,9 +27,9 @@ class MethodChannelFlutterAppAuth extends FlutterAppAuthPlatform { } @override - Future authorizeAndExchangeCode( + Future authorizeAndExchangeCode( AuthorizationTokenRequest request) async { - final Map result = await _channel.invokeMethod( + final Map? result = await _channel.invokeMethod( 'authorizeAndExchangeCode', request.toMap()); if (result == null) { return null; @@ -48,8 +48,8 @@ class MethodChannelFlutterAppAuth extends FlutterAppAuthPlatform { } @override - Future token(TokenRequest request) async { - final Map result = + Future token(TokenRequest request) async { + final Map? result = await _channel.invokeMethod('token', request.toMap()); if (result == null) { return null; diff --git a/flutter_appauth_platform_interface/lib/src/method_channel_mappers.dart b/flutter_appauth_platform_interface/lib/src/method_channel_mappers.dart index d0d6c464..814be0e9 100644 --- a/flutter_appauth_platform_interface/lib/src/method_channel_mappers.dart +++ b/flutter_appauth_platform_interface/lib/src/method_channel_mappers.dart @@ -6,9 +6,9 @@ import 'common_request_details.dart'; import 'grant_types.dart'; import 'token_request.dart'; -Map _convertCommonRequestDetailsToMap( +Map _convertCommonRequestDetailsToMap( CommonRequestDetails commonRequestDetails) { - return { + return { 'clientId': commonRequestDetails.clientId, 'issuer': commonRequestDetails.issuer, 'discoveryUrl': commonRequestDetails.discoveryUrl, @@ -21,7 +21,7 @@ Map _convertCommonRequestDetailsToMap( } extension AuthorizationRequestParameters on AuthorizationRequest { - Map toMap() { + Map toMap() { return _convertAuthorizationParametersToMap(this) ..addAll(_convertCommonRequestDetailsToMap(this)); } @@ -38,20 +38,20 @@ extension AuthorizationServiceConfigurationMapper } extension TokenRequestMapper on TokenRequest { - Map toMap() { + Map toMap() { return _convertTokenRequestToMap(this); } } extension AuthorizationTokenRequestMapper on AuthorizationTokenRequest { - Map toMap() { + Map toMap() { return _convertTokenRequestToMap(this) ..addAll(_convertAuthorizationParametersToMap(this)); } } -Map _convertTokenRequestToMap(TokenRequest tokenRequest) { - return { +Map _convertTokenRequestToMap(TokenRequest tokenRequest) { + return { 'clientSecret': tokenRequest.clientSecret, 'refreshToken': tokenRequest.refreshToken, 'authorizationCode': tokenRequest.authorizationCode, @@ -60,7 +60,7 @@ Map _convertTokenRequestToMap(TokenRequest tokenRequest) { }..addAll(_convertCommonRequestDetailsToMap(tokenRequest)); } -String _inferGrantType(TokenRequest tokenRequest) { +String? _inferGrantType(TokenRequest tokenRequest) { if (tokenRequest.grantType != null) { return tokenRequest.grantType; } @@ -75,9 +75,9 @@ String _inferGrantType(TokenRequest tokenRequest) { null, 'grantType', 'Grant type not specified and cannot be inferred'); } -Map _convertAuthorizationParametersToMap( +Map _convertAuthorizationParametersToMap( AuthorizationParameters authorizationParameters) { - return { + return { 'loginHint': authorizationParameters.loginHint, 'promptValues': authorizationParameters.promptValues, 'preferEphemeralSession': authorizationParameters.preferEphemeralSession, diff --git a/flutter_appauth_platform_interface/lib/src/token_request.dart b/flutter_appauth_platform_interface/lib/src/token_request.dart index 2bb2a82d..a2ae3130 100644 --- a/flutter_appauth_platform_interface/lib/src/token_request.dart +++ b/flutter_appauth_platform_interface/lib/src/token_request.dart @@ -7,13 +7,13 @@ class TokenRequest with CommonRequestDetails { String clientId, String redirectUrl, { this.clientSecret, - List scopes, - AuthorizationServiceConfiguration serviceConfiguration, - Map additionalParameters, + List? scopes, + AuthorizationServiceConfiguration? serviceConfiguration, + Map? additionalParameters, this.refreshToken, this.grantType, - String issuer, - String discoveryUrl, + String? issuer, + String? discoveryUrl, this.authorizationCode, this.codeVerifier, bool allowInsecureConnections = false, @@ -34,19 +34,19 @@ class TokenRequest with CommonRequestDetails { } /// The client secret. - final String clientSecret; + final String? clientSecret; /// The refresh token. - final String refreshToken; + final String? refreshToken; /// The grant type. /// /// If this is not specified then it will be inferred based on if [refreshToken] or [authorizationCode] has been specified. - final String grantType; + final String? grantType; /// The authorization code. - final String authorizationCode; + final String? authorizationCode; /// The code verifier to be sent with the authorization code. This should match the code verifier used when performing the authorization request - final String codeVerifier; + final String? codeVerifier; } diff --git a/flutter_appauth_platform_interface/lib/src/token_response.dart b/flutter_appauth_platform_interface/lib/src/token_response.dart index e4fd79f2..4e754825 100644 --- a/flutter_appauth_platform_interface/lib/src/token_response.dart +++ b/flutter_appauth_platform_interface/lib/src/token_response.dart @@ -10,24 +10,24 @@ class TokenResponse { ); /// The access token returned by the authorization server. - final String accessToken; + final String? accessToken; /// The refresh token returned by the authorization server. - final String refreshToken; + final String? refreshToken; /// Indicates when [accessToken] will expire. /// /// To ensure applications have continue to use valid access tokens, they /// will generally use the refresh token to get a new access token /// before it expires. - final DateTime accessTokenExpirationDateTime; + final DateTime? accessTokenExpirationDateTime; /// The id token returned by the authorization server. - final String idToken; + final String? idToken; /// The type of token returned by the authorization server. - final String tokenType; + final String? tokenType; /// Contains additional parameters returned by the authorization server from making the token request. - final Map tokenAdditionalParameters; + final Map? tokenAdditionalParameters; } diff --git a/flutter_appauth_platform_interface/pubspec.yaml b/flutter_appauth_platform_interface/pubspec.yaml index 208a2e9e..892084a8 100644 --- a/flutter_appauth_platform_interface/pubspec.yaml +++ b/flutter_appauth_platform_interface/pubspec.yaml @@ -1,18 +1,18 @@ name: flutter_appauth_platform_interface description: A common platform interface for the flutter_appauth plugin. -version: 2.0.0 +version: 3.0.0-nullsafety.0 homepage: https://github.com/MaikuB/flutter_appauth/tree/master/flutter_appauth_platform_interface environment: - sdk: ">=2.6.0 <3.0.0" + sdk: '>=2.12.0-0 <3.0.0' flutter: ">=1.10.0" dependencies: flutter: sdk: flutter - plugin_platform_interface: ^1.0.2 + plugin_platform_interface: ^2.0.0 dev_dependencies: flutter_test: sdk: flutter - mockito: ^4.1.1 \ No newline at end of file + mockito: ^5.0.0-nullsafety.7 \ No newline at end of file diff --git a/flutter_appauth_platform_interface/test/method_channel_flutter_appauth_test.dart b/flutter_appauth_platform_interface/test/method_channel_flutter_appauth_test.dart index a8ca602e..8b3aca9c 100644 --- a/flutter_appauth_platform_interface/test/method_channel_flutter_appauth_test.dart +++ b/flutter_appauth_platform_interface/test/method_channel_flutter_appauth_test.dart @@ -27,7 +27,7 @@ void main() { expect( log, [ - isMethodCall('authorize', arguments: { + isMethodCall('authorize', arguments: { 'clientId': 'someClientId', 'issuer': null, 'redirectUrl': 'someRedirectUrl', @@ -51,7 +51,7 @@ void main() { expect( log, [ - isMethodCall('authorizeAndExchangeCode', arguments: { + isMethodCall('authorizeAndExchangeCode', arguments: { 'clientId': 'someClientId', 'issuer': null, 'redirectUrl': 'someRedirectUrl', @@ -87,7 +87,7 @@ void main() { expect( log, [ - isMethodCall('token', arguments: { + isMethodCall('token', arguments: { 'clientId': 'someClientId', 'issuer': null, 'redirectUrl': 'someRedirectUrl', @@ -113,7 +113,7 @@ void main() { expect( log, [ - isMethodCall('token', arguments: { + isMethodCall('token', arguments: { 'clientId': 'someClientId', 'issuer': null, 'redirectUrl': 'someRedirectUrl', @@ -138,7 +138,7 @@ void main() { expect( log, [ - isMethodCall('token', arguments: { + isMethodCall('token', arguments: { 'clientId': 'someClientId', 'issuer': null, 'redirectUrl': 'someRedirectUrl',