Skip to content

Commit 496a2a0

Browse files
authored
[flutter_appauth_platform_interface] remove toMap method (MaikuB#118)
* update API docs * remove toMap from being in public API surface * update breaking change details * revert code change in example main.dart file * update docs and changelog * revert code changes in flutter_appauth This reverts commit 556a7a3.
1 parent b4b9c98 commit 496a2a0

11 files changed

+94
-70
lines changed

flutter_appauth_platform_interface/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## [1.0.3]
1+
## [2.0.0]
22

3+
* **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.
34
* Added `preferEphemeralSession` to `AuthorizationRequest` and `AuthorizationTokenRequest` classes. Thanks to the PR from [Matthew Smith](https://github.com/matthewtsmith).
45

56
## [1.0.2]
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import 'mappable.dart';
2-
3-
mixin AuthorizationParameters on Mappable {
1+
mixin AuthorizationParameters {
42
/// Hint to the Authorization Server about the login identifier the End-User might use to log in.
53
String loginHint;
64

@@ -11,13 +9,4 @@ mixin AuthorizationParameters on Mappable {
119
///
1210
/// This property is only applicable to iOS versions 13 and above.
1311
bool preferEphemeralSession;
14-
15-
@override
16-
Map<String, dynamic> toMap() {
17-
final Map<String, dynamic> map = super.toMap();
18-
map['loginHint'] = loginHint;
19-
map['promptValues'] = promptValues;
20-
map['preferEphemeralSession'] = preferEphemeralSession;
21-
return map;
22-
}
2312
}

flutter_appauth_platform_interface/lib/src/authorization_response.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// Contains the response from making an authorization request.
12
class AuthorizationResponse {
23
AuthorizationResponse(
34
this.authorizationCode,

flutter_appauth_platform_interface/lib/src/authorization_service_configuration.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,4 @@ class AuthorizationServiceConfiguration {
88
final String authorizationEndpoint;
99

1010
final String tokenEndpoint;
11-
12-
Map<String, dynamic> toMap() {
13-
return <String, dynamic>{
14-
'tokenEndpoint': tokenEndpoint,
15-
'authorizationEndpoint': authorizationEndpoint
16-
};
17-
}
1811
}

flutter_appauth_platform_interface/lib/src/common_request_details.dart

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'authorization_service_configuration.dart';
2-
import 'mappable.dart';
32

4-
class CommonRequestDetails implements Mappable {
3+
class CommonRequestDetails {
54
/// The client id.
65
String clientId;
76

@@ -27,18 +26,4 @@ class CommonRequestDetails implements Mappable {
2726
///
2827
/// This property is only applicable to Android.
2928
bool allowInsecureConnections;
30-
31-
@override
32-
Map<String, dynamic> toMap() {
33-
return <String, dynamic>{
34-
'clientId': clientId,
35-
'issuer': issuer,
36-
'discoveryUrl': discoveryUrl,
37-
'redirectUrl': redirectUrl,
38-
'scopes': scopes,
39-
'serviceConfiguration': serviceConfiguration?.toMap(),
40-
'additionalParameters': additionalParameters,
41-
'allowInsecureConnections': allowInsecureConnections,
42-
};
43-
}
4429
}

flutter_appauth_platform_interface/lib/src/mappable.dart

Lines changed: 0 additions & 3 deletions
This file was deleted.

flutter_appauth_platform_interface/lib/src/method_channel_flutter_appauth.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'authorization_response.dart';
55
import 'authorization_token_request.dart';
66
import 'authorization_token_response.dart';
77
import 'flutter_appauth_platform.dart';
8+
import 'method_channel_mappers.dart';
89
import 'token_request.dart';
910
import 'token_response.dart';
1011

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import 'authorization_parameters.dart';
2+
import 'authorization_request.dart';
3+
import 'authorization_service_configuration.dart';
4+
import 'authorization_token_request.dart';
5+
import 'common_request_details.dart';
6+
import 'grant_types.dart';
7+
import 'token_request.dart';
8+
9+
Map<String, Object> _convertCommonRequestDetailsToMap(
10+
CommonRequestDetails commonRequestDetails) {
11+
return <String, Object>{
12+
'clientId': commonRequestDetails.clientId,
13+
'issuer': commonRequestDetails.issuer,
14+
'discoveryUrl': commonRequestDetails.discoveryUrl,
15+
'redirectUrl': commonRequestDetails.redirectUrl,
16+
'scopes': commonRequestDetails.scopes,
17+
'serviceConfiguration': commonRequestDetails.serviceConfiguration?.toMap(),
18+
'additionalParameters': commonRequestDetails.additionalParameters,
19+
'allowInsecureConnections': commonRequestDetails.allowInsecureConnections,
20+
};
21+
}
22+
23+
extension AuthorizationRequestParameters on AuthorizationRequest {
24+
Map<String, Object> toMap() {
25+
return _convertAuthorizationParametersToMap(this)
26+
..addAll(_convertCommonRequestDetailsToMap(this));
27+
}
28+
}
29+
30+
extension AuthorizationServiceConfigurationMapper
31+
on AuthorizationServiceConfiguration {
32+
Map<String, Object> toMap() {
33+
return <String, Object>{
34+
'tokenEndpoint': tokenEndpoint,
35+
'authorizationEndpoint': authorizationEndpoint,
36+
};
37+
}
38+
}
39+
40+
extension TokenRequestMapper on TokenRequest {
41+
Map<String, Object> toMap() {
42+
return _convertTokenRequestToMap(this);
43+
}
44+
}
45+
46+
extension AuthorizationTokenRequestMapper on AuthorizationTokenRequest {
47+
Map<String, Object> toMap() {
48+
return _convertTokenRequestToMap(this)
49+
..addAll(_convertAuthorizationParametersToMap(this));
50+
}
51+
}
52+
53+
Map<String, Object> _convertTokenRequestToMap(TokenRequest tokenRequest) {
54+
return <String, Object>{
55+
'clientSecret': tokenRequest.clientSecret,
56+
'refreshToken': tokenRequest.refreshToken,
57+
'authorizationCode': tokenRequest.authorizationCode,
58+
'grantType': _inferGrantType(tokenRequest),
59+
'codeVerifier': tokenRequest.codeVerifier,
60+
}..addAll(_convertCommonRequestDetailsToMap(tokenRequest));
61+
}
62+
63+
String _inferGrantType(TokenRequest tokenRequest) {
64+
if (tokenRequest.grantType != null) {
65+
return tokenRequest.grantType;
66+
}
67+
if (tokenRequest.refreshToken != null) {
68+
return GrantType.refreshToken;
69+
}
70+
if (tokenRequest.authorizationCode != null) {
71+
return GrantType.authorizationCode;
72+
}
73+
74+
throw ArgumentError.value(
75+
null, 'grantType', 'Grant type not specified and cannot be inferred');
76+
}
77+
78+
Map<String, Object> _convertAuthorizationParametersToMap(
79+
AuthorizationParameters authorizationParameters) {
80+
return <String, Object>{
81+
'loginHint': authorizationParameters.loginHint,
82+
'promptValues': authorizationParameters.promptValues,
83+
'preferEphemeralSession': authorizationParameters.preferEphemeralSession,
84+
};
85+
}

flutter_appauth_platform_interface/lib/src/token_request.dart

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'authorization_service_configuration.dart';
22
import 'common_request_details.dart';
3-
import 'grant_types.dart';
43

54
/// Details for a token exchange request.
65
class TokenRequest with CommonRequestDetails {
@@ -50,31 +49,4 @@ class TokenRequest with CommonRequestDetails {
5049

5150
/// The code verifier to be sent with the authorization code. This should match the code verifier used when performing the authorization request
5251
final String codeVerifier;
53-
54-
@override
55-
Map<String, dynamic> toMap() {
56-
final Map<String, dynamic> map = super.toMap();
57-
final String inferredGrantType = _inferGrantType();
58-
map['clientSecret'] = clientSecret;
59-
map['refreshToken'] = refreshToken;
60-
map['authorizationCode'] = authorizationCode;
61-
map['grantType'] = inferredGrantType;
62-
map['codeVerifier'] = codeVerifier;
63-
return map;
64-
}
65-
66-
String _inferGrantType() {
67-
if (grantType != null) {
68-
return grantType;
69-
}
70-
if (refreshToken != null) {
71-
return GrantType.refreshToken;
72-
}
73-
if (authorizationCode != null) {
74-
return GrantType.authorizationCode;
75-
}
76-
77-
throw ArgumentError.value(
78-
null, 'grantType', 'Grant type not specified and cannot be inferred');
79-
}
8052
}

flutter_appauth_platform_interface/lib/src/token_response.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// Details from making a successful token exchange
1+
/// Details from making a successful token exchange.
22
class TokenResponse {
33
TokenResponse(
44
this.accessToken,

flutter_appauth_platform_interface/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: flutter_appauth_platform_interface
22
description: A common platform interface for the flutter_appauth plugin.
3-
version: 1.0.3
3+
version: 2.0.0
44
homepage: https://github.com/MaikuB/flutter_appauth/tree/master/flutter_appauth_platform_interface
55

66
environment:
7-
sdk: ">=2.1.0 <3.0.0"
7+
sdk: ">=2.6.0 <3.0.0"
88
flutter: ">=1.10.0"
99

1010
dependencies:

0 commit comments

Comments
 (0)