Skip to content

Commit

Permalink
Merge pull request #274 from Earlybyte/upgradeSdkVersion
Browse files Browse the repository at this point in the history
Upgrade sdk version
  • Loading branch information
josemiguelvarela authored Oct 11, 2023
2 parents c90028a + 4362866 commit d05e1a6
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 99 deletions.
80 changes: 28 additions & 52 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,54 +1,30 @@
# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# Google internally enforced rules. See README.md for more information,
# including a list of lints that are intentionally _not_ enforced.
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

linter:
rules:
- always_declare_return_types
- always_require_non_null_named_parameters
- annotate_overrides
- avoid_empty_else
- avoid_init_to_null
- avoid_null_checks_in_equality_operators
- avoid_relative_lib_imports
- avoid_return_types_on_setters
- avoid_shadowing_type_parameters
- avoid_types_as_parameter_names
- camel_case_extensions
- curly_braces_in_flow_control_structures
- empty_catches
- empty_constructor_bodies
- library_names
- library_prefixes
- no_duplicate_case_values
- null_closures
- omit_local_variable_types
- prefer_adjacent_string_concatenation
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_contains
- prefer_equal_for_default_values
- prefer_final_fields
- prefer_for_elements_to_map_fromIterable
- prefer_generic_function_type_aliases
- prefer_if_null_operators
- prefer_is_empty
- prefer_is_not_empty
- prefer_iterable_whereType
- prefer_single_quotes
- prefer_spread_collections
- recursive_getters
- slash_for_doc_comments
- type_init_formals
- unawaited_futures
- unnecessary_const
- unnecessary_new
- unnecessary_null_in_if_null_operators
- unnecessary_this
- unrelated_type_equality_checks
- use_function_type_syntax_for_parameters
- use_rethrow_when_possible
- valid_regexps
# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
10 changes: 5 additions & 5 deletions lib/helper/core_oauth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ class CoreOAuth {

Future<Either<Failure, Token>> login(
{bool refreshIfAvailable = false}) async =>
throw UnsupportedFailure(ErrorType.Unsupported, 'Unsupported login');
throw UnsupportedFailure(ErrorType.unsupported, 'Unsupported login');

Future<Either<Failure, Token>> refreshToken() async =>
throw UnsupportedFailure(
ErrorType.Unsupported, 'Unsupported silentlyLogin');
ErrorType.unsupported, 'Unsupported silentlyLogin');

Future<void> logout() async =>
throw UnsupportedFailure(ErrorType.Unsupported, 'Unsupported logout');
throw UnsupportedFailure(ErrorType.unsupported, 'Unsupported logout');

Future<bool> get hasCachedAccountInformation async => false;

Future<String?> getAccessToken() async => throw UnsupportedFailure(
ErrorType.Unsupported, 'Unsupported getAccessToken');
ErrorType.unsupported, 'Unsupported getAccessToken');

Future<String?> getIdToken() async => throw UnsupportedFailure(
ErrorType.Unsupported, 'Unsupported getAccessToken');
ErrorType.unsupported, 'Unsupported getAccessToken');

factory CoreOAuth.fromConfig(Config config) =>
config.isStub ? MockCoreOAuth() : getOAuthConfig(config);
Expand Down
12 changes: 6 additions & 6 deletions lib/helper/mobile_oauth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ class MobileOAuth extends CoreOAuth {

if (!token.hasValidAccessToken()) {
final result = await _performFullAuthFlow();
var failure;
Failure? failure;
result.fold(
(l) => failure = l,
(r) => token = r,
);
if (failure != null) {
return Left(failure);
return Left(failure!);
}
}

Expand All @@ -160,7 +160,7 @@ class MobileOAuth extends CoreOAuth {
var code = await _requestCode.requestCode();
if (code == null) {
return Left(AadOauthFailure(
ErrorType.AccessDeniedOrAuthenticationCanceled,
ErrorType.accessDeniedOrAuthenticationCanceled,
'Access denied or authentication canceled.',
));
}
Expand All @@ -169,10 +169,10 @@ class MobileOAuth extends CoreOAuth {

Future<void> _removeOldTokenOnFirstLogin() async {
var prefs = await SharedPreferences.getInstance();
final _keyFreshInstall = 'freshInstall';
if (!prefs.getKeys().contains(_keyFreshInstall)) {
final keyFreshInstall = 'freshInstall';
if (!prefs.getKeys().contains(keyFreshInstall)) {
await logout();
await prefs.setBool(_keyFreshInstall, false);
await prefs.setBool(keyFreshInstall, false);
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions lib/helper/web_oauth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ class WebOAuth extends CoreOAuth {
refreshIfAvailable,
config.webUseRedirect,
allowInterop(
(_value) => completer.complete(Right(Token(accessToken: _value)))),
allowInterop((_error) => completer.complete(Left(AadOauthFailure(
ErrorType.AccessDeniedOrAuthenticationCanceled,
'Access denied or authentication canceled. Error: ${_error.toString()}',
(value) => completer.complete(Right(Token(accessToken: value)))),
allowInterop((error) => completer.complete(Left(AadOauthFailure(
ErrorType.accessDeniedOrAuthenticationCanceled,
'Access denied or authentication canceled. Error: ${error.toString()}',
)))),
);

Expand All @@ -118,10 +118,10 @@ class WebOAuth extends CoreOAuth {

jsRefreshToken(
allowInterop(
(_value) => completer.complete(Right(Token(accessToken: _value)))),
allowInterop((_error) => completer.complete(Left(AadOauthFailure(
ErrorType.AccessDeniedOrAuthenticationCanceled,
'Access denied or authentication canceled. Error: ${_error.toString()}',
(value) => completer.complete(Right(Token(accessToken: value)))),
allowInterop((error) => completer.complete(Left(AadOauthFailure(
ErrorType.accessDeniedOrAuthenticationCanceled,
'Access denied or authentication canceled. Error: ${error.toString()}',
)))),
);

Expand Down
5 changes: 2 additions & 3 deletions lib/model/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class Config {
base = base.substring(0, idx);
}
if (!base.endsWith('/')) {
base = base + '/';
base = '$base/';
}
return base;
} else {
Expand Down Expand Up @@ -216,7 +216,7 @@ class Config {
required this.navigatorKey,
this.origin,
this.customParameters = const {},
String? postLogoutRedirectUri,
this.postLogoutRedirectUri,
this.appBar,
}) : authorizationUrl = customAuthorizationUrl ??
(isB2C
Expand All @@ -230,7 +230,6 @@ class Config {
? 'https://$tenant.b2clogin.com/$tenant.onmicrosoft.com/$policy/oauth2/v2.0/token'
: '$customDomainUrlWithTenantId/$policy/oauth2/v2.0/token')
: 'https://login.microsoftonline.com/$tenant/oauth2/v2.0/token'),
postLogoutRedirectUri = postLogoutRedirectUri,
aOptions = aOptions ?? AndroidOptions(encryptedSharedPreferences: true),
cacheLocation = cacheLocation ?? CacheLocation.localStorage,
redirectUri = redirectUri ?? getDefaultRedirectUri();
Expand Down
8 changes: 4 additions & 4 deletions lib/model/failure.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:equatable/equatable.dart';

enum ErrorType {
AccessDeniedOrAuthenticationCanceled,
InvalidJson,
Unsupported,
UnexpectedError,
accessDeniedOrAuthenticationCanceled,
invalidJson,
unsupported,
unexpectedError,
}

abstract class Failure extends Equatable {
Expand Down
6 changes: 2 additions & 4 deletions lib/model/token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ class Token {
if (map == null) throw Exception('No token from received');
//error handling as described in https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow#error-response-1
if (map['error'] != null) {
throw Exception('Error during token request: ' +
map['error'] +
': ' +
map['error_description']);
throw Exception(
'Error during token request: ${map['error']}: ${map['error_description']}');
}

var model = Token();
Expand Down
6 changes: 2 additions & 4 deletions lib/request/authorization_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ class AuthorizationRequest {
final bool clearCookies;

AuthorizationRequest(Config config,
{bool fullScreen = true, bool clearCookies = false})
{this.fullScreen = true, this.clearCookies = false})
: url = config.authorizationUrl,
redirectUrl = config.redirectUri,
parameters = {
'client_id': config.clientId,
'response_type': config.responseType,
'redirect_uri': config.redirectUri,
'scope': config.scope,
},
fullScreen = fullScreen,
clearCookies = clearCookies {
} {
if (config.state != null) {
parameters.putIfAbsent('state', () => config.state!);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/request_code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'request/authorization_request.dart';
class RequestCode {
final Config _config;
final AuthorizationRequest _authorizationRequest;
final _redirectUriHost;
final String _redirectUriHost;
late NavigationDelegate _navigationDelegate;
String? _code;

Expand Down
14 changes: 7 additions & 7 deletions lib/request_token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ class RequestToken {
RequestToken(this.config);

Future<Either<Failure, Token>> requestToken(String code) async {
final _tokenRequest = TokenRequestDetails(config, code);
final tokenRequest = TokenRequestDetails(config, code);
return await _sendTokenRequest(
_tokenRequest.url, _tokenRequest.params, _tokenRequest.headers);
tokenRequest.url, tokenRequest.params, tokenRequest.headers);
}

Future<Either<Failure, Token>> requestRefreshToken(
String refreshToken) async {
final _tokenRefreshRequest =
final tokenRefreshRequest =
TokenRefreshRequestDetails(config, refreshToken);
return await _sendTokenRequest(_tokenRefreshRequest.url,
_tokenRefreshRequest.params, _tokenRefreshRequest.headers);
return await _sendTokenRequest(tokenRefreshRequest.url,
tokenRefreshRequest.params, tokenRefreshRequest.headers);
}

Future<Either<Failure, Token>> _sendTokenRequest(String url,
Expand All @@ -39,10 +39,10 @@ class RequestToken {
return Right(token);
}
return Left(
RequestFailure(ErrorType.InvalidJson, 'Token json is invalid'));
RequestFailure(ErrorType.invalidJson, 'Token json is invalid'));
} catch (e) {
return Left(RequestFailure(
ErrorType.InvalidJson, 'Token json is invalid: ${e.toString()}'));
ErrorType.invalidJson, 'Token json is invalid: ${e.toString()}'));
}
}
}
10 changes: 5 additions & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ version: 1.0.0
homepage: https://github.com/Earlybyte/aad_oauth

environment:
sdk: '>=2.17.0 <3.0.0'
sdk: '>=3.0.0 <4.0.0'

dependencies:
flutter:
sdk: flutter
flutter_secure_storage: ^9.0.0
webview_flutter: ^4.4.1
js: any
http: ^1.1.0
pedantic: ^1.11.1
webview_flutter: ^4.4.1
js: ^0.6.7
http: ^1.1.0
lints: ^2.1.1
shared_preferences: ^2.2.1
dartz: ^0.10.1
equatable: ^2.0.5
Expand Down

0 comments on commit d05e1a6

Please sign in to comment.