From ada93ba4f3fec827785ab036ef23348ce5f5c90f Mon Sep 17 00:00:00 2001 From: Jonathan Daggerhart Date: Mon, 28 Sep 2015 21:46:50 -0400 Subject: [PATCH] Added setting for http_response_timeout --- .../openid-connect-generic-client-wrapper.php | 16 ++++++++++++++++ includes/openid-connect-generic-client.php | 8 ++++++++ .../openid-connect-generic-settings-page.php | 15 +++++++++++---- openid-connect-generic.php | 1 + 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/includes/openid-connect-generic-client-wrapper.php b/includes/openid-connect-generic-client-wrapper.php index 41641ee..a24aaef 100644 --- a/includes/openid-connect-generic-client-wrapper.php +++ b/includes/openid-connect-generic-client-wrapper.php @@ -47,6 +47,7 @@ class OpenID_Connect_Generic_Client_Wrapper { // alter the requests according to settings add_filter( 'openid-connect-generic-alter-request', array( $client_wrapper, 'alter_request' ), 10, 3 ); + add_filter( 'http_request_timeout', array( $client_wrapper, 'alter_http_request_timeout' ) ); if ( is_admin() ) { // use the ajax url to handle processing authorization without any html output @@ -63,6 +64,21 @@ class OpenID_Connect_Generic_Client_Wrapper { return $client_wrapper; } + /** + * WP Hook for altering remote request timeout + * + * @param $timeout + * + * @return int + */ + function alter_http_request_timeout( $timeout ){ + if ( is_numeric( $this->settings->http_request_timeout ) ){ + return absint( $this->settings->http_request_timeout ); + } + + return $timeout; + } + /** * Get the authentication url from the client * diff --git a/includes/openid-connect-generic-client.php b/includes/openid-connect-generic-client.php index 9aaef5b..2749c75 100644 --- a/includes/openid-connect-generic-client.php +++ b/includes/openid-connect-generic-client.php @@ -111,6 +111,10 @@ class OpenID_Connect_Generic_Client { // call the server and ask for a token $response = wp_remote_post( $this->endpoint_token, $request ); + if ( is_wp_error( $response ) ){ + $response->add( 'request_authentication_token' , __( 'Request for authentication token failed.' ) ); + } + return $response; } @@ -147,6 +151,10 @@ class OpenID_Connect_Generic_Client { // attempt the request $response = wp_remote_get( $this->endpoint_userinfo . '?access_token=' . $access_token, $request ); + if ( is_wp_error( $response ) ){ + $response->add( 'request_userinfo' , __( 'Request for userinfo failed.' ) ); + } + return $response; } diff --git a/includes/openid-connect-generic-settings-page.php b/includes/openid-connect-generic-settings-page.php index 8c09bf3..9680361 100644 --- a/includes/openid-connect-generic-settings-page.php +++ b/includes/openid-connect-generic-settings-page.php @@ -85,16 +85,23 @@ class OpenID_Connect_Generic_Settings_Page { 'type' => 'text', 'section' => 'client_settings', ), + 'identity_key' => array( + 'title' => __( 'Identity Key' ), + 'description' => __( 'Where in the user claim array to find the user\'s identification data. Possible standard values: preferred_username, name, or sub. If you\'re having trouble, use "sub".' ), + 'example' => 'preferred_username', + 'type' => 'text', + 'section' => 'client_settings', + ), 'no_sslverify' => array( 'title' => __( 'Disable SSL Verify' ), 'description' => __( 'Do not require SSL verification during authorization. The OAuth extension uses curl to make the request. By default CURL will generally verify the SSL certificate to see if its valid an issued by an accepted CA. This setting disabled that verification.' ), 'type' => 'checkbox', 'section' => 'client_settings', ), - 'identity_key' => array( - 'title' => __( 'Identity Key' ), - 'description' => __( 'Where in the user claim array to find the user\'s identification data. Possible standard values: preferred_username, name, or sub. If you\'re having trouble, use "sub".' ), - 'example' => 'preferred_username', + 'http_request_timeout' => array( + 'title' => __( 'HTTP Request Timeout' ), + 'description' => __( 'Set the timeout for requests made to the IDP. Default value is 5.' ), + 'example' => 5, 'type' => 'text', 'section' => 'client_settings', ), diff --git a/openid-connect-generic.php b/openid-connect-generic.php index 0c00d11..0b9c3de 100644 --- a/openid-connect-generic.php +++ b/openid-connect-generic.php @@ -177,6 +177,7 @@ class OpenID_Connect_Generic { // non-standard settings 'no_sslverify' => 0, + 'http_request_timeout' => 5, 'identity_key' => 'preferred_username', // plugin settings