Skip to content

Commit

Permalink
Merge branch 'newoauthlib'
Browse files Browse the repository at this point in the history
  • Loading branch information
MoralCode committed Mar 5, 2024
2 parents 6ce6eb7 + b4eed52 commit 27360ba
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 198 deletions.
177 changes: 6 additions & 171 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,80 +85,11 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.3"
flutter_secure_storage:
dependency: transitive
description:
name: flutter_secure_storage
sha256: "22dbf16f23a4bcf9d35e51be1c84ad5bb6f627750565edd70dab70f3ff5fff8f"
url: "https://pub.dev"
source: hosted
version: "8.1.0"
flutter_secure_storage_linux:
dependency: transitive
description:
name: flutter_secure_storage_linux
sha256: "3d5032e314774ee0e1a7d0a9f5e2793486f0dff2dd9ef5a23f4e3fb2a0ae6a9e"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
flutter_secure_storage_macos:
dependency: transitive
description:
name: flutter_secure_storage_macos
sha256: bd33935b4b628abd0b86c8ca20655c5b36275c3a3f5194769a7b3f37c905369c
url: "https://pub.dev"
source: hosted
version: "3.0.1"
flutter_secure_storage_platform_interface:
dependency: transitive
description:
name: flutter_secure_storage_platform_interface
sha256: "0d4d3a5dd4db28c96ae414d7ba3b8422fd735a8255642774803b2532c9a61d7e"
url: "https://pub.dev"
source: hosted
version: "1.0.2"
flutter_secure_storage_web:
dependency: transitive
description:
name: flutter_secure_storage_web
sha256: "30f84f102df9dcdaa2241866a958c2ec976902ebdaa8883fbfe525f1f2f3cf20"
url: "https://pub.dev"
source: hosted
version: "1.1.2"
flutter_secure_storage_windows:
dependency: transitive
description:
name: flutter_secure_storage_windows
sha256: "38f9501c7cb6f38961ef0e1eacacee2b2d4715c63cc83fe56449c4d3d0b47255"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
flutter_web_auth_2:
dependency: transitive
description:
name: flutter_web_auth_2
sha256: "0da41e631a368e02366fc1a9b79dd8da191e700a836878bc54466fff51c07df2"
url: "https://pub.dev"
source: hosted
version: "2.2.1"
flutter_web_auth_2_platform_interface:
dependency: transitive
description:
name: flutter_web_auth_2_platform_interface
sha256: f6fa7059ff3428c19cd756c02fef8eb0147131c7e64591f9060c90b5ab84f094
url: "https://pub.dev"
source: hosted
version: "2.1.4"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
freezed_annotation:
dependency: transitive
description:
Expand All @@ -183,14 +114,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.2"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
json_annotation:
dependency: transitive
description:
Expand Down Expand Up @@ -239,14 +162,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.0"
oauth2_client:
oauth2:
dependency: transitive
description:
name: oauth2_client
sha256: e23986d8976d6af361aa52689ef175113379c6e13859011e18bdf8ef9c6754e2
name: oauth2
sha256: c4013ef62be37744efdc0861878fd9e9285f34db1f9e331cc34100d7674feb42
url: "https://pub.dev"
source: hosted
version: "3.2.2"
version: "2.0.2"
path:
dependency: transitive
description:
Expand All @@ -255,14 +178,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.8.3"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
url: "https://pub.dev"
source: hosted
version: "2.1.8"
provider:
dependency: "direct main"
description:
Expand All @@ -271,14 +186,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.1.1"
random_string:
dependency: transitive
description:
name: random_string
sha256: "03b52435aae8cbdd1056cf91bfc5bf845e9706724dd35ae2e99fa14a1ef79d02"
url: "https://pub.dev"
source: hosted
version: "2.3.1"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -340,70 +247,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.2"
url_launcher:
dependency: transitive
description:
name: url_launcher
sha256: c512655380d241a337521703af62d2c122bf7b77a46ff7dd750092aa9433499c
url: "https://pub.dev"
source: hosted
version: "6.2.4"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
sha256: "507dc655b1d9cb5ebc756032eb785f114e415f91557b73bf60b7e201dfedeb2f"
url: "https://pub.dev"
source: hosted
version: "6.2.2"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
sha256: "75bb6fe3f60070407704282a2d295630cab232991eb52542b18347a8a941df03"
url: "https://pub.dev"
source: hosted
version: "6.2.4"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
sha256: ab360eb661f8879369acac07b6bb3ff09d9471155357da8443fd5d3cf7363811
url: "https://pub.dev"
source: hosted
version: "3.1.1"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
sha256: b7244901ea3cf489c5335bdacda07264a6e960b1c1b1a9f91e4bc371d9e68234
url: "https://pub.dev"
source: hosted
version: "3.1.0"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: a932c3a8082e118f80a475ce692fde89dc20fddb24c57360b96bc56f7035de1f
url: "https://pub.dev"
source: hosted
version: "2.3.1"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: fff0932192afeedf63cdd50ecbb1bc825d31aed259f02bb8dba0f3b729a5e88b
url: "https://pub.dev"
source: hosted
version: "2.2.3"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: ecf9725510600aa2bb6d7ddabe16357691b6d2805f66216a97d1b881e21beff7
url: "https://pub.dev"
source: hosted
version: "3.1.1"
vector_math:
dependency: transitive
description:
Expand All @@ -420,14 +263,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.3.0"
window_to_front:
dependency: transitive
description:
name: window_to_front
sha256: "7aef379752b7190c10479e12b5fd7c0b9d92adc96817d9e96c59937929512aee"
url: "https://pub.dev"
source: hosted
version: "0.0.3"
sdks:
dart: ">=3.2.6 <3.11.0"
flutter: ">=3.16.0"
dart: ">=3.2.6 <4.0.0"
flutter: ">=1.16.0"
1 change: 0 additions & 1 deletion lib/c2logbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export 'src/c2logbook_base.dart';
export 'src/types/c2_user.dart';
export 'src/types/c2_results.dart';


// TODO: Export any libraries intended for clients of this package.
4 changes: 2 additions & 2 deletions lib/src/c2_oauth_client.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:oauth2_client/oauth2_client.dart';
import 'package:oauth2/oauth2.dart' as oauth2;

class Concept2OAuth2Client extends OAuth2Client {
class Concept2OAuth2Client {
String baseUrl;

Concept2OAuth2Client(
Expand Down
36 changes: 13 additions & 23 deletions lib/src/c2logbook_base.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:convert';

import 'package:c2logbook/src/c2_oauth_client.dart';
import 'package:oauth2_client/oauth2_helper.dart';
import 'package:oauth2/oauth2.dart' as oauth2;
import 'package:http/http.dart' as http;

import '../c2logbook.dart';
Expand All @@ -11,6 +11,8 @@ class C2Logbook {
final bool development;
final String _userAgent;

outh2.Client oauthClient;

Uri get _serverUri =>
Uri.https(development ? 'log-dev.concept2.com' : 'log.concept2.com');

Expand All @@ -19,39 +21,27 @@ class C2Logbook {
'User-Agent': _userAgent
};

late OAuth2Helper oauthHelper;

Future<bool> get isLoggedIn => oauthHelper.getTokenFromStorage().then(
(value) => value != null,
);
bool get isLoggedIn => oauthClient != null;

C2Logbook(
{required String clientId,
required String clientSecret,
required String redirectUri,
required oauth2.Credentials credentials,
this.development = false,
String? userAgent})
: _userAgent = userAgent ?? "c2logbook Dart Wrapper Library" {
final oauthClient = Concept2OAuth2Client(
baseUrl: _serverUri.toString(),
redirectUri: redirectUri,
customUriScheme: Uri.parse(redirectUri).scheme);

oauthHelper = OAuth2Helper(oauthClient,
grantType: OAuth2Helper.authorizationCode,
clientId: clientId,
clientSecret: clientSecret,
enableState: false,
enablePKCE: false,
scopes: ['user:read', 'results:read']); //'user:write', 'results:write'
// If the OAuth2 credentials have already been saved from a previous run, we
// just want to reload them.
oauthClient =
oauth2.Client(credentials, identifier: clientId, secret: clientSecret);
}

Future<http.Response> _get(String url,
{Map<String, String>? headers, http.Client? httpClient}) async {
final allHeaders = <String, String>{}
..addAll(headers ?? {})
..addAll(_headers);
return oauthHelper.get(url, headers: allHeaders, httpClient: httpClient);
return oauthClient.get(url, headers: allHeaders, httpClient: httpClient);
}

Future<http.Response> _post(String url,
Expand All @@ -61,7 +51,7 @@ class C2Logbook {
final allHeaders = <String, String>{}
..addAll(headers ?? {})
..addAll(_headers);
return oauthHelper.post(url,
return oauthClient.post(url,
headers: allHeaders, body: body, httpClient: httpClient);
}

Expand All @@ -72,7 +62,7 @@ class C2Logbook {
final allHeaders = <String, String>{}
..addAll(headers ?? {})
..addAll(_headers);
return oauthHelper.patch(url,
return oauthClient.patch(url,
headers: allHeaders, body: body, httpClient: httpClient);
}

Expand All @@ -81,7 +71,7 @@ class C2Logbook {
final allHeaders = <String, String>{}
..addAll(headers ?? {})
..addAll(_headers);
return oauthHelper.delete(url, headers: allHeaders, httpClient: httpClient);
return oauthClient.delete(url, headers: allHeaders, httpClient: httpClient);
}

/// Get user metadata (name, email, etc) by id.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
freezed_annotation: ^2.4.1
http: ^1.2.0
json_annotation: ^4.8.1
oauth2_client: ^3.2.2
oauth2: ^2.0.2
# path: ^1.8.0

dev_dependencies:
Expand Down

0 comments on commit 27360ba

Please sign in to comment.