Blog

Adding User Authentication to a Simple ASP.NET Application With Akamai Identity Cloud

August 6, 2020 · by Ajay Mishra ·

This blog is part of a series that walks through user authentication using Akamai Identity Cloud in various languages. 

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

Asp.net

You can complete the login life cycle for a simple ASP.NET 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.cshtml

Step 2. Configure ASP.NET to Use Akamai Identity Cloud

Here you need to set up all the artifacts as shown below. Simply create ASP.NET-based razor file index.cshtml and define the constants to put all the values that we gathered in Step 1.

web pagecode block

Step 3. Trigger Authentication

Let’s trigger the authorization endpoint to have a login link for the ASP.NET application. This code will be executed in same file of index.cshtml.

code block

A sign-in link is triggered:

sign in

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

welcome

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

welcome

  • Now John Doe is registered and displayed

welcome

The login process is just as simple:

  • Insert user name and password

welcome

  • John Doe is registered and displayed

welcome

After registration or login, users are redirected to a “welcome.cshtml” 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

5. Logout

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

success

For more coding examples of ASP.NET with OIDC visit:

https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.OpenIdConnect

You Might Also Like