Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat logout #1

Merged
merged 6 commits into from
Jan 9, 2024
Merged
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
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
4 changes: 3 additions & 1 deletion example/lib/env.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// This file contains the configuration for the app.

String discoveryUrl = "https://login.emddigital.com/.well-known/openid-configuration";
String discoveryUrl =
"https://login.emddigital.com/.well-known/openid-configuration";
String clientId = "pkt-ALEUvLknGqosN8w7cA";
String redirectUrl = "com.your.awesome-app://login-callback";
List<String> scopes = ["openid", "email"];
String logoutUrl = "https://login.emddigital.com/logout";
7 changes: 7 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import 'package:emd_flutter_identity/emd_flutter_identity.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_web_plugins/url_strategy.dart';

var auth = AuthService();

void main() {
WidgetsFlutterBinding.ensureInitialized();

if (kIsWeb) {
usePathUrlStrategy();
}

auth.init(
handler: getOAuthHandler(),
);
Expand Down Expand Up @@ -53,6 +59,7 @@ OAuthHandler getOAuthHandler() {
return WebAuth(
discoveryUrl: discoveryUrl,
clientId: clientId,
redirectUrl: "http://localhost:8000/login-callback",
scopes: scopes,
);
} else {
Expand Down
24 changes: 21 additions & 3 deletions example/macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
PODS:
- flutter_secure_storage_macos (3.3.1):
- AppAuth (1.6.2):
- AppAuth/Core (= 1.6.2)
- AppAuth/ExternalUserAgent (= 1.6.2)
- AppAuth/Core (1.6.2)
- AppAuth/ExternalUserAgent (1.6.2):
- AppAuth/Core
- flutter_appauth (0.0.1):
- AppAuth (= 1.6.2)
- FlutterMacOS
- flutter_secure_storage_macos (6.1.1):
- FlutterMacOS
- FlutterMacOS (1.0.0)
- url_launcher_macos (0.0.1):
- FlutterMacOS

DEPENDENCIES:
- flutter_appauth (from `Flutter/ephemeral/.symlinks/plugins/flutter_appauth/macos`)
- flutter_secure_storage_macos (from `Flutter/ephemeral/.symlinks/plugins/flutter_secure_storage_macos/macos`)
- FlutterMacOS (from `Flutter/ephemeral`)
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)

SPEC REPOS:
trunk:
- AppAuth

EXTERNAL SOURCES:
flutter_appauth:
:path: Flutter/ephemeral/.symlinks/plugins/flutter_appauth/macos
flutter_secure_storage_macos:
:path: Flutter/ephemeral/.symlinks/plugins/flutter_secure_storage_macos/macos
FlutterMacOS:
Expand All @@ -19,9 +35,11 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos

SPEC CHECKSUMS:
flutter_secure_storage_macos: 6ceee8fbc7f484553ad17f79361b556259df89aa
AppAuth: 3bb1d1cd9340bd09f5ed189fb00b1cc28e1e8570
flutter_appauth: b91dffc2477d9b24a32983ca523a91812f228552
flutter_secure_storage_macos: d56e2d218c1130b262bef8b4a7d64f88d7f9c9ea
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
url_launcher_macos: 5335912b679c073563f29d89d33d10d459f95451
url_launcher_macos: d2691c7dd33ed713bf3544850a623080ec693d95

PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7

Expand Down
2 changes: 1 addition & 1 deletion example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
1 change: 1 addition & 0 deletions lib/emd_flutter_identity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export './src/services/desktop/desktop_auth.dart';
export './src/services/mobile/mobile_auth.dart';
export './src/services/oauth_handler.dart';
export './src/services/web/web_auth.dart';
export 'src/services/oauth/oauth_requests.dart';
7 changes: 6 additions & 1 deletion lib/src/services/auth.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:emd_flutter_identity/src/services/desktop/oauth_token_result.dart';
import 'package:emd_flutter_identity/src/services/oauth/oauth_token_result.dart';
import 'package:emd_flutter_identity/src/services/oauth_handler.dart';
import 'package:emd_flutter_identity/src/services/token_utils.dart';
import 'package:flutter/foundation.dart';
Expand Down Expand Up @@ -164,11 +164,16 @@ class AuthService extends ChangeNotifier {

/// Log the user out, deletes all tokens
Future<void> logout() async {
final accessToken = await this.accessToken;
if (accessToken == null) {
throw Exception('No access token to logout');
}
await _storage.delete(key: _prefsAccessToken);
await _storage.delete(key: _prefsRefreshToken);
await _storage.delete(key: _prefsIdToken);
await _storage.delete(key: _prefsAccessTokenExpiry);
_status = AuthServiceStatus.loggedOut;

notifyListeners();
}
}
11 changes: 8 additions & 3 deletions lib/src/services/desktop/desktop_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'dart:convert';

import 'package:emd_flutter_identity/src/services/desktop/auth_utils.dart';
import 'package:emd_flutter_identity/src/services/desktop/callback_server.dart';
import 'package:emd_flutter_identity/src/services/desktop/oauth_requests.dart';
import 'package:emd_flutter_identity/src/services/desktop/oauth_token_result.dart';
import 'package:emd_flutter_identity/src/services/oauth/oauth_requests.dart';
import 'package:emd_flutter_identity/src/services/oauth/oauth_token_result.dart';
import 'package:emd_flutter_identity/src/services/oauth_handler.dart';
import 'package:http/http.dart';
import 'package:url_launcher/url_launcher.dart';
Expand All @@ -17,14 +17,17 @@ class DesktopAuth with OAuthHandler {
required String discoveryUrl,
required String clientId,
required List<String> scopes,
String redirectUrl = 'http://localhost:8080',
int port = 8080,
}) : _port = port,
_discoveryUrl = discoveryUrl,
_scopes = scopes,
_redirectUrl = redirectUrl,
_clientId = clientId;

final String _discoveryUrl;
final String _clientId;
final String _redirectUrl;
final List<String> _scopes;
final int _port;

Expand Down Expand Up @@ -53,9 +56,10 @@ class DesktopAuth with OAuthHandler {
final query = {
'client_id': _clientId,
'response_type': 'code',
'redirect_uri': 'http://localhost:8080/login-callback',
'redirect_uri': _redirectUrl,
'code_challenge': challengeHash,
'code_challenge_method': 'S256',
'prompt': 'login',
'scope': _scopes.join(' '),
};

Expand All @@ -74,6 +78,7 @@ class DesktopAuth with OAuthHandler {
return fetchTokens(
authCode: code,
rawChallenge: rawChallenge,
redirectUrl: _redirectUrl,
clientId: _clientId,
tokenUrl: tokenUrl,
);
Expand Down
3 changes: 2 additions & 1 deletion lib/src/services/mobile/mobile_auth.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:emd_flutter_identity/src/services/desktop/oauth_token_result.dart';
import 'package:emd_flutter_identity/src/services/oauth/oauth_token_result.dart';
import 'package:emd_flutter_identity/src/services/oauth_handler.dart';
import 'package:flutter_appauth/flutter_appauth.dart';

Expand All @@ -17,6 +17,7 @@ class MobileAuth with OAuthHandler {
final String _discoveryUrl;
final String _clientId;
final String _redirectUrl;

final List<String> _scopes;

final FlutterAppAuth _appAuth = const FlutterAppAuth();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:convert';

import 'package:emd_flutter_identity/src/services/desktop/oauth_discovery_response.dart';
import 'package:emd_flutter_identity/src/services/desktop/oauth_token_result.dart';
import 'package:emd_flutter_identity/src/services/oauth/oauth_discovery_response.dart';
import 'package:emd_flutter_identity/src/services/oauth/oauth_token_result.dart';
import 'package:http/http.dart';

/// gets the o auth configuration from the discovery endpoint
Expand All @@ -24,11 +24,12 @@ Future<OAuthTokenResult> fetchTokens({
required String rawChallenge,
required String clientId,
required String tokenUrl,
required String redirectUrl,
}) async {
final query = {
'client_id': clientId,
'code': authCode,
'redirect_uri': 'http://localhost:8080/login-callback',
'redirect_uri': redirectUrl,
'code_verifier': rawChallenge,
'grant_type': 'authorization_code',
};
Expand Down
2 changes: 1 addition & 1 deletion lib/src/services/oauth_handler.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:emd_flutter_identity/src/services/desktop/oauth_token_result.dart';
import 'package:emd_flutter_identity/src/services/oauth/oauth_token_result.dart';

/// [OAuthHandler] is used to handle authentication for the different platforms
abstract class OAuthHandler {
Expand Down
13 changes: 7 additions & 6 deletions lib/src/services/web/web_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'dart:async';
import 'dart:convert';

import 'package:emd_flutter_identity/src/services/desktop/auth_utils.dart';
import 'package:emd_flutter_identity/src/services/desktop/oauth_requests.dart';
import 'package:emd_flutter_identity/src/services/desktop/oauth_token_result.dart';
import 'package:emd_flutter_identity/src/services/oauth/oauth_requests.dart';
import 'package:emd_flutter_identity/src/services/oauth/oauth_token_result.dart';
import 'package:emd_flutter_identity/src/services/oauth_handler.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:http/http.dart';
Expand All @@ -17,16 +17,17 @@ class WebAuth with OAuthHandler {
required String discoveryUrl,
required String clientId,
required List<String> scopes,
String? redirectUrl,
String redirectUrl = 'http://localhost:8080/#/login-callback',
}) : _scopes = scopes,
_redirectUrl = redirectUrl,
_clientId = clientId,
_discoveryUrl = discoveryUrl;

final String _discoveryUrl;
final _storage = const FlutterSecureStorage();
final String _clientId;
final List<String> _scopes;
final String? _redirectUrl;
final String _redirectUrl;

@override
Future<OAuthTokenResult?> login() async {
Expand All @@ -51,6 +52,7 @@ class WebAuth with OAuthHandler {
authCode: location.queryParameters['code']!,
rawChallenge: rawChallenge,
clientId: _clientId,
redirectUrl: _redirectUrl,
tokenUrl: discoveryResponse.tokenEndpoint,
);
}
Expand All @@ -67,8 +69,7 @@ class WebAuth with OAuthHandler {
final query = {
'client_id': _clientId,
'response_type': 'code',
'redirect_uri': _redirectUrl ??
'${window.location.protocol}//${window.location.host}/#/login-callback',
'redirect_uri': _redirectUrl,
'code_challenge': challengeHash,
'code_challenge_method': 'S256',
'scope': _scopes.join(' '),
Expand Down
Loading
Loading