Blog

Adding User Authentication to a Simple PHP Application With Akamai Identity Cloud

July 7, 2020 · by Ajay Mishra ·

In this blog, we will add user authentication to a simple PHP web application with Akamai Identity Cloud. The primary use case is user registration and log in or out from a simple PHP application. In this example, we will use the OpenID Connect (OIDC) Authorization Code flow built into Akamai Identity Cloud as illustrated below.

chart

You can complete the login life cycle for a simple PHP web app in just five steps.

Step 1. Gather Your Details

Gather your details from the Akamai Identity Cloud console, where the following are the arbitrary values:

Required Artifacts

Arbitrary Values

OIDC URL

https://v1.api.us.janrain.com/my-customer-id/login 

Authorization Endpoint

https://v1.api.us.janrain.com/my-customer-id/login/authorize 

UserInfo Endpoint

https://v1.api.us.janrain.com/my-customer-id/profiles/oidc/userinfo

Customer ID

a12bc34d-567e-8f90-gh12-3i45jk678lm9

Client Secret

8rrr8rrPmth_*****24rjffjjc

Logout_URL

https://v1.api.us.janrain.com/my-customer-id/logout?client_id=my-client-id 

Redirect_URL

https://www.company.com/redirect.php

 Step 2. Configure PHP to Use Akamai Identity Cloud

Here you need to fill all of the values in a PHP configuration file (config_aic.php) as shown below. Simply create PHP constants to put all the values that we gathered in Step 1.

chart

Step 3. Trigger Authentication

Let’s trigger the authorization endpoint to have a login link for the PHP application. This code will go to another file of index.php, which includes the config_aic.php file.

code blockcode block

A sign-in link is triggered:

sign in

Pressing the sign-in button will bring up Akamai’s pre-built hosted login page:

log in

At this point, you can register a Generic User (John Doe) as follows:

  • Complete the display name, email address, desired password, and confirm the password

log in

  • Now John Doe is registered and displayed

welcome

The login process is just as simple:

  • Insert user name and password

log in

  • John Doe is registered and displayed 

welcome

After registration or login, users are redirected to a “welcome.php” page where authentication transpires:

  • Exchanging access token with authorization code

code block

  • Using that access token to access user information from OIDC user info endpoint

code block

Step 4. Display User Information

Here, user information is fetched and displayed by calling the OIDC user info endpoint.

welcome

Step 5. Logout

As shown above, you can logout from the PHP application by pressing the "Logout" link. The link button is backed by the logout URL, resulting in the following pop-up:

login successful

For more coding examples of PHP with OIDC client and server visit:

https://oauth.net/code/php/

You Might Also Like