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

Adds implementation for RP initiated logout #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ It currently supports these features:
* parsing and validating id tokens
* basic tools for implementing implicit and authorization code flow
* authentication for command line tools

* RP initiated logout

Besides authentication providers that support OpenID Connect, this
library can also work with other authentication providers supporting
oauth2, like Facebook. For these providers, some features (e.g. discovery and id tokens)
will not work. You should define the metadata for those providers manually, except
for Facebook, which is predefined in the library.



## Usage

Below are some examples of how to use the library. For more examples, see the [`example` folder](example/example.md). It contains full examples of how to use the library with a keycloak server in a flutter, command line and browser application.
Expand Down
36 changes: 35 additions & 1 deletion lib/openid_client_io.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
library openid_client.io;

import 'dart:async';
import 'dart:io';
import 'dart:developer';
import 'dart:io';

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

import 'openid_client.dart';
import 'src/http_util.dart' as http_util;

export 'openid_client.dart';

Expand Down Expand Up @@ -158,6 +161,37 @@ class Authenticator {
_requestServers.clear();
}
}

/// Performs OpenID connect RP-Initiated Logout according to specification
/// See: https://openid.net/specs/openid-connect-rpinitiated-1_0.html#RPLogout
FutureOr<void> logout({
required Uri endSessionEndpoint,
Map<String, String>? headers,
http.Client? client,
String? idTokenHint,
String? logoutHint,
String? clientId,
String? postLogoutRedirectUri,
String? state,
String? uiLocales,
}) async {
headers ??= <String, String>{};
final body = <String, String>{
if (idTokenHint != null) 'id_token_hint': idTokenHint,
if (logoutHint != null) 'logout_hint': logoutHint,
if (clientId != null) 'client_id': clientId,
if (postLogoutRedirectUri != null)
'post_logout_redirect_uri': postLogoutRedirectUri,
if (state != null) 'state': state,
if (uiLocales != null) 'ui_locales': uiLocales,
};
await http_util.post(
endSessionEndpoint,
headers: headers,
body: body,
client: client,
);
}
}

void _runBrowser(String url) {
Expand Down