Skip to content

Commit

Permalink
- userAgent can now be set in OAuthConfiguration and `BaseConfigu…
Browse files Browse the repository at this point in the history
…ration`.

- `useHybridComposition` can now be set in `OAuthConfiguration` and `BaseConfiguration`.
  • Loading branch information
luis901101 committed Aug 13, 2024
1 parent 5d88d5a commit 637c8e0
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 15 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ Types of changes
- `Security` in case of vulnerabilities.

## 5.1.0
### Changed
-
### Added
- `userAgent` can now be set in `OAuthConfiguration` and `BaseConfiguration`.
- `useHybridComposition` can now be set in `OAuthConfiguration` and `BaseConfiguration`.

## 5.0.0+1
### Changed
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ With this plugin you will get:
- Users will not be affected by any system browser problem cache and also will be able to clean app browser cache from the authentication screen itself.
- Authentication page locale can be set from app using the `contentLocale` property to ensure the same locale. By default Operating System locale will be used if no `contentLocale` is specified.
- Custom headers can be set if necessary.
- Custom UserAgent can be set if necessary.

**Notes:**
- `contentLocale` will apply only if the authentication page supports the specified `Locale('...')` and accepts the header: `'Accept-Language': 'es-ES'`.
- Web implementation deson't allow `contentLocale`, custom headers, nor full control over UI, because web implementation loads the page directly in the browser.
- Web implementation deson't allow `contentLocale`, custom headers, custom UserAgent, nor full control over UI, because web implementation loads the page directly in the browser.

## Migration from ^1.0.0 to ^2.0.0
- Static constants key for tooltips, message and hero tags were moved from `OAuthWebView` to `BaseWebView`
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ packages:
path: ".."
relative: true
source: path
version: "6.0.0"
version: "5.1.0"
path:
dependency: transitive
description:
Expand Down
25 changes: 25 additions & 0 deletions lib/src/base/model/base_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,26 @@ class BaseConfiguration {
/// Not available for Web
final CertificateValidator? onCertificateValidate;

///A dictionary containing all of the HTTP header fields for a request.
/// Not available for Web
final Map<String, String> headers;

/// Sets the user-agent for the WebView.
/// Not available for Web
/// Defaults to: 'Mozilla/5.0'
/// Notes: Make sure the user-agent is compliant with the security constraints of Google's OAuth2 policies (https://developers.googleblog.com/2021/06/upcoming-security-changes-to-googles-oauth-2.0-authorization-endpoint.html)
final String userAgent;

///Set to `false` to disable Flutter Hybrid Composition. The default value is `true`.
///Hybrid Composition is supported starting with Flutter v1.20+.
///
///**NOTE for Android native WebView**: It is recommended to use Hybrid Composition only on Android 10+ for a release app,
///as it can cause framerate drops on animations in Android 9 and lower (see [Hybrid-Composition#performance](https://github.com/flutter/flutter/wiki/Hybrid-Composition#performance)).
///
///**Officially Supported Platforms/Implementations**:
///- Android native WebView
final bool useHybridComposition;

/// Use this stream when you need to asynchronously navigate to a specific url
/// Not available for Web
final Stream<String>? urlStream;
Expand Down Expand Up @@ -62,6 +79,8 @@ class BaseConfiguration {
this.onCancel,
this.onCertificateValidate,
Map<String, String>? headers,
String? userAgent,
bool? useHybridComposition,
this.urlStream,
this.themeData,
this.textLocales,
Expand All @@ -72,6 +91,8 @@ class BaseConfiguration {
bool? clearCacheBtnVisible,
bool? closeBtnVisible,
}) : headers = headers ?? const {},
userAgent = userAgent ?? 'Mozilla/5.0',
useHybridComposition = useHybridComposition ?? true,
goBackBtnVisible = goBackBtnVisible ?? true,
goForwardBtnVisible = goForwardBtnVisible ?? true,
refreshBtnVisible = refreshBtnVisible ?? true,
Expand All @@ -95,6 +116,8 @@ class BaseConfiguration {
VoidCallback? onCancel,
CertificateValidator? onCertificateValidate,
Map<String, String>? headers,
String? userAgent,
bool? useHybridComposition,
Stream<String>? urlStream,
ThemeData? themeData,
Map<String, String>? textLocales,
Expand All @@ -114,6 +137,8 @@ class BaseConfiguration {
onCertificateValidate:
onCertificateValidate ?? this.onCertificateValidate,
headers: headers ?? this.headers,
userAgent: userAgent ?? this.userAgent,
useHybridComposition: useHybridComposition ?? this.useHybridComposition,
urlStream: urlStream ?? this.urlStream,
themeData: themeData ?? this.themeData,
textLocales: textLocales ?? this.textLocales,
Expand Down
8 changes: 8 additions & 0 deletions lib/src/base/model/oauth_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class OAuthConfiguration extends BaseConfiguration {
super.onCancel,
super.onCertificateValidate,
super.headers,
super.userAgent,
super.useHybridComposition,
super.urlStream,
super.themeData,
super.textLocales,
Expand Down Expand Up @@ -131,6 +133,8 @@ class OAuthConfiguration extends BaseConfiguration {
super.onCancel,
super.onCertificateValidate,
super.headers,
super.userAgent,
super.useHybridComposition,
super.urlStream,
super.themeData,
super.textLocales,
Expand Down Expand Up @@ -164,6 +168,8 @@ class OAuthConfiguration extends BaseConfiguration {
VoidCallback? onCancel,
CertificateValidator? onCertificateValidate,
Map<String, String>? headers,
String? userAgent,
bool? useHybridComposition,
Stream<String>? urlStream,
ThemeData? themeData,
Map<String, String>? textLocales,
Expand Down Expand Up @@ -197,6 +203,8 @@ class OAuthConfiguration extends BaseConfiguration {
onCertificateValidate:
onCertificateValidate ?? this.onCertificateValidate,
headers: headers ?? this.headers,
userAgent: userAgent ?? this.userAgent,
useHybridComposition: useHybridComposition ?? this.useHybridComposition,
urlStream: urlStream ?? this.urlStream,
themeData: themeData ?? this.themeData,
textLocales: textLocales ?? this.textLocales,
Expand Down
5 changes: 3 additions & 2 deletions lib/src/base_web_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ class BaseWebScreen extends StatelessWidget {
configuration.onCancel?.call();
}

Future<bool> onBackPressed(dynamic result) async {
if (!((await globalKey.currentState?.onBackPressed(result)) ?? false)) {
Future<bool> onBackPressed({dynamic result}) async {
if (!((await globalKey.currentState?.onBackPressed(result: result)) ??
false)) {
return false;
}
configuration.onCancel?.call();
Expand Down
8 changes: 3 additions & 5 deletions lib/src/base_web_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,8 @@ class BaseWebViewState<S extends BaseWebView> extends State<S>
useShouldOverrideUrlLoading: true,
supportZoom: false,
transparentBackground: true,

/// This custom userAgent is mandatory due to security constraints of Google's OAuth2 policies (https://developers.googleblog.com/2021/06/upcoming-security-changes-to-googles-oauth-2.0-authorization-endpoint.html)
userAgent: 'Mozilla/5.0',
useHybridComposition: true,
userAgent: configuration.userAgent,
useHybridComposition: configuration.useHybridComposition,
),
initialUrlRequest:
URLRequest(url: WebUri(initialUri.toString()), headers: {
Expand Down Expand Up @@ -438,7 +436,7 @@ class BaseWebViewState<S extends BaseWebView> extends State<S>
}
}

Future<bool> onBackPressed(dynamic result) async {
Future<bool> onBackPressed({dynamic result}) async {
if (await controllerCanGoBack()) {
controllerGoBack();
return false;
Expand Down
5 changes: 3 additions & 2 deletions lib/src/oauth_web_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ class OAuthWebScreen extends StatelessWidget {
configuration.onCancel?.call();
}

Future<bool> onBackPressed(dynamic result) async {
if (!((await globalKey.currentState?.onBackPressed(result)) ?? false)) {
Future<bool> onBackPressed({dynamic result}) async {
if (!((await globalKey.currentState?.onBackPressed(result: result)) ??
false)) {
return false;
}
configuration.onCancel?.call();
Expand Down
4 changes: 2 additions & 2 deletions lib/src/utils/custom_pop_scope.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';

typedef CanGoBackCallback<T> = Future<bool> Function(T? result);
typedef CanGoBackCallback<T> = Future<bool> Function({T? result});

class CustomPopScope<T> extends StatelessWidget {
const CustomPopScope({
Expand All @@ -21,7 +21,7 @@ class CustomPopScope<T> extends StatelessWidget {
onPopInvokedWithResult: onPopInvokedWithResult ??
(bool didPop, T? result) {
if (didPop) return;
canGoBack?.call(result).then((canPop) {
canGoBack?.call(result: result).then((canPop) {
if (canPop && context.mounted) {
Navigator.of(context).pop(result);
}
Expand Down

0 comments on commit 637c8e0

Please sign in to comment.