Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[various] updated methods to return non-nullable types #519

Merged
merged 2 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions flutter_appauth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [7.0.0-dev.3]

* **Breaking change** all methods have now been made to return non-nullable types

# 7.0.0-dev.2

* The `errorUri` property of the `FlutterAppAuthPlatformErrorDetails` class will now be populated on iOS/maCOS if available
Expand Down
28 changes: 11 additions & 17 deletions flutter_appauth/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class _MyAppState extends State<MyApp> {
Future<void> _refresh() async {
try {
_setBusyState();
final TokenResponse? result = await _appAuth.token(TokenRequest(
final TokenResponse result = await _appAuth.token(TokenRequest(
_clientId, _redirectUrl,
refreshToken: _refreshToken, issuer: _issuer, scopes: _scopes));
_processTokenResponse(result);
Expand All @@ -203,7 +203,7 @@ class _MyAppState extends State<MyApp> {
Future<void> _exchangeCode() async {
try {
_setBusyState();
final TokenResponse? result = await _appAuth.token(TokenRequest(
final TokenResponse result = await _appAuth.token(TokenRequest(
_clientId, _redirectUrl,
authorizationCode: _authorizationCode,
discoveryUrl: _discoveryUrl,
Expand Down Expand Up @@ -233,7 +233,7 @@ class _MyAppState extends State<MyApp> {
Code challenge is not used according to the spec
https://www.rfc-editor.org/rfc/rfc7636 page 9 section 4.5.
*/
final AuthorizationResponse? result = await _appAuth.authorize(
final AuthorizationResponse result = await _appAuth.authorize(
AuthorizationRequest(_clientId, _redirectUrl,
discoveryUrl: _discoveryUrl, scopes: _scopes, loginHint: 'bob'),
);
Expand All @@ -250,9 +250,7 @@ class _MyAppState extends State<MyApp> {
);
*/

if (result != null) {
_processAuthResponse(result);
}
_processAuthResponse(result);
} catch (e) {
_handleError(e);
} finally {
Expand All @@ -267,17 +265,15 @@ class _MyAppState extends State<MyApp> {
final String nonce =
base64Url.encode(List<int>.generate(16, (_) => random.nextInt(256)));
// use the discovery endpoint to find the configuration
final AuthorizationResponse? result = await _appAuth.authorize(
final AuthorizationResponse result = await _appAuth.authorize(
AuthorizationRequest(_clientId, _redirectUrl,
discoveryUrl: _discoveryUrl,
scopes: _scopes,
loginHint: 'bob',
nonce: nonce),
);

if (result != null) {
_processAuthResponse(result);
}
_processAuthResponse(result);
} catch (e) {
_handleError(e);
} finally {
Expand All @@ -294,7 +290,7 @@ class _MyAppState extends State<MyApp> {
This shows that we can also explicitly specify the endpoints rather than
getting from the details from the discovery document.
*/
final AuthorizationTokenResponse? result =
final AuthorizationTokenResponse result =
await _appAuth.authorizeAndExchangeCode(
AuthorizationTokenRequest(
_clientId,
Expand Down Expand Up @@ -322,10 +318,8 @@ class _MyAppState extends State<MyApp> {
```
*/

if (result != null) {
_processAuthTokenResponse(result);
await _testApi(result);
}
_processAuthTokenResponse(result);
await _testApi(result);
} catch (e) {
_handleError(e);
} finally {
Expand Down Expand Up @@ -391,9 +385,9 @@ class _MyAppState extends State<MyApp> {
});
}

void _processTokenResponse(TokenResponse? response) {
void _processTokenResponse(TokenResponse response) {
setState(() {
_accessToken = _accessTokenTextController.text = response!.accessToken!;
_accessToken = _accessTokenTextController.text = response.accessToken!;
_idToken = _idTokenTextController.text = response.idToken!;
_refreshToken = _refreshTokenTextController.text = response.refreshToken!;
_accessTokenExpirationTextController.text =
Expand Down
8 changes: 4 additions & 4 deletions flutter_appauth/lib/src/flutter_appauth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ class FlutterAppAuth {
const FlutterAppAuth();

/// Convenience method for authorizing and then exchanges code
Future<AuthorizationTokenResponse?> authorizeAndExchangeCode(
Future<AuthorizationTokenResponse> authorizeAndExchangeCode(
AuthorizationTokenRequest request) {
return FlutterAppAuthPlatform.instance.authorizeAndExchangeCode(request);
}

/// Sends an authorization request
Future<AuthorizationResponse?> authorize(AuthorizationRequest request) {
Future<AuthorizationResponse> authorize(AuthorizationRequest request) {
return FlutterAppAuthPlatform.instance.authorize(request);
}

/// For exchanging tokens
Future<TokenResponse?> token(TokenRequest request) {
Future<TokenResponse> token(TokenRequest request) {
return FlutterAppAuthPlatform.instance.token(request);
}

Future<EndSessionResponse?> endSession(EndSessionRequest request) {
Future<EndSessionResponse> endSession(EndSessionRequest request) {
return FlutterAppAuthPlatform.instance.endSession(request);
}
}
4 changes: 2 additions & 2 deletions 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: 7.0.0-dev.2
version: 7.0.0-dev.3
homepage: https://github.com/MaikuB/flutter_appauth/tree/master/flutter_appauth

environment:
Expand All @@ -10,7 +10,7 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_appauth_platform_interface: ^7.0.0-dev.2
flutter_appauth_platform_interface: ^7.0.0-dev.3

flutter:
plugin:
Expand Down
4 changes: 4 additions & 0 deletions flutter_appauth_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [7.0.0-dev.3]

* **Breaking change** all methods have now been made to return non-nullable types

## [7.0.0-dev.2]

* Updated API docs for `FlutterAppAuthPlatformErrorDetails`'s `errorUri` property as this can now be returned on iOS/macOS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ 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');
}

Future<EndSessionResponse?> endSession(EndSessionRequest request) {
Future<EndSessionResponse> endSession(EndSessionRequest request) {
throw UnimplementedError('endSession() has not been implemented');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ const MethodChannel _channel =

class MethodChannelFlutterAppAuth extends FlutterAppAuthPlatform {
@override
Future<AuthorizationResponse?> authorize(AuthorizationRequest request) async {
final Map<dynamic, dynamic>? result = await invokeMethod(
Future<AuthorizationResponse> authorize(AuthorizationRequest request) async {
final Map<dynamic, dynamic> result = await invokeMethod(
'authorize',
request.toMap(),
);

if (result == null) {
return null;
}
return AuthorizationResponse(
authorizationCode: result['authorizationCode'],
codeVerifier: result['codeVerifier'],
Expand All @@ -36,16 +33,13 @@ class MethodChannelFlutterAppAuth extends FlutterAppAuthPlatform {
}

@override
Future<AuthorizationTokenResponse?> authorizeAndExchangeCode(
Future<AuthorizationTokenResponse> authorizeAndExchangeCode(
AuthorizationTokenRequest request) async {
final Map<dynamic, dynamic>? result = await invokeMethod(
final Map<dynamic, dynamic> result = await invokeMethod(
'authorizeAndExchangeCode',
request.toMap(),
);

if (result == null) {
return null;
}
return AuthorizationTokenResponse(
result['accessToken'],
result['refreshToken'],
Expand All @@ -61,15 +55,12 @@ class MethodChannelFlutterAppAuth extends FlutterAppAuthPlatform {
}

@override
Future<TokenResponse?> token(TokenRequest request) async {
final Map<dynamic, dynamic>? result = await invokeMethod(
Future<TokenResponse> token(TokenRequest request) async {
final Map<dynamic, dynamic> result = await invokeMethod(
'token',
request.toMap(),
);

if (result == null) {
return null;
}
return TokenResponse(
result['accessToken'],
result['refreshToken'],
Expand All @@ -84,22 +75,20 @@ class MethodChannelFlutterAppAuth extends FlutterAppAuthPlatform {
}

@override
Future<EndSessionResponse?> endSession(EndSessionRequest request) async {
final Map<dynamic, dynamic>? result = await invokeMethod(
Future<EndSessionResponse> endSession(EndSessionRequest request) async {
final Map<dynamic, dynamic> result = await invokeMethod(
'endSession',
request.toMap(),
);

if (result == null) {
return null;
}
return EndSessionResponse(result['state']);
}

Future<Map<dynamic, dynamic>?> invokeMethod(
Future<Map<dynamic, dynamic>> invokeMethod(
String method, dynamic arguments) async {
try {
return await _channel.invokeMethod(method, arguments);
return (await _channel.invokeMethod<Map<dynamic, dynamic>>(
method, arguments))!;
} on PlatformException catch (e) {
if (e.details == null) {
rethrow;
Expand Down
2 changes: 1 addition & 1 deletion 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: 7.0.0-dev.2
version: 7.0.0-dev.3
homepage: https://github.com/MaikuB/flutter_appauth/tree/master/flutter_appauth_platform_interface

environment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void main() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return null;
return <Object, Object>{};
});

tearDown(() {
Expand Down
Loading