Skip to content

Commit

Permalink
- Added support to clearCache and clearCookies directly from `Oau…
Browse files Browse the repository at this point in the history
…thWebAuth.instance`.

- Full code refactor to use `BaseConfiguration(...)` and `OauthConfiguration(...)`. See readme for migration.
- SDK constraints updated to `sdk: ">=2.19.0 <3.0.0"` and `flutter: ">=2.0.0"`.
- Fixed bug in redirect url handling that caused `invalid_grant` due to content after `#` in url.
  • Loading branch information
luis901101 committed Apr 4, 2023
1 parent 952225a commit a4c0050
Show file tree
Hide file tree
Showing 22 changed files with 960 additions and 911 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ Types of changes
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## 4.0.0+14
### Added
- Added support to `clearCache` and `clearCookies` directly from `OauthWebAuth.instance`.

### Changed
- Full code refactor to use `BaseConfiguration(...)` and `OauthConfiguration(...)`. See readme for migration.
- SDK constraints updated to `sdk: ">=2.19.0 <3.0.0"` and `flutter: ">=2.0.0"`.

### Fixed
- Fixed bug in redirect url handling that caused `invalid_grant` due to content after `#` in url.

## 3.1.2+13
### Fixed
- Fixed bug on BaseOAuthFlowMixin onSuccess function that caused wrong flow cancellation on baseUrl redirect.
Expand Down
4 changes: 2 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ linter:
use_key_in_widget_constructors: false
constant_identifier_names: false
depend_on_referenced_packages: false
library_private_types_in_public_api: true # Change to true when there are no branches to merge
prefer_single_quotes: true # Change to true when there are no branches to merge
library_private_types_in_public_api: true
prefer_single_quotes: true

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.7.20'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 7368163408c647b7eb699d0d788ba6718e18fb8d

COCOAPODS: 1.11.3
COCOAPODS: 1.12.0
4 changes: 3 additions & 1 deletion example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -221,6 +221,7 @@
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand All @@ -235,6 +236,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down
2 changes: 2 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ class _MyHomePageState extends State<MyHomePage> {
onPressed: () {
goAuthSampleScreen();
},
child: const Text('Oauth login samples'),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.green)),
child: const Text('Oauth login samples'),
),
const SizedBox(height: 4),
ElevatedButton(
Expand Down
150 changes: 77 additions & 73 deletions example/lib/src/auth_sample_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
// ignore: depend_on_referenced_packages
import 'package:oauth2/oauth2.dart';
import 'package:oauth_webauth/oauth_webauth.dart';

Expand Down Expand Up @@ -87,10 +88,10 @@ class _AuthSampleScreenState extends State<AuthSampleScreen> {
),
ElevatedButton(
onPressed: kIsWeb ? null : loginV1,
child: const Text(
'Login variant 1${kIsWeb ? '(NOT SUPPORTED ON WEB)' : ''}'),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.green)),
child: const Text(
'Login variant 1${kIsWeb ? '(NOT SUPPORTED ON WEB)' : ''}'),
),
const SizedBox(height: 4),
ElevatedButton(
Expand All @@ -106,33 +107,34 @@ class _AuthSampleScreenState extends State<AuthSampleScreen> {

void loginV1() async {
final result = await OAuthWebScreen.start(
context: context,
authorizationEndpointUrl: authorizationEndpointUrl,
tokenEndpointUrl: tokenEndpointUrl,
clientSecret: clientSecret,
clientId: clientId,
redirectUrl: redirectUrl,
scopes: scopes,
promptValues: const ['login'],
loginHint: '[email protected]',
onCertificateValidate: (certificate) {
///This is recommended
/// Do certificate validations here
/// If false is returned then a CertificateException() will be thrown
return true;
},
textLocales: {
///Optionally texts can be localized
BaseWebView.backButtonTooltipKey: 'Ir atrás',
BaseWebView.forwardButtonTooltipKey: 'Ir adelante',
BaseWebView.reloadButtonTooltipKey: 'Recargar',
BaseWebView.clearCacheButtonTooltipKey: 'Limpiar caché',
BaseWebView.closeButtonTooltipKey: 'Cerrar',
BaseWebView.clearCacheWarningMessageKey:
'¿Está seguro que desea limpiar la caché?',
},
contentLocale: contentLocale,
);
context: context,
configuration: OauthConfiguration(
authorizationEndpointUrl: authorizationEndpointUrl,
tokenEndpointUrl: tokenEndpointUrl,
clientSecret: clientSecret,
clientId: clientId,
redirectUrl: redirectUrl,
scopes: scopes,
promptValues: const ['login'],
loginHint: '[email protected]',
onCertificateValidate: (certificate) {
///This is recommended
/// Do certificate validations here
/// If false is returned then a CertificateException() will be thrown
return true;
},
textLocales: {
///Optionally texts can be localized
BaseConfiguration.backButtonTooltipKey: 'Ir atrás',
BaseConfiguration.forwardButtonTooltipKey: 'Ir adelante',
BaseConfiguration.reloadButtonTooltipKey: 'Recargar',
BaseConfiguration.clearCacheButtonTooltipKey: 'Limpiar caché',
BaseConfiguration.closeButtonTooltipKey: 'Cerrar',
BaseConfiguration.clearCacheWarningMessageKey:
'¿Está seguro que desea limpiar la caché?',
},
contentLocale: contentLocale,
));
isLoading = false;
if (result != null) {
if (result is Credentials) {
Expand All @@ -148,50 +150,52 @@ class _AuthSampleScreenState extends State<AuthSampleScreen> {

void loginV2() {
OAuthWebScreen.start(
context: context,
authorizationEndpointUrl: authorizationEndpointUrl,
tokenEndpointUrl: tokenEndpointUrl,
clientSecret: clientSecret,
clientId: clientId,
redirectUrl: redirectUrl,
scopes: scopes,
promptValues: const ['login'],
loginHint: '[email protected]',
onCertificateValidate: (certificate) {
///This is recommended
/// Do certificate validations here
/// If false is returned then a CertificateException() will be thrown
return true;
},
textLocales: {
///Optionally text can be localized
BaseWebView.backButtonTooltipKey: 'Ir atrás',
BaseWebView.forwardButtonTooltipKey: 'Ir adelante',
BaseWebView.reloadButtonTooltipKey: 'Recargar',
BaseWebView.clearCacheButtonTooltipKey: 'Limpiar caché',
BaseWebView.closeButtonTooltipKey: 'Cerrar',
BaseWebView.clearCacheWarningMessageKey:
'¿Está seguro que desea limpiar la caché?',
},
contentLocale: contentLocale,
onSuccess: (credentials) {
isLoading = false;
setState(() {
authResponse = getPrettyCredentialsJson(credentials);
});
},
onError: (error) {
isLoading = false;
setState(() {
authResponse = error.toString();
});
},
onCancel: () {
isLoading = false;
setState(() {
authResponse = 'User cancelled authentication';
});
});
context: context,
configuration: OauthConfiguration(
authorizationEndpointUrl: authorizationEndpointUrl,
tokenEndpointUrl: tokenEndpointUrl,
clientSecret: clientSecret,
clientId: clientId,
redirectUrl: redirectUrl,
scopes: scopes,
promptValues: const ['login'],
loginHint: '[email protected]',
onCertificateValidate: (certificate) {
///This is recommended
/// Do certificate validations here
/// If false is returned then a CertificateException() will be thrown
return true;
},
textLocales: {
///Optionally text can be localized
BaseConfiguration.backButtonTooltipKey: 'Ir atrás',
BaseConfiguration.forwardButtonTooltipKey: 'Ir adelante',
BaseConfiguration.reloadButtonTooltipKey: 'Recargar',
BaseConfiguration.clearCacheButtonTooltipKey: 'Limpiar caché',
BaseConfiguration.closeButtonTooltipKey: 'Cerrar',
BaseConfiguration.clearCacheWarningMessageKey:
'¿Está seguro que desea limpiar la caché?',
},
contentLocale: contentLocale,
onSuccessAuth: (credentials) {
isLoading = false;
setState(() {
authResponse = getPrettyCredentialsJson(credentials);
});
},
onError: (error) {
isLoading = false;
setState(() {
authResponse = error.toString();
});
},
onCancel: () {
isLoading = false;
setState(() {
authResponse = 'User cancelled authentication';
});
}),
);
}

String getPrettyCredentialsJson(Credentials credentials) {
Expand Down
Loading

0 comments on commit a4c0050

Please sign in to comment.