@@ -64,6 +64,15 @@ class OpenID_Connect_Generic_Client {
6464 */
6565 private $ endpoint_userinfo ;
6666
67+ /**
68+ * The OIDC/oAuth token revocation endpoint URL.
69+ *
70+ * @see OpenID_Connect_Generic_Option_Settings::endpoint_revoke
71+ *
72+ * @var string
73+ */
74+ private $ endpoint_revoke ;
75+
6776 /**
6877 * The OIDC/oAuth token validation endpoint URL.
6978 *
@@ -73,6 +82,15 @@ class OpenID_Connect_Generic_Client {
7382 */
7483 private $ endpoint_token ;
7584
85+ /**
86+ * The logout front channel flow "ajax" endpoint URI.
87+ *
88+ * @see OpenID_Connect_Generic_Option_Settings::logout_uri
89+ *
90+ * @var string
91+ */
92+ private $ logout_uri ;
93+
7694 /**
7795 * The login flow "ajax" endpoint URI.
7896 *
@@ -106,23 +124,37 @@ class OpenID_Connect_Generic_Client {
106124 * @param string $scope @see OpenID_Connect_Generic_Option_Settings::scope for description.
107125 * @param string $endpoint_login @see OpenID_Connect_Generic_Option_Settings::endpoint_login for description.
108126 * @param string $endpoint_userinfo @see OpenID_Connect_Generic_Option_Settings::endpoint_userinfo for description.
127+ * @param string $endpoint_revoke @see OpenID_Connect_Generic_Option_Settings::endpoint_revoke for description.
109128 * @param string $endpoint_token @see OpenID_Connect_Generic_Option_Settings::endpoint_token for description.
129+ * @param string $logout_uri @see OpenID_Connect_Generic_Option_Settings::logout_uri for description.
110130 * @param string $redirect_uri @see OpenID_Connect_Generic_Option_Settings::redirect_uri for description.
111131 * @param int $state_time_limit @see OpenID_Connect_Generic_Option_Settings::state_time_limit for description.
112132 * @param OpenID_Connect_Generic_Option_Logger $logger The plugin logging object instance.
113133 */
114- public function __construct ( $ client_id , $ client_secret , $ scope , $ endpoint_login , $ endpoint_userinfo , $ endpoint_token , $ redirect_uri , $ state_time_limit , $ logger ) {
134+ public function __construct ( $ client_id , $ client_secret , $ scope , $ endpoint_login , $ endpoint_userinfo , $ endpoint_revoke , $ endpoint_token ,
135+ $ logout_uri , $ redirect_uri , $ state_time_limit , $ logger ) {
115136 $ this ->client_id = $ client_id ;
116137 $ this ->client_secret = $ client_secret ;
117138 $ this ->scope = $ scope ;
118139 $ this ->endpoint_login = $ endpoint_login ;
119140 $ this ->endpoint_userinfo = $ endpoint_userinfo ;
141+ $ this ->endpoint_revoke = $ endpoint_revoke ;
120142 $ this ->endpoint_token = $ endpoint_token ;
143+ $ this ->logout_uri = $ logout_uri ;
121144 $ this ->redirect_uri = $ redirect_uri ;
122145 $ this ->state_time_limit = $ state_time_limit ;
123146 $ this ->logger = $ logger ;
124147 }
125148
149+ /**
150+ * Provides the configured logout URI supplied to the IDP.
151+ *
152+ * @return string
153+ */
154+ public function get_logout_uri () {
155+ return $ this ->logout_uri ;
156+ }
157+
126158 /**
127159 * Provides the configured Redirect URI supplied to the IDP.
128160 *
@@ -538,4 +570,37 @@ public function get_subject_identity( $id_token_claim ) {
538570 return $ id_token_claim ['sub ' ];
539571 }
540572
573+ /**
574+ * Using the refresh token, revoke its usage
575+ *
576+ * @param string $refresh_token The refresh token previously obtained from token response.
577+ *
578+ * @return array<mixed>|WP_Error
579+ */
580+ public function revoke_refresh_token ( $ refresh_token ) {
581+ $ request = array (
582+ 'headers ' => array (
583+ 'Content-type: application/x-www-form-urlencoded ' ,
584+ ),
585+ 'body ' => array (
586+ 'client_id ' => $ this ->client_id ,
587+ 'client_secret ' => $ this ->client_secret ,
588+ 'token ' => $ refresh_token ,
589+ ),
590+ );
591+
592+ // Allow modifications to the request.
593+ $ request = apply_filters ( 'openid-connect-generic-alter-request ' , $ request , 'refresh-token ' );
594+
595+ // Call the server and ask to revoke token.
596+ $ this ->logger ->log ( $ this ->endpoint_revoke , 'revoke_refresh_token ' );
597+ $ response = wp_remote_post ( $ this ->endpoint_revoke , $ request );
598+
599+ if ( is_wp_error ( $ response ) ) {
600+ $ response ->add ( 'revoke_refresh_token ' , __ ( 'Revoke refresh token failed. ' , 'daggerhart-openid-connect-generic ' ) );
601+ }
602+
603+ return $ response ;
604+ }
605+
541606}
0 commit comments