yoti

package module
v2.3.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2019 License: MIT Imports: 24 Imported by: 2

README

Yoti Go SDK

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

Table of Contents

  1. An Architectural view - High level overview of integration

  2. Installing the SDK - How to install our SDK

  3. SDK Project import - How to install the SDK to your project

  4. Configuration - How to initialise your configuration

  5. Profile Retrieval - How to retrieve a Yoti profile using the one time use token

  6. Handling users - How to manage users

  7. AML Integration - How to integrate with Yoti's AML (Anti Money Laundering) service

  8. Running the tests - Attributes defined

  9. Running the example - Attributes defined

  10. API Coverage - Attributes defined

  11. Support - Please feel free to reach out

  12. References

An Architectural View

Before you start your integration, here is a bit of background on how the integration works. To integrate your application with Yoti, your back-end must expose a GET endpoint that Yoti will use to forward tokens. The endpoint is configured in the Yoti Dashboard where you create/update your application. For more information on how to create an application please check our developer page.

The image below shows how your application back-end and Yoti integrate into 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. 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 desktop and mobile clients.

Installing the SDK

To download and install the Yoti SDK and its dependencies, simply run the following command from your terminal:

go get "github.com/getyoti/yoti-go-sdk"

SDK Project import

You can reference the project URL by adding the following import:

import "github.com/getyoti/yoti-go-sdk"

Configuration

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

sdkID := "your-sdk-id";
key, err := ioutil.ReadFile("path/to/your-application-pem-file.pem")
if err != nil {
    // handle key load error
}

client := yoti.Client{
    SdkID: sdkID,
    Key: key}

Where:

  • sdkID is the SDK identifier generated by Yoti Dashboard in the Key tab when you create your app. Note this is not your Application Identifier which is needed by your client-side code.

  • path/to/your-application-pem-file.pem is the path to the application pem file. It can be downloaded from the Keys tab in the Yoti Dashboard.

Please do not open the pem file as this might corrupt the key and you will need to create a new application.

Keeping your settings and access keys outside your repository is highly recommended. You can use gems like godotenv to manage environment variables more easily.

Profile Retrieval

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

activityDetails, errStrings := client.GetActivityDetails(yotiOneTimeUseToken)
if len(errStrings) != 0 {
  // handle unhappy path
}
Profile

You can then get the user profile from the activityDetails struct:

var rememberMeID string = activityDetails.RememberMeID()
var userProfile yoti.Profile = activityDetails.UserProfile

var selfie = userProfile.Selfie().Value()
var givenNames string = userProfile.GivenNames().Value()
var familyName string = userProfile.FamilyName().Value()
var fullName string = userProfile.FullName().Value()
var mobileNumber string = userProfile.MobileNumber().Value()
var emailAddress string = userProfile.EmailAddress().Value()
var address string = userProfile.Address().Value()
var gender string = userProfile.Gender().Value()
var nationality string = userProfile.Nationality().Value()
var dateOfBirth *time.Time
dobAttr, err := userProfile.DateOfBirth()
if err != nil {
    //handle error
} else {
    dateOfBirth = dobAttr.Value()
}
var structuredPostalAddress map[string]interface{}
structuredPostalAddressAttribute, err := userProfile.StructuredPostalAddress()
if err != nil {
    //handle error
} else {
    structuredPostalAddress := structuredPostalAddressAttribute.Value().(map[string]interface{})
}

If you have chosen Verify Condition on the Yoti Dashboard with the age condition of "Over 18", you can retrieve the user information with the generic .GetAttribute method, which requires the result to be cast to the original type:

userProfile.GetAttribute("age_over:18").Value().(string)

GetAttribute returns an interface, the value can be acquired through a type assertion.

Anchors, Sources and Verifiers

An Anchor represents how a given Attribute has been sourced or verified. These values are created and signed whenever a Profile Attribute is created, or verified with an external party.

For example, an attribute value that was sourced from a Passport might have the following values:

Anchor property Example value
type SOURCE
value PASSPORT
subType OCR
signedTimestamp 2017-10-31, 19:45:59.123789

Similarly, an attribute verified against the data held by an external party will have an Anchor of type VERIFIER, naming the party that verified it.

From each attribute you can retrieve the Anchors, and subsets Sources and Verifiers (all as []*anchor.Anchor) as follows:

givenNamesAnchors := userProfile.GivenNames().Anchors()
givenNamesSources := userProfile.GivenNames().Sources()
givenNamesVerifiers := userProfile.GivenNames().Verifiers()

You can also retrieve further properties from these respective anchors in the following way:

var givenNamesFirstAnchor *anchor.Anchor = givenNamesAnchors[0]

var anchorType anchor.Type = givenNamesFirstAnchor.Type()
var signedTimestamp *time.Time = givenNamesFirstAnchor.SignedTimestamp().Timestamp()
var subType string = givenNamesFirstAnchor.SubType()
var value []string = givenNamesFirstAnchor.Value()

Handling Users

When you retrieve the user profile, you receive a user ID 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 this ID to verify whether (for your application) the retrieved profile identifies a new or an existing user. Here is an example of how this works:

activityDetails, err := client.GetActivityDetails(yotiOneTimeUseToken)
if err == nil {
    user := YourUserSearchFunction(activityDetails.RememberMeID())
    if user != nil {
        // 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 RememberMeID. 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.

Running the Tests

You can run the unit tests for this project by executing the following commands inside the repository folder

go get -t
go test

AML Integration

Yoti provides an AML (Anti Money Laundering) check service to allow a deeper KYC process to prevent fraud. This is a chargeable service, so please contact sdksupport@yoti.com for more information.

Yoti will provide a boolean result on the following checks:

  • PEP list - Verify against Politically Exposed Persons list
  • Fraud list - Verify against US Social Security Administration Fraud (SSN Fraud) list
  • Watch list - Verify against watch lists from the Office of Foreign Assets Control

To use this functionality you must ensure your application is assigned to your Organisation in the Yoti Dashboard - please see here for further information.

For the AML check you will need to provide the following:

  • Data provided by Yoti (please ensure you have selected the Given name(s) and Family name attributes from the Data tab in the Yoti Dashboard)
    • Given name(s)
    • Family name
  • Data that must be collected from the user:
    • Country of residence (must be an ISO 3166 3-letter code)
    • Social Security Number (US citizens only)
    • Postcode/Zip code (US citizens only)

Performing an AML check on a person requires their consent. You must ensure you have user consent before using this service.

Code Example

Given a YotiClient initialised with your SDK ID and KeyPair (see Client Initialisation) performing an AML check is a straightforward case of providing basic profile data.

givenNames := "Edward Richard George"
familyName := "Heath"

amlAddress := yoti.AmlAddress{
    Country: "GBR"}

amlProfile := yoti.AmlProfile{
    GivenNames: givenNames,
    FamilyName: familyName,
    Address:    amlAddress}

result, err := client.PerformAmlCheck(amlProfile)

log.Printf(
    "AML Result for %s %s:",
    givenNames,
    familyName)
log.Printf(
    "On PEP list: %s",
    strconv.FormatBool(result.OnPEPList))
log.Printf(
    "On Fraud list: %s",
    strconv.FormatBool(result.OnFraudList))
log.Printf(
    "On Watch list: %s",
    strconv.FormatBool(result.OnWatchList))
}

Additionally, an example AML application is provided in the examples folder.

  • Rename the .env.example file to .env and fill in the required configuration values (mentioned in the Configuration section)
  • Change directory to the aml example folder: cd examples/aml
  • Install the dependencies with go get
  • Start the example with go run main.go

Running the Profile Example

The profile retrieval example can be found in the examples folder.

  • Change directory to the profile example folder: cd examples/profile
  • On the Yoti Dashboard:
    • Set the application domain of your app to localhost:8080
    • Set the scenario callback URL to /profile
  • Rename the .env.example file to .env and fill in the required configuration values (mentioned in the Configuration section)
  • Install the dependencies with go get
  • Start the server with go run main.go certificatehelper.go

Visiting https://localhost:8080/ should show a Yoti Connect button

API Coverage

  • Activity Details
    • Remember Me ID RememberMeID()
    • User Profile UserProfile
      • Selfie Selfie()
      • Selfie Base64 URL Selfie().Value().Base64URL()
      • Given Names GivenNames()
      • Family Name FamilyName()
      • Full Name FullName()
      • Mobile Number MobileNumber()
      • Email Address EmailAddress()
      • Date of Birth DateOfBirth()
      • Postal Address Address()
      • Structured Postal Address StructuredPostalAddress()
      • Gender Gender()
      • Nationality Nationality()

Support

For any questions or support please email sdksupport@yoti.com. Please provide the following to get you up and working as quickly as possible:

  • Computer type
  • OS version
  • Version of Go being used
  • Screenshot

Once we have answered your question we may contact you again to discuss Yoti products and services. If you’d prefer us not to do this, please let us know when you e-mail.

References

Documentation

Index

Constants

View Source
const (
	// HTTPMethodPost Post HTTP method
	HTTPMethodPost = "POST"
	// HTTPMethodGet Get HTTP method
	HTTPMethodGet = "GET"
	// HTTPMethodPut Put HTTP method
	HTTPMethodPut = "PUT"
	// HTTPMethodPatch Patch HTTP method
	HTTPMethodPatch = "PATCH"
)

Variables

View Source
var (
	// ErrProfileNotFound profile was not found during activity retrieval for the provided one time use token
	ErrProfileNotFound = errors.New("ProfileNotFound")
	// ErrFailure there was a failure during activity retrieval
	ErrFailure = errors.New("Failure")
	// ErrSharingFailure there was a failure when sharing
	ErrSharingFailure = errors.New("SharingFailure")
)

Functions

This section is empty.

Types

type ActivityDetails

type ActivityDetails struct {
	UserProfile Profile
	// contains filtered or unexported fields
}

ActivityDetails represents the result of an activity between a user and the application.

func (ActivityDetails) RememberMeID

func (a ActivityDetails) RememberMeID() string

RememberMeID is a unique identifier Yoti assigns to your user, but only for your app. If the same user logs into your app again, you get the same id. If she/he logs into another application, Yoti will assign a different id for that app.

type AmlAddress added in v1.1.0

type AmlAddress struct {
	Country  string `json:"country"`
	Postcode string `json:"post_code"`
}

AmlAddress Address for Anti Money Laundering (AML) purposes

type AmlProfile added in v1.1.0

type AmlProfile struct {
	GivenNames string     `json:"given_names"`
	FamilyName string     `json:"family_name"`
	Address    AmlAddress `json:"address"`
	SSN        string     `json:"ssn"`
}

AmlProfile User profile for Anti Money Laundering (AML) checks

type AmlResult added in v1.1.0

type AmlResult struct {
	OnFraudList bool `json:"on_fraud_list"`
	OnPEPList   bool `json:"on_pep_list"`
	OnWatchList bool `json:"on_watch_list"`
}

AmlResult Result of Anti Money Laundering (AML) check for a particular user

func GetAmlResult

func GetAmlResult(amlResponse []byte) (AmlResult, error)

GetAmlResult Parses AML result from response

func GetAmlResultFromResponse deprecated added in v1.1.0

func GetAmlResultFromResponse(amlResponse []byte) AmlResult

Deprecated: Will be removed in v3.0.0, please use GetAmlResult below instead. Parses AML result from response

type AttributeType deprecated

type AttributeType int

Deprecated: AttributeType format of the attribute

const (
	// AttributeTypeDate date format
	AttributeTypeDate AttributeType = 1 + iota
	// AttributeTypeText text format
	AttributeTypeText
	// AttributeTypeJPEG JPEG format
	AttributeTypeJPEG
	// AttributeTypePNG PNG fornmat
	AttributeTypePNG
	// AttributeTypeJSON JSON fornmat
	AttributeTypeJSON
)

type AttributeValue deprecated added in v1.1.0

type AttributeValue struct {
	// Type represents the format of the piece of user data, whether it is a date, a piece of text or a picture
	//
	// Note the potential values for this variable are stored in constants with names beginning with
	// 'AttributeType'. These include:
	// 	yoti.AttributeTypeDate
	// 	yoti.AttributeTypeText
	// 	yoti.AttributeTypeJPEG
	// 	yoti.AttributeTypePNG
	// 	yoti.AttributeTypeJSON
	Type  AttributeType
	Value []byte
}

Deprecated: Will be removed in v3.0.0, values here will be available on Attribute objects. AttributeValue represents a small piece of information about a Yoti user such as a photo of the user or the user's date of birth.

func (AttributeValue) GetContentType deprecated added in v1.1.0

func (val AttributeValue) GetContentType() (result string)

Deprecated: Will be removed in v3.0.0, use GetMIMEType() instead. GetContentType returns the MIME type of this piece of Yoti user information. For more information see: https://en.wikipedia.org/wiki/Media_type

type Client added in v1.1.0

type Client struct {
	// SdkID represents the SDK ID and NOT the App ID. This can be found in the integration section of your
	// application dashboard at https://www.yoti.com/dashboard/
	SdkID string

	// Key should be the security key given to you by yoti (see: security keys section of
	// https://www.yoti.com/dashboard/) for more information about how to load your key from a file see:
	// https://github.com/getyoti/yoti-go-sdk/blob/master/README.md
	Key []byte
}

Client represents a client that can communicate with yoti and return information about Yoti users.

func (*Client) GetActivityDetails

func (client *Client) GetActivityDetails(token string) (ActivityDetails, []string)

GetActivityDetails requests information about a Yoti user using the one time use token generated by the Yoti login process. It returns the outcome of the request. If the request was successful it will include the users details, otherwise it will specify a reason the request failed.

func (*Client) GetUserProfile deprecated added in v1.1.0

func (client *Client) GetUserProfile(token string) (userProfile UserProfile, firstError error)

Deprecated: Will be removed in v3.0.0. Use `GetActivityDetails` instead. GetUserProfile requests information about a Yoti user using the one time use token generated by the Yoti login process. It returns the outcome of the request. If the request was successful it will include the users details, otherwise it will specify a reason the request failed.

func (*Client) PerformAmlCheck added in v1.1.0

func (client *Client) PerformAmlCheck(amlProfile AmlProfile) (AmlResult, error)

PerformAmlCheck performs an Anti Money Laundering Check (AML) for a particular user. Returns three boolean values: 'OnPEPList', 'OnWatchList' and 'OnFraudList'.

type Image deprecated

type Image struct {
	Type ImageType
	Data []byte
}

Deprecated: Will be removed in v3.0.0 - use attribute.Image instead. ImageType struct containing the type of the image and the data in bytes.

func (*Image) GetContentType deprecated

func (image *Image) GetContentType() string

Deprecated: Will be removed in v3.0.0, please use image.GetMIMEType instead. GetContentType returns the MIME type of this piece of Yoti user information. For more information see: https://en.wikipedia.org/wiki/Media_type

func (*Image) URL deprecated

func (image *Image) URL() string

Deprecated: Will be removed in v3.0.0, please use image.Base64URL() instead. URL Image encoded in a base64 URL

type ImageType deprecated

type ImageType int

Deprecated: Will be removed in v3.0.0 - use attribute.ContentType instead. ImageType Image format

const (
	// ImageTypeJpeg JPEG format
	ImageTypeJpeg ImageType = 1 + iota
	// ImageTypePng PNG format
	ImageTypePng
	// ImageTypeOther Other image formats
	ImageTypeOther
)

type Profile

type Profile struct {
	// contains filtered or unexported fields
}

Profile represents the details retrieved for a particular user. Consists of Yoti attributes: a small piece of information about a Yoti user such as a photo of the user or the user's date of birth.

func (Profile) Address

func (p Profile) Address() *attribute.StringAttribute

Address represents the user's address. Will be nil if not provided by Yoti

func (Profile) DateOfBirth

func (p Profile) DateOfBirth() (*attribute.TimeAttribute, error)

DateOfBirth represents the user's date of birth. Will be nil if not provided by Yoti. Has an err value which will be filled if there is an error parsing the date.

func (Profile) EmailAddress

func (p Profile) EmailAddress() *attribute.StringAttribute

EmailAddress represents the user's email address. Will be nil if not provided by Yoti

func (Profile) FamilyName

func (p Profile) FamilyName() *attribute.StringAttribute

FamilyName represents the user's family name. Will be nil if not provided by Yoti

func (Profile) FullName

func (p Profile) FullName() *attribute.StringAttribute

FullName represents the user's full name. Will be nil if not provided by Yoti

func (Profile) Gender

func (p Profile) Gender() *attribute.StringAttribute

Gender represents the user's gender. Will be nil if not provided by Yoti

func (Profile) GetAttribute

func (p Profile) GetAttribute(attributeName string) *attribute.GenericAttribute

GetAttribute retrieve an attribute by name on the Yoti profile. Will return nil if attribute is not present.

func (Profile) GivenNames

func (p Profile) GivenNames() *attribute.StringAttribute

GivenNames represents the user's given names. Will be nil if not provided by Yoti

func (Profile) MobileNumber

func (p Profile) MobileNumber() *attribute.StringAttribute

MobileNumber represents the user's mobile phone number. Will be nil if not provided by Yoti

func (Profile) Nationality

func (p Profile) Nationality() *attribute.StringAttribute

Nationality represents the user's nationality. Will be nil if not provided by Yoti

func (Profile) Selfie

func (p Profile) Selfie() *attribute.ImageAttribute

Selfie is a photograph of the user. Will be nil if not provided by Yoti

func (Profile) StructuredPostalAddress

func (p Profile) StructuredPostalAddress() (*attribute.JSONAttribute, error)

StructuredPostalAddress represents the user's address in a JSON format. Will be nil if not provided by Yoti

type UserProfile deprecated added in v1.1.0

type UserProfile struct {
	// ID is a unique identifier Yoti assigns to your user, but only for your app.
	// If the same user logs into your app again, you get the same id.
	// If she/he logs into another application, Yoti will assign a different id for that app.
	ID string

	// Selfie is a photograph of the user. This will be nil if not provided by Yoti
	Selfie *Image

	// GivenNames represents the user's given names. This will be an empty string if not provided by Yoti
	GivenNames string

	// Family represents the user's family name. This will be an empty string if not provided by Yoti
	FamilyName string

	// Full name represents the user's full name. This will be an empty string if not provided by Yoti
	FullName string

	// MobileNumber represents the user's mobile phone number. This will be an empty string if not provided by Yoti
	MobileNumber string

	// EmailAddress represents the user's email address. This will be an empty string if not provided by Yoti
	EmailAddress string

	// DateOfBirth represents the user's date of birth. This will be nil if not provided by Yoti
	DateOfBirth *time.Time

	// IsAgeVerified represents the result of the age verification check on the user. The bool will be true if they passed, false if they failed, and nil if there was no check
	IsAgeVerified *bool

	// Address represents the user's address. This will be an empty string if not provided by Yoti
	Address string

	// StructuredPostalAddress represents the user's address in a JSON format. This will be empty if not provided by Yoti
	StructuredPostalAddress interface{}

	// Gender represents the user's gender. This will be an empty string if not provided by Yoti
	Gender string

	// Nationality represents the user's nationality. This will be an empty string if not provided by Yoti
	Nationality string

	// OtherAttributes is a map of any other information about the user provided by Yoti. The key will be the name
	// of the piece of information, and the keys associated value will be the piece of information itself.
	OtherAttributes map[string]AttributeValue
}

Deprecated: Will be removed in v3.0.0. Use `Profile` instead. UserProfile represents the details retrieved for a particular

Directories

Path Synopsis
examples
aml

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL