diff --git a/README.md b/README.md index 07e02f7..dba40a1 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ 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 @@ -21,8 +21,6 @@ oauth2, like Facebook. For these providers, some features (e.g. discovery and id 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. diff --git a/lib/openid_client_io.dart b/lib/openid_client_io.dart index 8f49184..dc3a14f 100644 --- a/lib/openid_client_io.dart +++ b/lib/openid_client_io.dart @@ -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'; @@ -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 logout({ + required Uri endSessionEndpoint, + Map? headers, + http.Client? client, + String? idTokenHint, + String? logoutHint, + String? clientId, + String? postLogoutRedirectUri, + String? state, + String? uiLocales, + }) async { + headers ??= {}; + final body = { + 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) {