Giter VIP home page Giter VIP logo

.net's Introduction

Yoti .NET SDK

Welcome to the Yoti .NET SDK. This repo contains the tools you need to quickly integrate your .NET back-end with Yoti, so that your users can share their identity details with your application in a secure and trusted way.

An architectural view

To integrate your application with Yoti, your back-end must expose a GET endpoint that Yoti will use to forward tokens. The endpoint can be configured in Yoti Dashboard when you create/update your application.

The image below shows how your application back-end and Yoti integrate in the context of a Login flow. Yoti SDK carries out for you steps 6, 7 ,8 and the profile decryption in step 9.

alt text

Yoti also allows you to enable user details verification from your mobile app by means of the Android (TBA) and iOS (TBA) SDKs. In that scenario, your Yoti-enabled mobile app is playing both the role of the browser and the Yoti app. By the way, your back-end doesn't need to handle these cases in a significantly different way. You might just decide to handle the User-Agent header in order to provide different responses for web and mobile clients.

Compiling the NuGet package

To compile the NuGet package you will need to install NuGet. You can find instructions to do that here

Next clone this repo and ensure that the Yoti.Auth project has been compiled in Release configuration.

Finally run the following command from the <repo-path>/src folder:

nuget pack Yoti.Auth.nuspec

Enabling the SDK

To import the Yoti SDK inside your project, you should use the NuGet Yoti.Auth Package

Install-Package Yoti.Auth

We are not yet on NuGet, so, for the moment, in order to use the SDK you need to clone this repo and run Install-Package Yoti.Auth -Source "<repo-path>/src" from the Package Manager Console.

Client initialisation

The YotiClient is the SDK entry point. To initialise it you need include the following snippet inside your endpoint initialisation section:

const string sdkId = "your-sdk-id";
var privateKeyStream = System.IO.File.OpenText("path/to/your-application-pem-file.pem")
var yotiClient = new YotiClient(sdkId, privateKeyStream);

Where:

  • sdkId is the sdk identifier generated by Yoti Dashboard when you create your app. Note this is not your Application Identifier which is needed by your clientside code
  • path/to/your-application-pem-file.pem is the path to the pem file your browser generates for you, when you create your app on Yoti Dashboard.

Profile retrieval

When your application receives a token via the exposed endpoint (it will be assigned to a query string parameter named token), you can easily retrieve the user profile by adding the following to your endpoint handler:

var activityDetails = yotiClient.GetActivityDetails(token);

Or if you are in an asynchronous method:

var activityDetails = await yotiClient.GetActivityDetailsAsync(token);

Before you inspect the user profile, you might want to check whether the user validation was successful. This is done as follows:

var activityDetails = yotiClient.GetActivityDetails(token);
if (activityDetails.Outcome == ActivityOutcome.Success)
{
    var profile = activityDetails.UserProfile;
}
else
{
    // handle unhappy path
}

Handling users

When you retrieve the user profile, you receive a userId generated by Yoti exclusively for your application. This means that if the same individual logs into another app, Yoti will assign her/him a different id. You can use such id to verify whether the retrieved profile identifies a new or an existing user. Here is an example of how this works:

var activityDetails = yotiClient.GetActivityDetails(token);
if (activityDetails.Outcome == ActivityOutcome.Success)
{
    var profile = activityDetails.UserProfile;
    var user = YourUserSearchFunction(profile.Id);
    if (user != null)
    {
        // handle login
    }
    else
    {
        // handle registration
    }
}
else
{
    // handle unhappy path
}

Where yourUserSearchFunction is a piece of logic in your app that is supposed to find a user, given a userId. No matter if the user is a new or an existing one, Yoti will always provide her/his profile, so you don't necessarily need to store it.

The profile object provides a set of attributes corresponding to user attributes. Whether the attributes are present or not depends on the settings you have applied to your app on Yoti Dashboard.

.net's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.