Merge pull request #200 from timnolte/feature/redirect-with-shortcode

Add Redirect & Override Attributes Support to Shortcodes.
isekai
Tim Nolte 5 years ago committed by GitHub
commit 3e97a145e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -96,10 +96,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' );

@ -129,11 +129,19 @@ 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 = apply_filters( 'openid-connect-generic-login-button-url', $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