Skip to content

Commit

Permalink
migrate platform interface to null safety
Browse files Browse the repository at this point in the history
  • Loading branch information
MaikuB committed Feb 21, 2021
1 parent 8d266d8 commit c3cf7b8
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 85 deletions.
7 changes: 6 additions & 1 deletion flutter_appauth_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> promptValues;
List<String>? 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ class AuthorizationRequest extends CommonRequestDetails
AuthorizationRequest(
String clientId,
String redirectUrl, {
String loginHint,
List<String> scopes,
AuthorizationServiceConfiguration serviceConfiguration,
Map<String, String> additionalParameters,
String issuer,
String discoveryUrl,
List<String> promptValues,
String? loginHint,
List<String>? scopes,
AuthorizationServiceConfiguration? serviceConfiguration,
Map<String, String>? additionalParameters,
String? issuer,
String? discoveryUrl,
List<String>? promptValues,
bool allowInsecureConnections = false,
bool preferEphemeralSession = false,
}) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, dynamic> authorizationAdditionalParameters;
final Map<String, dynamic>? authorizationAdditionalParameters;
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class AuthorizationTokenRequest extends TokenRequest
AuthorizationTokenRequest(
String clientId,
String redirectUrl, {
String loginHint,
String clientSecret,
List<String> scopes,
AuthorizationServiceConfiguration serviceConfiguration,
Map<String, String> additionalParameters,
String issuer,
String discoveryUrl,
List<String> promptValues,
String? loginHint,
String? clientSecret,
List<String>? scopes,
AuthorizationServiceConfiguration? serviceConfiguration,
Map<String, String>? additionalParameters,
String? issuer,
String? discoveryUrl,
List<String>? promptValues,
bool allowInsecureConnections = false,
bool preferEphemeralSession = false,
}) : super(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic> tokenAdditionalParameters,
Map<String, dynamic>? tokenAdditionalParameters,
) : super(accessToken, refreshToken, accessTokenExpirationDateTime, idToken,
tokenType, tokenAdditionalParameters);

/// Contains additional parameters returned by the authorization server from making the authorization request.
final Map<String, dynamic> authorizationAdditionalParameters;
final Map<String, dynamic>? authorizationAdditionalParameters;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> scopes;
List<String>? 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<String, String> additionalParameters;
Map<String, String>? additionalParameters;

/// Whether to allow non-HTTPS endpoints.
///
/// This property is only applicable to Android.
bool allowInsecureConnections;
bool? allowInsecureConnections;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ abstract class FlutterAppAuthPlatform extends PlatformInterface {
}

/// Convenience method for authorizing and then exchanges the authorization grant code.
Future<AuthorizationTokenResponse> authorizeAndExchangeCode(
Future<AuthorizationTokenResponse?> authorizeAndExchangeCode(
AuthorizationTokenRequest request) {
throw UnimplementedError(
'authorizeAndExchangeCode() has not been implemented');
}

/// Sends an authorization request.
Future<AuthorizationResponse> authorize(AuthorizationRequest request) {
Future<AuthorizationResponse?> authorize(AuthorizationRequest request) {
throw UnimplementedError('authorize() has not been implemented');
}

/// For exchanging tokens.
Future<TokenResponse> token(TokenRequest request) {
Future<TokenResponse?> token(TokenRequest request) {
throw UnimplementedError('token() has not been implemented');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const MethodChannel _channel =

class MethodChannelFlutterAppAuth extends FlutterAppAuthPlatform {
@override
Future<AuthorizationResponse> authorize(AuthorizationRequest request) async {
final Map<dynamic, dynamic> result =
Future<AuthorizationResponse?> authorize(AuthorizationRequest request) async {
final Map<dynamic, dynamic>? result =
await _channel.invokeMethod('authorize', request.toMap());
if (result == null) {
return null;
Expand All @@ -27,9 +27,9 @@ class MethodChannelFlutterAppAuth extends FlutterAppAuthPlatform {
}

@override
Future<AuthorizationTokenResponse> authorizeAndExchangeCode(
Future<AuthorizationTokenResponse?> authorizeAndExchangeCode(
AuthorizationTokenRequest request) async {
final Map<dynamic, dynamic> result = await _channel.invokeMethod(
final Map<dynamic, dynamic>? result = await _channel.invokeMethod(
'authorizeAndExchangeCode', request.toMap());
if (result == null) {
return null;
Expand All @@ -48,8 +48,8 @@ class MethodChannelFlutterAppAuth extends FlutterAppAuthPlatform {
}

@override
Future<TokenResponse> token(TokenRequest request) async {
final Map<dynamic, dynamic> result =
Future<TokenResponse?> token(TokenRequest request) async {
final Map<dynamic, dynamic>? result =
await _channel.invokeMethod('token', request.toMap());
if (result == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import 'common_request_details.dart';
import 'grant_types.dart';
import 'token_request.dart';

Map<String, Object> _convertCommonRequestDetailsToMap(
Map<String, Object?> _convertCommonRequestDetailsToMap(
CommonRequestDetails commonRequestDetails) {
return <String, Object>{
return <String, Object?>{
'clientId': commonRequestDetails.clientId,
'issuer': commonRequestDetails.issuer,
'discoveryUrl': commonRequestDetails.discoveryUrl,
Expand All @@ -21,7 +21,7 @@ Map<String, Object> _convertCommonRequestDetailsToMap(
}

extension AuthorizationRequestParameters on AuthorizationRequest {
Map<String, Object> toMap() {
Map<String, Object?> toMap() {
return _convertAuthorizationParametersToMap(this)
..addAll(_convertCommonRequestDetailsToMap(this));
}
Expand All @@ -38,20 +38,20 @@ extension AuthorizationServiceConfigurationMapper
}

extension TokenRequestMapper on TokenRequest {
Map<String, Object> toMap() {
Map<String, Object?> toMap() {
return _convertTokenRequestToMap(this);
}
}

extension AuthorizationTokenRequestMapper on AuthorizationTokenRequest {
Map<String, Object> toMap() {
Map<String, Object?> toMap() {
return _convertTokenRequestToMap(this)
..addAll(_convertAuthorizationParametersToMap(this));
}
}

Map<String, Object> _convertTokenRequestToMap(TokenRequest tokenRequest) {
return <String, Object>{
Map<String, Object?> _convertTokenRequestToMap(TokenRequest tokenRequest) {
return <String, Object?>{
'clientSecret': tokenRequest.clientSecret,
'refreshToken': tokenRequest.refreshToken,
'authorizationCode': tokenRequest.authorizationCode,
Expand All @@ -60,7 +60,7 @@ Map<String, Object> _convertTokenRequestToMap(TokenRequest tokenRequest) {
}..addAll(_convertCommonRequestDetailsToMap(tokenRequest));
}

String _inferGrantType(TokenRequest tokenRequest) {
String? _inferGrantType(TokenRequest tokenRequest) {
if (tokenRequest.grantType != null) {
return tokenRequest.grantType;
}
Expand All @@ -75,9 +75,9 @@ String _inferGrantType(TokenRequest tokenRequest) {
null, 'grantType', 'Grant type not specified and cannot be inferred');
}

Map<String, Object> _convertAuthorizationParametersToMap(
Map<String, Object?> _convertAuthorizationParametersToMap(
AuthorizationParameters authorizationParameters) {
return <String, Object>{
return <String, Object?>{
'loginHint': authorizationParameters.loginHint,
'promptValues': authorizationParameters.promptValues,
'preferEphemeralSession': authorizationParameters.preferEphemeralSession,
Expand Down
20 changes: 10 additions & 10 deletions flutter_appauth_platform_interface/lib/src/token_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class TokenRequest with CommonRequestDetails {
String clientId,
String redirectUrl, {
this.clientSecret,
List<String> scopes,
AuthorizationServiceConfiguration serviceConfiguration,
Map<String, String> additionalParameters,
List<String>? scopes,
AuthorizationServiceConfiguration? serviceConfiguration,
Map<String, String>? additionalParameters,
this.refreshToken,
this.grantType,
String issuer,
String discoveryUrl,
String? issuer,
String? discoveryUrl,
this.authorizationCode,
this.codeVerifier,
bool allowInsecureConnections = false,
Expand All @@ -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;
}
12 changes: 6 additions & 6 deletions flutter_appauth_platform_interface/lib/src/token_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic> tokenAdditionalParameters;
final Map<String, dynamic>? tokenAdditionalParameters;
}
8 changes: 4 additions & 4 deletions flutter_appauth_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
mockito: ^5.0.0-nullsafety.7
Loading

0 comments on commit c3cf7b8

Please sign in to comment.