Add Redirect & Override Attributes Support to Shortcodes.

* Adds support for setting the redirect cookie when shortcodes are used.
* Adds support for overriding some attributes for authentication URLs
  and login buttons when using the shortcodes.
* Fixes code formatting.
isekai
Tim Nolte 5 years ago
parent 43badcc569
commit 65051b75a8
No known key found for this signature in database
GPG Key ID: 33E7CA1AD448F3B3

@ -97,10 +97,21 @@ class OpenID_Connect_Generic_Client_Wrapper {
/** /**
* Get the authentication url from the client * Get the authentication url from the client
* *
* @param array $atts The optional attributes array when called via a shortcode.
*
* @return string * @return string
*/ */
function get_authentication_url(){ function get_authentication_url( $atts = array() ){
return $this->client->make_authentication_url();
if ( ! empty( $atts['redirect_to'] ) ) {
// Set the request query parameter used to set the cookie redirect.
$_REQUEST['redirect_to'] = $atts['redirect_to'];
$login_form = new OpenID_Connect_Generic_Login_Form( $this->settings, $this );
$login_form->handle_redirect_cookie();
}
return $this->client->make_authentication_url( $atts );
} }
/** /**

@ -45,20 +45,28 @@ class OpenID_Connect_Generic_Client {
/** /**
* Create a single use authentication url * Create a single use authentication url
* *
* @param array $atts An optional array of override/feature attributes.
*
* @return string * @return string
*/ */
function make_authentication_url() { function make_authentication_url( $atts = array() ) {
$endpoint_login = ( ! empty( $atts['endpoint_login'] ) ) ? $atts['endpoint_login'] : $this->endpoint_login;
$scope = ( ! empty( $atts['scope'] ) ) ? $atts['scope'] : $this->scope;
$client_id = ( ! empty( $atts['client_id'] ) ) ? $atts['client_id'] : $this->client_id;
$redirect_uri = ( ! empty( $atts['redirect_uri'] ) ) ? $atts['redirect_uri'] : $this->redirect_uri;
$separator = '?'; $separator = '?';
if ( stripos( $this->endpoint_login, '?' ) !== FALSE ) { if ( stripos( $this->endpoint_login, '?' ) !== FALSE ) {
$separator = '&'; $separator = '&';
} }
$url = sprintf( '%1$s%2$sresponse_type=code&scope=%3$s&client_id=%4$s&state=%5$s&redirect_uri=%6$s', $url = sprintf( '%1$s%2$sresponse_type=code&scope=%3$s&client_id=%4$s&state=%5$s&redirect_uri=%6$s',
$this->endpoint_login, $endpoint_login,
$separator, $separator,
rawurlencode( $this->scope ), rawurlencode( $scope ),
rawurlencode( $this->client_id ), rawurlencode( $client_id ),
$this->new_state(), $this->new_state(),
rawurlencode( $this->redirect_uri ) rawurlencode( $redirect_uri )
); );
$this->logger->log( apply_filters( 'openid-connect-generic-auth-url', $url ), 'make_authentication_url' ); $this->logger->log( apply_filters( 'openid-connect-generic-auth-url', $url ), 'make_authentication_url' );

@ -128,12 +128,20 @@ class OpenID_Connect_Generic_Login_Form {
/** /**
* Create a login button (link) * Create a login button (link)
*
* @param array $atts Array of optional attributes to override login buton
* functionality when used by shortcode.
* *
* @return string * @return string
*/ */
function make_login_button() { function make_login_button( $atts = array() ) {
$text = apply_filters( 'openid-connect-generic-login-button-text', __( 'Login with OpenID Connect' ) ); $button_text = __( 'Login with OpenID Connect' );
$href = $this->client_wrapper->get_authentication_url(); if ( ! empty( $atts['button_text'] ) ) {
$button_text = $atts['button_text'];
}
$text = apply_filters( 'openid-connect-generic-login-button-text', $button_text );
$href = $this->client_wrapper->get_authentication_url( $atts );
ob_start(); ob_start();
?> ?>

Loading…
Cancel
Save