Skip to content

trusona/trusona-oidc-example-dotnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Trusona OpenID Connect Example using .NET Core

This project demonstrates integrating ASP.NET and Trusona using the built-in OpenID Connect components.

Signup for a Trusona Developers account at https://developers.trusona.com/

Requirements

  • .NET Core 2.1
  • Trusona Developers Account

Project setup

  1. Checkout the project from GitHub
  2. Email support@trusona.com and let them know that you want to run this example. Include the email that is displayed when you log in to your Trusona Developers account.
  3. Edit appsettings.json and add your ClientID value
  4. Execute dotnet run --project trusona-gateway-example

Using the example

  1. Open a browser and navigate to https://localhost:5001
  2. Click the “Login with Trusona button” that you see on the screen
  3. Open the Trusona App on your phone
  4. Now that you’ve been redirect to the Trusona Gateway, use the Trusona App to scan the QR code on your screen
  5. Tap "Accept" in the Trusona App
  6. Now you’ve been redirected back to the example application running on your machine
  7. See the user information displayed on the screen that indicates a successful login

Technical information

The following snippet from Startup.cs descibes how you configure .NET to use OpenID Connect for integration with Trusona.

On startup, the framework will auto-configure using Trusona's metadata address and the your Client ID.

In this example we are requesting an e-mail address and profile information in addition to the unique nameidentifier.

Note: There is an outstanding issue with iOS and Safari and the .NET framework. This example as configured does not work on these devices. For more information, see https://github.com/aspnet/Security/issues/1864

services
  .AddAuthentication(options =>
  {
    options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
  })
  .AddCookie()
  .AddOpenIdConnect(options =>
  {
    options.ClientId = "<client_id>";
    options.MetadataAddress = "https://gateway.trusona.net/oidc/.well-known/openid-configuration";
    options.Scope.Add("email");
    options.Scope.Add("profile");
    options.ResponseMode = OpenIdConnectResponseMode.FormPost;
    options.ResponseType = OpenIdConnectResponseType.IdToken;
    options.TokenValidationParameters = new TokenValidationParameters()
    {
      ValidateIssuer = true
    };
  });

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published