Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'dart:io';
import 'package:flutter/foundation.dart';

import 'package:http/http.dart' as http;
import 'package:http/io_client.dart';

Expand Down Expand Up @@ -40,7 +40,7 @@ class HttpClientManager {
HttpClientManager._internal();

http.Client createClient(String requestId, {bool noSSL = false}) {
final client = (noSSL && !kIsWeb)
final client = (noSSL)
? createHttpClientWithNoSSL()
: http.Client();
_clients[requestId] = client;
Expand Down Expand Up @@ -82,7 +82,7 @@ class HttpClientManager {
String requestId, {
bool noSSL = false,
}) {
final baseClient = (noSSL && !kIsWeb)
final baseClient = (noSSL)
? createHttpClientWithNoSSL()
: http.Client();

Expand Down
12 changes: 6 additions & 6 deletions packages/better_networking/lib/utils/auth/handle_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:better_networking/utils/auth/jwt_auth_utils.dart';
import 'package:better_networking/utils/auth/digest_auth_utils.dart';
import 'package:better_networking/better_networking.dart';
import 'package:better_networking/utils/auth/oauth2_utils.dart';
import 'package:flutter/foundation.dart';


import 'oauth1_utils.dart';

Expand Down Expand Up @@ -215,13 +215,13 @@ Future<HttpRequestModel> handleAuth(
try {
await server.stop();
} catch (e) {
debugPrint(
stderr.writeln(
'Error stopping OAuth callback server (might already be stopped): $e',
);
}
}

debugPrint(res.$1.credentials.accessToken);
stderr.writeln(res.$1.credentials.accessToken);

// Add the access token to the request headers
updatedHeaders.add(
Expand All @@ -238,7 +238,7 @@ Future<HttpRequestModel> handleAuth(
oauth2Model: oauth2,
credentialsFile: credentialsFile,
);
debugPrint(client.credentials.accessToken);
stderr.writeln(client.credentials.accessToken);

// Add the access token to the request headers
updatedHeaders.add(
Expand All @@ -250,12 +250,12 @@ Future<HttpRequestModel> handleAuth(
updatedHeaderEnabledList.add(true);
break;
case OAuth2GrantType.resourceOwnerPassword:
debugPrint("==Resource Owner Password==");
stderr.writeln("==Resource Owner Password==");
final client = await oAuth2ResourceOwnerPasswordGrantHandler(
oauth2Model: oauth2,
credentialsFile: credentialsFile,
);
debugPrint(client.credentials.accessToken);
stderr.writeln(client.credentials.accessToken);

// Add the access token to the request headers
updatedHeaders.add(
Expand Down
12 changes: 3 additions & 9 deletions packages/better_networking/lib/utils/auth/oauth2_utils.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter_web_auth_2/flutter_web_auth_2.dart';
import 'package:oauth2/oauth2.dart' as oauth2;

import '../../models/auth/auth_oauth2_model.dart';
Expand Down Expand Up @@ -107,14 +106,9 @@ Future<(oauth2.Client, OAuthCallbackServer?)> oAuth2AuthorizationCodeGrant({
}
}
} else {
// For mobile: Use the standard flutter_web_auth_2 approach
callbackUri = await FlutterWebAuth2.authenticate(
url: authorizationUrl.toString(),
callbackUrlScheme: actualRedirectUrl.scheme,
options: const FlutterWebAuth2Options(
useWebview: true,
windowName: 'OAuth Authorization - API Dash',
),
throw UnsupportedError(
'OAuth authorization code grant is not supported in pure Dart CLI context. '
'Mobile platforms require flutter_web_auth_2 which is a Flutter dependency.',
);
}

Expand Down
8 changes: 3 additions & 5 deletions packages/better_networking/lib/utils/platform_utils.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import 'dart:io';
import 'package:flutter/foundation.dart';

/// Platform detection utilities for the better_networking package.
class PlatformUtils {
/// Returns true if running on desktop platforms (macOS, Windows, Linux).
static bool get isDesktop =>
!kIsWeb && (Platform.isMacOS || Platform.isWindows || Platform.isLinux);
Platform.isMacOS || Platform.isWindows || Platform.isLinux;

/// Returns true if running on mobile platforms (iOS, Android).
static bool get isMobile => !kIsWeb && (Platform.isIOS || Platform.isAndroid);
static bool get isMobile => Platform.isIOS || Platform.isAndroid;

/// Returns true if running on web.
static bool get isWeb => kIsWeb;
static bool get isWeb => false;

/// Returns true if OAuth should use localhost callback server.
/// This is true for desktop platforms.
static bool get shouldUseLocalhostCallback => isDesktop;
}
8 changes: 1 addition & 7 deletions packages/better_networking/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@ topics:

environment:
sdk: ">=3.6.0 <4.0.0"
flutter: ">=1.17.0"

resolution: workspace

dependencies:
flutter:
sdk: flutter
collection: ^1.18.0
convert: ^3.1.2
crypto: ^3.0.7
dart_jsonwebtoken: ^3.3.2
flutter_web_auth_2: ^5.0.1
http: ^1.6.0
http_parser: ^4.1.2
json5: ^0.8.2
Expand All @@ -34,10 +30,8 @@ dependencies:
oauth2: ^2.0.5

dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.11.1
flutter_lints: ^6.0.0
lints: ^6.1.0
freezed: ^3.2.5
json_serializable: ^6.13.0
test: ^1.29.0