OpenID Connect Generic Client Shortcodes

Below, you’ll find a detailed guide on how to add the OpenID Connect Generic Client Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the OpenID Connect Generic Client Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the OpenID Connect Generic Client Plugin and the shortcodes it provides:

Plugin Icon
OpenID Connect Generic Client

"OpenID Connect Generic Client is a robust WordPress plugin that facilitates seamless integration with any OpenID Connect compliant authentication server. It's ideal for secure, single sign-on setups."

★★★★★ (16) Active Installs: 4000+ Tested with: 6.0.6 PHP Version: 7.2
Included Shortcodes:
  • [openid_connect_generic_login_button]
  • [openid_connect_generic_auth_url]

OpenID [openid_connect_generic_login_button] Shortcode

The Daggerhart OpenID Connect Generic shortcode is a functionality that generates a login button. This button, when clicked, directs users to an OpenID Connect authentication page. The shortcode allows customization of the button text and assigns it to the ‘button_text’ attribute. It applies filters to sanitize the text and URL, ensuring secure navigation.

Shortcode: [openid_connect_generic_login_button]

Parameters

Here is a list of all possible openid_connect_generic_login_button shortcode parameters and attributes:

  • button_text – defines the text displayed on the login button

Examples and Usage

Basic example – The basic usage of the OpenID Connect Generic Login Button shortcode.

[openid_connect_generic_login_button /]

This will generate a login button with the default text “Login with OpenID Connect”.

For more customization, you can use the ‘button_text’ attribute to change the text displayed on the login button.

[openid_connect_generic_login_button button_text="Sign in with OpenID Connect" /]

Advanced examples

Using the shortcode with multiple attributes. Here, we are not only changing the button text but also adding other attributes to further customize the login button. Note that the additional attributes should be supported by the ‘get_authentication_url’ function in the client wrapper.

[openid_connect_generic_login_button button_text="Sign in with OpenID Connect" attribute1="value1" attribute2="value2" /]

Remember, the additional attributes will only work if they are supported by the ‘get_authentication_url’ function in the client wrapper. If they are not, they will simply be ignored.

PHP Function Code

In case you have difficulties debugging what causing issues with [openid_connect_generic_login_button] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'openid_connect_generic_login_button', array( $login_form, 'make_login_button' ) );

Shortcode PHP function:

function make_login_button( $atts = array() ) {

		$atts = shortcode_atts(
			array(
				'button_text' => __( 'Login with OpenID Connect', 'daggerhart-openid-connect-generic' ),
			),
			$atts,
			'openid_connect_generic_login_button'
		);

		$text = apply_filters( 'openid-connect-generic-login-button-text', $atts['button_text'] );
		$text = esc_html( $text );

		$href = $this->client_wrapper->get_authentication_url( $atts );
		$href = esc_url_raw( $href );

		$login_button = <<<HTML
<div class="openid-connect-login-button" style="margin: 1em 0; text-align: center;">
	<a class="button button-large" href="{$href}">{$text}</a>
</div>
HTML;

		return $login_button;

	}

Code file location:

daggerhart-openid-connect-generic/daggerhart-openid-connect-generic/includes/openid-connect-generic-login-form.php

OpenID [openid_connect_generic_auth_url] Shortcode

The Daggerhart OpenID Connect Generic shortcode is used for generating an authentication URL. It takes several parameters like endpoint_login, scope, client_id, redirect_uri, redirect_to, and acr_values to construct the URL. This shortcode validates the redirection URL to prevent redirection attacks. It also logs the generated URL for debugging purposes. It’s a vital part of the Daggerhart OpenID Connect Generic plugin.

Shortcode: [openid_connect_generic_auth_url]

Parameters

Here is a list of all possible openid_connect_generic_auth_url shortcode parameters and attributes:

  • endpoint_login – URL where the user will be directed for authentication.
  • scope – Defines what information the user will share.
  • client_id – Identifier for the application requesting authentication.
  • redirect_uri – URL to which the user will be redirected after authentication.
  • redirect_to – URL where the user will be redirected after login.
  • acr_values – Specifies how the server must authenticate the user.

Examples and Usage

Basic example – The shortcode is used to generate an authentication URL for the OpenID Connect Generic Client plugin. This basic usage example uses the default settings for the endpoint login, scope, client_id, redirect_uri, redirect_to, and acr_values parameters.

[openid_connect_generic_auth_url /]

Advanced examples

Customizing the endpoint login and scope parameters. This example generates an authentication URL with a specific endpoint login and scope.

[openid_connect_generic_auth_url endpoint_login="https://example.com/login" scope="openid profile email" /]

Specifying a custom redirect_uri and redirect_to parameters. This example generates an authentication URL that will redirect the user to a specific URL after authentication.

[openid_connect_generic_auth_url redirect_uri="https://example.com/redirect" redirect_to="https://example.com/welcome" /]

Setting the acr_values parameter. This example generates an authentication URL with specified acr_values, which represent Authentication Context Class Reference values.

[openid_connect_generic_auth_url acr_values="2" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [openid_connect_generic_auth_url] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'openid_connect_generic_auth_url', array( $this->client_wrapper, 'get_authentication_url' ) );

Shortcode PHP function:

function get_authentication_url( $atts = array() ) {

		$atts = shortcode_atts(
			array(
				'endpoint_login' => $this->settings->endpoint_login,
				'scope' => $this->settings->scope,
				'client_id' => $this->settings->client_id,
				'redirect_uri' => $this->client->get_redirect_uri(),
				'redirect_to' => $this->get_redirect_to(),
				'acr_values' => $this->settings->acr_values,
			),
			$atts,
			'openid_connect_generic_auth_url'
		);

		// Validate the redirect to value to prevent a redirection attack.
		if ( ! empty( $atts['redirect_to'] ) ) {
			$atts['redirect_to'] = wp_validate_redirect( $atts['redirect_to'], home_url() );
		}

		$separator = '?';
		if ( stripos( $this->settings->endpoint_login, '?' ) !== false ) {
			$separator = '&';
		}

		$url_format = '%1$s%2$sresponse_type=code&scope=%3$s&client_id=%4$s&state=%5$s&redirect_uri=%6$s';
		if ( ! empty( $atts['acr_values'] ) ) {
			$url_format .= '&acr_values=%7$s';
		}

		$url = sprintf(
			$url_format,
			$atts['endpoint_login'],
			$separator,
			rawurlencode( $atts['scope'] ),
			rawurlencode( $atts['client_id'] ),
			$this->client->new_state( $atts['redirect_to'] ),
			rawurlencode( $atts['redirect_uri'] ),
			rawurlencode( $atts['acr_values'] )
		);

		$this->logger->log( apply_filters( 'openid-connect-generic-auth-url', $url ), 'make_authentication_url' );
		return apply_filters( 'openid-connect-generic-auth-url', $url );
	}

Code file location:

daggerhart-openid-connect-generic/daggerhart-openid-connect-generic/openid-connect-generic.php

Conclusion

Now that you’ve learned how to embed the OpenID Connect Generic Client Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *