Skip to content

Commit

Permalink
[flutter_appauth][flutter_appauth_platform_interface] add responseMod…
Browse files Browse the repository at this point in the history
…e as parameter for android and ios (MaikuB#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]>
  • Loading branch information
3 people authored Jul 10, 2021
1 parent be0fd7a commit 3aef4a6
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 13 deletions.
4 changes: 4 additions & 0 deletions flutter_appauth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.0

* * 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`.

## 1.0.0+1

* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ private AuthorizationTokenRequestParameters processAuthorizationTokenRequestArgu
Map<String, String> serviceConfigurationParameters = (Map<String, String>) arguments.get("serviceConfiguration");
Map<String, String> additionalParameters = (Map<String, String>) arguments.get("additionalParameters");
allowInsecureConnections = (boolean) arguments.get("allowInsecureConnections");
return new AuthorizationTokenRequestParameters(clientId, issuer, discoveryUrl, scopes, redirectUrl, serviceConfigurationParameters, additionalParameters, loginHint, promptValues);
final String responseMode = (String) arguments.get("responseMode");

return new AuthorizationTokenRequestParameters(clientId, issuer, discoveryUrl, scopes, redirectUrl, serviceConfigurationParameters, additionalParameters, loginHint, promptValues, responseMode);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -221,13 +223,13 @@ private void handleAuthorizeMethodCall(Map<String, Object> arguments, final bool
final AuthorizationTokenRequestParameters tokenRequestParameters = processAuthorizationTokenRequestArguments(arguments);
if (tokenRequestParameters.serviceConfigurationParameters != null) {
AuthorizationServiceConfiguration serviceConfiguration = requestParametersToServiceConfiguration(tokenRequestParameters);
performAuthorization(serviceConfiguration, tokenRequestParameters.clientId, tokenRequestParameters.redirectUrl, tokenRequestParameters.scopes, tokenRequestParameters.loginHint, tokenRequestParameters.additionalParameters, exchangeCode, tokenRequestParameters.promptValues);
performAuthorization(serviceConfiguration, tokenRequestParameters.clientId, tokenRequestParameters.redirectUrl, tokenRequestParameters.scopes, tokenRequestParameters.loginHint, tokenRequestParameters.additionalParameters, exchangeCode, tokenRequestParameters.promptValues, tokenRequestParameters.responseMode);
} else {
AuthorizationServiceConfiguration.RetrieveConfigurationCallback callback = new AuthorizationServiceConfiguration.RetrieveConfigurationCallback() {
@Override
public void onFetchConfigurationCompleted(@Nullable AuthorizationServiceConfiguration serviceConfiguration, @Nullable AuthorizationException ex) {
if (ex == null) {
performAuthorization(serviceConfiguration, tokenRequestParameters.clientId, tokenRequestParameters.redirectUrl, tokenRequestParameters.scopes, tokenRequestParameters.loginHint, tokenRequestParameters.additionalParameters, exchangeCode, tokenRequestParameters.promptValues);
performAuthorization(serviceConfiguration, tokenRequestParameters.clientId, tokenRequestParameters.redirectUrl, tokenRequestParameters.scopes, tokenRequestParameters.loginHint, tokenRequestParameters.additionalParameters, exchangeCode, tokenRequestParameters.promptValues, tokenRequestParameters.responseMode);
} else {
finishWithDiscoveryError(ex);
}
Expand Down Expand Up @@ -282,7 +284,7 @@ public void onFetchConfigurationCompleted(@Nullable AuthorizationServiceConfigur
}


private void performAuthorization(AuthorizationServiceConfiguration serviceConfiguration, String clientId, String redirectUrl, ArrayList<String> scopes, String loginHint, Map<String, String> additionalParameters, boolean exchangeCode, ArrayList<String> promptValues) {
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) {
AuthorizationRequest.Builder authRequestBuilder =
new AuthorizationRequest.Builder(
serviceConfiguration,
Expand All @@ -297,15 +299,18 @@ private void performAuthorization(AuthorizationServiceConfiguration serviceConfi
authRequestBuilder.setLoginHint(loginHint);
}

if(promptValues != null && !promptValues.isEmpty()) {
if (promptValues != null && !promptValues.isEmpty()) {
authRequestBuilder.setPromptValues(promptValues);
}

if (responseMode != null) {
authRequestBuilder.setResponseMode(responseMode);
}

if (additionalParameters != null && !additionalParameters.isEmpty()) {
authRequestBuilder.setAdditionalParameters(additionalParameters);
}


AuthorizationService authorizationService = allowInsecureConnections ? insecureAuthorizationService : defaultAuthorizationService;
Intent authIntent = authorizationService.getAuthorizationRequestIntent(authRequestBuilder.build());
mainActivity.startActivityForResult(authIntent, exchangeCode ? RC_AUTH_EXCHANGE_CODE : RC_AUTH);
Expand Down Expand Up @@ -493,11 +498,13 @@ private TokenRequestParameters(String clientId, String issuer, String discoveryU
private class AuthorizationTokenRequestParameters extends TokenRequestParameters {
final String loginHint;
final ArrayList<String> promptValues;
final String responseMode;

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) {
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) {
super(clientId, issuer, discoveryUrl, scopes, redirectUrl, null, null, null, null, serviceConfigurationParameters, additionalParameters);
this.loginHint = loginHint;
this.promptValues = promptValues;
this.responseMode = responseMode;
}
}

Expand Down
6 changes: 6 additions & 0 deletions flutter_appauth/ios/Classes/FlutterAppauthPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ - (id)initWithArguments:(NSDictionary *)arguments {
@interface AuthorizationTokenRequestParameters : TokenRequestParameters
@property(nonatomic, strong) NSString *loginHint;
@property(nonatomic, strong) NSArray *promptValues;
@property(nonatomic, strong) NSString *responseMode;
@end

@implementation AuthorizationTokenRequestParameters
- (id)initWithArguments:(NSDictionary *)arguments {
[super processArguments:arguments];
_loginHint = [ArgumentProcessor processArgumentValue:arguments withKey:@"loginHint"];
_promptValues = [ArgumentProcessor processArgumentValue:arguments withKey:@"promptValues"];
_responseMode = [ArgumentProcessor processArgumentValue:arguments withKey:@"responseMode"];
return self;
}
@end
Expand Down Expand Up @@ -120,6 +122,10 @@ -(void)handleAuthorizeMethodCall:(NSDictionary*)arguments result:(FlutterResult)
[self ensureAdditionalParametersInitialized:requestParameters];
[requestParameters.additionalParameters setValue:[requestParameters.promptValues componentsJoinedByString:@","] forKey:@"prompt"];
}
if(requestParameters.responseMode) {
[self ensureAdditionalParametersInitialized:requestParameters];
[requestParameters.additionalParameters setValue:requestParameters.responseMode forKey:@"response_mode"];
}
if(requestParameters.serviceConfigurationParameters != nil) {
OIDServiceConfiguration *serviceConfiguration =
[[OIDServiceConfiguration alloc]
Expand Down
2 changes: 1 addition & 1 deletion flutter_appauth/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_appauth
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
version: 1.0.0+1
version: 1.1.0
homepage: https://github.com/MaikuB/flutter_appauth/tree/master/flutter_appauth

environment:
Expand Down
6 changes: 5 additions & 1 deletion flutter_appauth_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [3.1.0]

* 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`.

## [3.0.0]

* Migrated to null safety
Expand All @@ -22,4 +26,4 @@

## [1.0.0]

* Initial release of platform interface
* Initial release of platform interface
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ mixin AuthorizationParameters {
///
/// This property is only applicable to iOS versions 13 and above.
bool? preferEphemeralSession;

String? responseMode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AuthorizationRequest extends CommonRequestDetails
List<String>? promptValues,
bool allowInsecureConnections = false,
bool preferEphemeralSession = false,
String? responseMode,
}) {
this.clientId = clientId;
this.redirectUrl = redirectUrl;
Expand All @@ -29,5 +30,6 @@ class AuthorizationRequest extends CommonRequestDetails
this.promptValues = promptValues;
this.allowInsecureConnections = allowInsecureConnections;
this.preferEphemeralSession = preferEphemeralSession;
this.responseMode = responseMode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AuthorizationTokenRequest extends TokenRequest
List<String>? promptValues,
bool allowInsecureConnections = false,
bool preferEphemeralSession = false,
String? responseMode,
}) : super(
clientId,
redirectUrl,
Expand All @@ -34,5 +35,6 @@ class AuthorizationTokenRequest extends TokenRequest
this.loginHint = loginHint;
this.promptValues = promptValues;
this.preferEphemeralSession = preferEphemeralSession;
this.responseMode = responseMode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ Map<String, Object?> _convertAuthorizationParametersToMap(
'loginHint': authorizationParameters.loginHint,
'promptValues': authorizationParameters.promptValues,
'preferEphemeralSession': authorizationParameters.preferEphemeralSession,
'responseMode': authorizationParameters.responseMode,
};
}
4 changes: 2 additions & 2 deletions flutter_appauth_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_appauth_platform_interface
description: A common platform interface for the flutter_appauth plugin.
version: 3.0.0
version: 3.1.0
homepage: https://github.com/MaikuB/flutter_appauth/tree/master/flutter_appauth_platform_interface

environment:
Expand All @@ -15,4 +15,4 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^5.0.0-nullsafety.7
mockito: ^5.0.0-nullsafety.7
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void main() {
'allowInsecureConnections': false,
'preferEphemeralSession': false,
'promptValues': null,
'responseMode': null
})
],
);
Expand All @@ -47,7 +48,7 @@ void main() {
test('authorizeAndExchangeCode', () async {
await flutterAppAuth.authorizeAndExchangeCode(AuthorizationTokenRequest(
'someClientId', 'someRedirectUrl',
discoveryUrl: 'someDiscoveryUrl', loginHint: 'someLoginHint'));
discoveryUrl: 'someDiscoveryUrl', loginHint: 'someLoginHint', responseMode: 'fragment'));
expect(
log,
<Matcher>[
Expand All @@ -67,7 +68,8 @@ void main() {
'refreshToken': null,
'authorizationCode': null,
'grantType': 'authorization_code',
'codeVerifier': null
'codeVerifier': null,
'responseMode': 'fragment'
})
],
);
Expand Down

0 comments on commit 3aef4a6

Please sign in to comment.