Skip to content

Commit 3aef4a6

Browse files
sbarthBarth, StefanMaikuB
authored
[flutter_appauth][flutter_appauth_platform_interface] add responseMode as parameter for android and ios (#221)
* add responseMode as parameter for android and ios * add responseMode to interface test * removed console outputs * add responseMode to authorize test method * fixed authorize test method * revert pubspec.yaml, use version instead of path for flutter_appauth_platform_interface * increased version from 3.0.0 to 3.1.0 * increase version to 1.1.0 * add responseMode to AuthorizationRequest and amend changelog entries Co-authored-by: Barth, Stefan <[email protected]> Co-authored-by: Michael Bui <[email protected]>
1 parent be0fd7a commit 3aef4a6

File tree

11 files changed

+43
-13
lines changed

11 files changed

+43
-13
lines changed

flutter_appauth/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.1.0
2+
3+
* * Added the ability to specify the response mode for authorization requests. This can be done using the `responseMode` parameter when constructing either an `AuthorizationRequest` or `AuthorizationTokenRequest`. This was done as the AppAuth Android SDK throws an exception when this was done via `additionalParameters`.
4+
15
## 1.0.0+1
26

37
* There are no functional changes in this release. The only changes done were to suppress warnings that were occurring as a result of making use of Android v1 embedding APIs for backwards compatibility

flutter_appauth/android/src/main/java/io/crossingthestreams/flutterappauth/FlutterAppauthPlugin.java

+14-7
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ private AuthorizationTokenRequestParameters processAuthorizationTokenRequestArgu
187187
Map<String, String> serviceConfigurationParameters = (Map<String, String>) arguments.get("serviceConfiguration");
188188
Map<String, String> additionalParameters = (Map<String, String>) arguments.get("additionalParameters");
189189
allowInsecureConnections = (boolean) arguments.get("allowInsecureConnections");
190-
return new AuthorizationTokenRequestParameters(clientId, issuer, discoveryUrl, scopes, redirectUrl, serviceConfigurationParameters, additionalParameters, loginHint, promptValues);
190+
final String responseMode = (String) arguments.get("responseMode");
191+
192+
return new AuthorizationTokenRequestParameters(clientId, issuer, discoveryUrl, scopes, redirectUrl, serviceConfigurationParameters, additionalParameters, loginHint, promptValues, responseMode);
191193
}
192194

193195
@SuppressWarnings("unchecked")
@@ -221,13 +223,13 @@ private void handleAuthorizeMethodCall(Map<String, Object> arguments, final bool
221223
final AuthorizationTokenRequestParameters tokenRequestParameters = processAuthorizationTokenRequestArguments(arguments);
222224
if (tokenRequestParameters.serviceConfigurationParameters != null) {
223225
AuthorizationServiceConfiguration serviceConfiguration = requestParametersToServiceConfiguration(tokenRequestParameters);
224-
performAuthorization(serviceConfiguration, tokenRequestParameters.clientId, tokenRequestParameters.redirectUrl, tokenRequestParameters.scopes, tokenRequestParameters.loginHint, tokenRequestParameters.additionalParameters, exchangeCode, tokenRequestParameters.promptValues);
226+
performAuthorization(serviceConfiguration, tokenRequestParameters.clientId, tokenRequestParameters.redirectUrl, tokenRequestParameters.scopes, tokenRequestParameters.loginHint, tokenRequestParameters.additionalParameters, exchangeCode, tokenRequestParameters.promptValues, tokenRequestParameters.responseMode);
225227
} else {
226228
AuthorizationServiceConfiguration.RetrieveConfigurationCallback callback = new AuthorizationServiceConfiguration.RetrieveConfigurationCallback() {
227229
@Override
228230
public void onFetchConfigurationCompleted(@Nullable AuthorizationServiceConfiguration serviceConfiguration, @Nullable AuthorizationException ex) {
229231
if (ex == null) {
230-
performAuthorization(serviceConfiguration, tokenRequestParameters.clientId, tokenRequestParameters.redirectUrl, tokenRequestParameters.scopes, tokenRequestParameters.loginHint, tokenRequestParameters.additionalParameters, exchangeCode, tokenRequestParameters.promptValues);
232+
performAuthorization(serviceConfiguration, tokenRequestParameters.clientId, tokenRequestParameters.redirectUrl, tokenRequestParameters.scopes, tokenRequestParameters.loginHint, tokenRequestParameters.additionalParameters, exchangeCode, tokenRequestParameters.promptValues, tokenRequestParameters.responseMode);
231233
} else {
232234
finishWithDiscoveryError(ex);
233235
}
@@ -282,7 +284,7 @@ public void onFetchConfigurationCompleted(@Nullable AuthorizationServiceConfigur
282284
}
283285

284286

285-
private void performAuthorization(AuthorizationServiceConfiguration serviceConfiguration, String clientId, String redirectUrl, ArrayList<String> scopes, String loginHint, Map<String, String> additionalParameters, boolean exchangeCode, ArrayList<String> promptValues) {
287+
private void performAuthorization(AuthorizationServiceConfiguration serviceConfiguration, String clientId, String redirectUrl, ArrayList<String> scopes, String loginHint, Map<String, String> additionalParameters, boolean exchangeCode, ArrayList<String> promptValues, String responseMode) {
286288
AuthorizationRequest.Builder authRequestBuilder =
287289
new AuthorizationRequest.Builder(
288290
serviceConfiguration,
@@ -297,15 +299,18 @@ private void performAuthorization(AuthorizationServiceConfiguration serviceConfi
297299
authRequestBuilder.setLoginHint(loginHint);
298300
}
299301

300-
if(promptValues != null && !promptValues.isEmpty()) {
302+
if (promptValues != null && !promptValues.isEmpty()) {
301303
authRequestBuilder.setPromptValues(promptValues);
302304
}
303305

306+
if (responseMode != null) {
307+
authRequestBuilder.setResponseMode(responseMode);
308+
}
309+
304310
if (additionalParameters != null && !additionalParameters.isEmpty()) {
305311
authRequestBuilder.setAdditionalParameters(additionalParameters);
306312
}
307313

308-
309314
AuthorizationService authorizationService = allowInsecureConnections ? insecureAuthorizationService : defaultAuthorizationService;
310315
Intent authIntent = authorizationService.getAuthorizationRequestIntent(authRequestBuilder.build());
311316
mainActivity.startActivityForResult(authIntent, exchangeCode ? RC_AUTH_EXCHANGE_CODE : RC_AUTH);
@@ -493,11 +498,13 @@ private TokenRequestParameters(String clientId, String issuer, String discoveryU
493498
private class AuthorizationTokenRequestParameters extends TokenRequestParameters {
494499
final String loginHint;
495500
final ArrayList<String> promptValues;
501+
final String responseMode;
496502

497-
private AuthorizationTokenRequestParameters(String clientId, String issuer, String discoveryUrl, ArrayList<String> scopes, String redirectUrl, Map<String, String> serviceConfigurationParameters, Map<String, String> additionalParameters, String loginHint, ArrayList<String> promptValues) {
503+
private AuthorizationTokenRequestParameters(String clientId, String issuer, String discoveryUrl, ArrayList<String> scopes, String redirectUrl, Map<String, String> serviceConfigurationParameters, Map<String, String> additionalParameters, String loginHint, ArrayList<String> promptValues, String responseMode) {
498504
super(clientId, issuer, discoveryUrl, scopes, redirectUrl, null, null, null, null, serviceConfigurationParameters, additionalParameters);
499505
this.loginHint = loginHint;
500506
this.promptValues = promptValues;
507+
this.responseMode = responseMode;
501508
}
502509
}
503510

flutter_appauth/ios/Classes/FlutterAppauthPlugin.m

+6
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ - (id)initWithArguments:(NSDictionary *)arguments {
5757
@interface AuthorizationTokenRequestParameters : TokenRequestParameters
5858
@property(nonatomic, strong) NSString *loginHint;
5959
@property(nonatomic, strong) NSArray *promptValues;
60+
@property(nonatomic, strong) NSString *responseMode;
6061
@end
6162

6263
@implementation AuthorizationTokenRequestParameters
6364
- (id)initWithArguments:(NSDictionary *)arguments {
6465
[super processArguments:arguments];
6566
_loginHint = [ArgumentProcessor processArgumentValue:arguments withKey:@"loginHint"];
6667
_promptValues = [ArgumentProcessor processArgumentValue:arguments withKey:@"promptValues"];
68+
_responseMode = [ArgumentProcessor processArgumentValue:arguments withKey:@"responseMode"];
6769
return self;
6870
}
6971
@end
@@ -120,6 +122,10 @@ -(void)handleAuthorizeMethodCall:(NSDictionary*)arguments result:(FlutterResult)
120122
[self ensureAdditionalParametersInitialized:requestParameters];
121123
[requestParameters.additionalParameters setValue:[requestParameters.promptValues componentsJoinedByString:@","] forKey:@"prompt"];
122124
}
125+
if(requestParameters.responseMode) {
126+
[self ensureAdditionalParametersInitialized:requestParameters];
127+
[requestParameters.additionalParameters setValue:requestParameters.responseMode forKey:@"response_mode"];
128+
}
123129
if(requestParameters.serviceConfigurationParameters != nil) {
124130
OIDServiceConfiguration *serviceConfiguration =
125131
[[OIDServiceConfiguration alloc]

flutter_appauth/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_appauth
22
description: This plugin provides an abstraction around the Android and iOS AppAuth SDKs so it can be used to communicate with OAuth 2.0 and OpenID Connect providers
3-
version: 1.0.0+1
3+
version: 1.1.0
44
homepage: https://github.com/MaikuB/flutter_appauth/tree/master/flutter_appauth
55

66
environment:

flutter_appauth_platform_interface/CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [3.1.0]
2+
3+
* Added the ability to specify the response mode for authorization requests. This can be done using the `responseMode` parameter when constructing either an `AuthorizationRequest` or `AuthorizationTokenRequest`. This was done as the AppAuth Android SDK throws an exception when this was done via `additionalParameters`.
4+
15
## [3.0.0]
26

37
* Migrated to null safety
@@ -22,4 +26,4 @@
2226

2327
## [1.0.0]
2428

25-
* Initial release of platform interface
29+
* Initial release of platform interface

flutter_appauth_platform_interface/lib/src/authorization_parameters.dart

+2
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ mixin AuthorizationParameters {
99
///
1010
/// This property is only applicable to iOS versions 13 and above.
1111
bool? preferEphemeralSession;
12+
13+
String? responseMode;
1214
}

flutter_appauth_platform_interface/lib/src/authorization_request.dart

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class AuthorizationRequest extends CommonRequestDetails
1717
List<String>? promptValues,
1818
bool allowInsecureConnections = false,
1919
bool preferEphemeralSession = false,
20+
String? responseMode,
2021
}) {
2122
this.clientId = clientId;
2223
this.redirectUrl = redirectUrl;
@@ -29,5 +30,6 @@ class AuthorizationRequest extends CommonRequestDetails
2930
this.promptValues = promptValues;
3031
this.allowInsecureConnections = allowInsecureConnections;
3132
this.preferEphemeralSession = preferEphemeralSession;
33+
this.responseMode = responseMode;
3234
}
3335
}

flutter_appauth_platform_interface/lib/src/authorization_token_request.dart

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class AuthorizationTokenRequest extends TokenRequest
1919
List<String>? promptValues,
2020
bool allowInsecureConnections = false,
2121
bool preferEphemeralSession = false,
22+
String? responseMode,
2223
}) : super(
2324
clientId,
2425
redirectUrl,
@@ -34,5 +35,6 @@ class AuthorizationTokenRequest extends TokenRequest
3435
this.loginHint = loginHint;
3536
this.promptValues = promptValues;
3637
this.preferEphemeralSession = preferEphemeralSession;
38+
this.responseMode = responseMode;
3739
}
3840
}

flutter_appauth_platform_interface/lib/src/method_channel_mappers.dart

+1
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,6 @@ Map<String, Object?> _convertAuthorizationParametersToMap(
8181
'loginHint': authorizationParameters.loginHint,
8282
'promptValues': authorizationParameters.promptValues,
8383
'preferEphemeralSession': authorizationParameters.preferEphemeralSession,
84+
'responseMode': authorizationParameters.responseMode,
8485
};
8586
}

flutter_appauth_platform_interface/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_appauth_platform_interface
22
description: A common platform interface for the flutter_appauth plugin.
3-
version: 3.0.0
3+
version: 3.1.0
44
homepage: https://github.com/MaikuB/flutter_appauth/tree/master/flutter_appauth_platform_interface
55

66
environment:
@@ -15,4 +15,4 @@ dependencies:
1515
dev_dependencies:
1616
flutter_test:
1717
sdk: flutter
18-
mockito: ^5.0.0-nullsafety.7
18+
mockito: ^5.0.0-nullsafety.7

flutter_appauth_platform_interface/test/method_channel_flutter_appauth_test.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void main() {
3939
'allowInsecureConnections': false,
4040
'preferEphemeralSession': false,
4141
'promptValues': null,
42+
'responseMode': null
4243
})
4344
],
4445
);
@@ -47,7 +48,7 @@ void main() {
4748
test('authorizeAndExchangeCode', () async {
4849
await flutterAppAuth.authorizeAndExchangeCode(AuthorizationTokenRequest(
4950
'someClientId', 'someRedirectUrl',
50-
discoveryUrl: 'someDiscoveryUrl', loginHint: 'someLoginHint'));
51+
discoveryUrl: 'someDiscoveryUrl', loginHint: 'someLoginHint', responseMode: 'fragment'));
5152
expect(
5253
log,
5354
<Matcher>[
@@ -67,7 +68,8 @@ void main() {
6768
'refreshToken': null,
6869
'authorizationCode': null,
6970
'grantType': 'authorization_code',
70-
'codeVerifier': null
71+
'codeVerifier': null,
72+
'responseMode': 'fragment'
7173
})
7274
],
7375
);

0 commit comments

Comments
 (0)