idenfy

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

README

Idenfy Golang Library

GitHub Release test status Follow on Twitter

Idenfy Golang is a Golang library for requesting and receiving verifications from the Idenfy API.

Features

  • Client side request validation
  • Token request
  • Webhook parsing
  • Webhook signature verification (mandatory)

Missing

  • Proper AML detailed service report, currently passed as []map[string]interface{}
  • Anything not related to session creation/validation

Usage

See the Go documentation for more details.

Request verification token
package main

import (
	"context"
	"github.com/gboddin/go-idenfy"
	"log"
)

func main() {
	// Create an idenfy client
	client, err := idenfy.NewClient(
		idenfy.WithApiCredentials("access-key", "secret-key"),
		idenfy.WithCustomEndpoint("http://localhost:8080"),
	)
	if err != nil {
		panic(err)
	}
	// Create a token request
	tokenReq := idenfy.TokenRequest{
		ClientId:            "your-local-id",
		DateOfBirth:         &idenfy.Date{Year: 1981, Month: 3, Day: 4},
		GenerateDigitString: idenfy.Bool(false),
	}
	// create verification session
	tokenResp, err := client.CreateIdentityVerificationSession(context.Background(), tokenReq)
	if err != nil {
		panic(err)
	}
	// Get authToken and/or redirect URL
	log.Println(tokenResp.AuthToken, tokenResp.DateOfBirth, tokenResp.GetRedirectUrl())
}

Receive webhook
package main

import (
	"github.com/gboddin/go-idenfy"
	"log"
	"net/http"
)

var idenfyClient *idenfy.Client

func main() {
	var err error
	idenfyClient, err = idenfy.NewClient(
		idenfy.WithCallbackSignatureKey("signature-key"),
		idenfy.WithCustomEndpoint("http://localhost:8080"),
	)
	if err != nil {
		panic(err)
	}
	http.HandleFunc("/webhook/idenfy", receiveHook)
	log.Println("Starting server at http://localhost:8081")
	http.ListenAndServe(":8081", nil)
}

func receiveHook(w http.ResponseWriter, req *http.Request) {
	// Decode hook request and verify its signature
	reply, err := idenfyClient.DecodeHttpRequestIdentityCallback(req)
	if err != nil {
		w.WriteHeader(500)
		w.Write([]byte(err.Error()))
		return
	}
	// Do something with the reply
	log.Println(reply.ClientId)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidDate = errors.New("invalid date")
View Source
var ErrServerError = errors.New("received server error")

Functions

func Bool

func Bool(value bool) *bool

Bool returns and Idenfy bool that can be null

func Int

func Int(value int) *int

Int returns and Idenfy int type that can be null

Types

type AML

type AML struct {
	Status           ServiceStatus            `json:"status"`
	Data             []map[string]interface{} `json:"data"`
	ServiceName      string                   `json:"serviceName"`
	ServiceGroupType string                   `json:"serviceGroupType"`
	Uid              string                   `json:"uid"`
	ErrorMessage     string                   `json:"errorMessage"`
}

type Client

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

func NewClient

func NewClient(options ...ClientOption) (*Client, error)

NewClient Creates a new Idenfy API client

func (*Client) CreateIdentityVerificationSession

func (c *Client) CreateIdentityVerificationSession(ctx context.Context, request TokenRequest) (*TokenResponse, error)

CreateIdentityVerificationSession Creates a new identity verification session and returns the response

func (*Client) DecodeHttpRequestIdentityCallback

func (c *Client) DecodeHttpRequestIdentityCallback(request *http.Request) (*IdentityCallbackResp, error)

DecodeHttpRequestIdentityCallback Decodes an identity callback response from an *http.Request and verify its signature

func (*Client) DecodeReaderIdentityCallback

func (c *Client) DecodeReaderIdentityCallback(reader io.Reader, sigHeader string) (*IdentityCallbackResp, error)

DecodeReaderIdentityCallback Decodes an identity callback response from an io.Reader and verify its signature

type ClientOption

type ClientOption func(client *Client) error

func WithApiCredentials

func WithApiCredentials(accessKey, secretKey string) ClientOption

WithApiCredentials Option is used to specify Idenfy API credentials

func WithCallbackSignatureKey

func WithCallbackSignatureKey(key string) ClientOption

WithCallbackSignatureKey Option is used to specify a callback signature key to verify requests signatures

func WithCustomEndpoint

func WithCustomEndpoint(endpoint string) ClientOption

WithCustomEndpoint Option is used to specify an alternative API endpoint

func WithCustomHttpClient

func WithCustomHttpClient(httpClient *http.Client) ClientOption

WithCustomHttpClient Option is used to specify a custom *http.Client to make requests with

type Data

type Data struct {
	DocFirstname           string   `json:"docFirstName"`
	DocLastname            string   `json:"docLastName"`
	DocNumber              string   `json:"docNumber"`
	DocPersonalCode        string   `json:"docPersonalCode"`
	DocExpiry              string   `json:"docExpiry"`
	DocDob                 string   `json:"docDob"`
	DocDateOfIssue         string   `json:"docDateOfIssue"`
	DocType                Document `json:"docType"`
	DocSex                 string   `json:"docSex"`
	DocNationality         string   `json:"docNationality"`
	DocIssuingCountry      string   `json:"docIssuingCountry"`
	DocTemporaryAddress    string   `json:"docTemporaryAddress"`
	DocBirthName           string   `json:"docBirthName"`
	BirthPlace             string   `json:"birthPlace"`
	Authority              string   `json:"authority"`
	Address                string   `json:"address"`
	MothersMaidenName      string   `json:"mothersMaidenName"`
	DriverLicenseCategory  string   `json:"driverLicenseCategory"`
	ManuallyDataChanged    bool     `json:"manuallyDataChanged"`
	FullName               string   `json:"fullName"`
	SelectedCountry        string   `json:"selectedCountry"`
	OrgFirstName           string   `json:"orgFirstName"`
	OrgLastName            string   `json:"orgLastName"`
	OrgNationality         string   `json:"orgNationality"`
	OrgBirthPlace          string   `json:"orgBirthPlace"`
	OrgAuthority           string   `json:"orgAuthority"`
	OrgAddress             string   `json:"orgAddress"`
	OrgTemporaryAddress    string   `json:"OrgTemporaryAddress"`
	OrgMothersMaidenName   string   `json:"orgMothersMaidenName"`
	OrgBirthName           string   `json:"orgBirthName"`
	AgeEstimate            string   `json:"ageEstimate"`
	ClientIpProxyRiskLevel string   `json:"clientIpProxyRiskLevel"`
	DuplicateFaces         []string `json:"duplicateFaces"`
	DuplicateDocFaces      []string `json:"duplicateDocFaces"`
}

type Date

type Date struct {
	Year  int
	Month int
	Day   int
}

Date represents a date without time

func (Date) MarshalJSON

func (d Date) MarshalJSON() ([]byte, error)

MarshalJSON converts a Date into an Idenfy date

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(data []byte) error

UnmarshalJSON converts an Idenfy date into a Date

type Document

type Document string
const (
	ID_CARD                Document = "ID_CARD"
	PASSPORT               Document = "PASSPORT"
	RESIDENCE_PERMIT       Document = "RESIDENCE_PERMIT"
	DRIVER_LICENSE         Document = "DRIVER_LICENSE"
	AADHAAR                Document = "AADHAAR"
	PAN_CARD               Document = "PAN_CARD"
	VISA                   Document = "VISA"
	BORDER_CROSSING        Document = "BORDER_CROSSING"
	ASYLUM                 Document = "ASYLUM"
	NATIONAL_PASSPORT      Document = "NATIONAL_PASSPORT"
	INTERNATIONAL_PASSPORT Document = "INTERNATIONAL_PASSPORT"
	VOTER_CARD             Document = "VOTER_CARD"
	OLD_ID_CARD            Document = "OLD_ID_CARD"
	TRAVEL_CARD            Document = "TRAVEL_CARD"
	PHOTO_CARD             Document = "PHOTO_CARD"
	MILITARY_CARD          Document = "MILITARY_CARD"
	PROOF_OF_AGE_CARD      Document = "PROOF_OF_AGE_CARD"
	DIPLOMATIC_ID          Document = "DIPLOMATIC_ID"
)

type IdentityCallbackResp

type IdentityCallbackResp struct {
	Final           *bool             `json:"final"`
	Platform        string            `json:"platform"`
	Status          Status            `json:"status"`
	Data            Data              `json:"data"`
	FileUrls        map[string]string `json:"fileUrls"`
	AML             []AML             `json:"AML"`
	LID             []LID             `json:"LID"`
	ScanRef         string            `json:"scanRef"`
	ExternalRef     string            `json:"externalRef"`
	ClientId        string            `json:"clientId"`
	StartTime       int64             `json:"startTime"`
	FinishTime      int64             `json:"finishTime"`
	ClientIp        string            `json:"clientIp"`
	ClientIpCountry string            `json:"clientIpCountry"`
	ClientLocation  string            `json:"clientLocation"`
	GdcMatch        bool              `json:"gdcMatch"`
	ManualAddress   string            `json:"manualAddress"`
}

type LID

type LID struct {
	Status           ServiceStatus `json:"status"`
	Data             []LIDData     `json:"data"`
	ServiceName      string        `json:"serviceName"`
	ServiceGroupType string        `json:"serviceGroupType"`
	Uid              string        `json:"uid"`
	ErrorMessage     string        `json:"errorMessage"`
}

type LIDData

type LIDData struct {
	DocumentNumber string   `json:"documentNumber"`
	DocumentType   Document `json:"documentType"`
	Valid          bool     `json:"valid"`
	ExpiryDate     string   `json:"expiryDate"`
	CheckDate      string   `json:"checkDate"`
}

type ServiceStatus

type ServiceStatus struct {
	ServiceSuspected bool   `json:"serviceSuspected"`
	CheckSuccessful  bool   `json:"checkSuccessful"`
	ServiceFound     bool   `json:"serviceFound"`
	ServiceUsed      bool   `json:"serviceUsed"`
	OverallStatus    string `json:"overallStatus"`
}

type Status

type Status struct {
	Overall         string   `json:"overall"`
	FraudTags       []string `json:"fraudTags"`
	MismatchTags    []string `json:"mismatchTags"`
	AutoFace        string   `json:"autoFace"`
	ManualFace      string   `json:"manualFace"`
	AutoDocument    string   `json:"autoDocument"`
	ManualDocument  string   `json:"manualDocument"`
	AdditionalSteps string   `json:"additionalSteps"`
}

type TokenRequest

type TokenRequest struct {
	ClientId            string     `json:"clientId"`
	Firstname           string     `json:"firstName,omitempty"`
	Lastname            string     `json:"lastName,omitempty"`
	SuccessUrl          string     `json:"successUrl,omitempty"`
	ErrorUrl            string     `json:"errorUrl,omitempty"`
	UnverifiedUrl       string     `json:"unverifiedUrl,omitempty"`
	Locale              string     `json:"locale,omitempty"`
	ShowInstructions    *bool      `json:"showInstructions,omitempty"`
	ExpiryTime          *int       `json:"expiryTime,omitempty"`
	SessionLength       *int       `json:"sessionLength,omitempty"`
	Country             string     `json:"country,omitempty"`
	Documents           []Document `json:"documents,omitempty"`
	DateOfBirth         *Date      `json:"dateOfBirth,omitempty"`
	DateOfExpiry        *Date      `json:"dateOfExpiry,omitempty"`
	DateOfIssue         *Date      `json:"dateOfIssue,omitempty"`
	Nationality         string     `json:"nationality,omitempty"`
	PersonalNumber      string     `json:"personalNumber,omitempty"`
	DocumentNumber      string     `json:"documentNumber,omitempty"`
	Sex                 string     `json:"sex,omitempty"`
	GenerateDigitString *bool      `json:"generateDigitString,omitempty"`
	Address             string     `json:"address,omitempty"`
	TokenType           Type       `json:"tokenType,omitempty"`
	VideoCallQuestions  []string   `json:"videoCallQuestions,omitempty"`
	ExternalRef         string     `json:"externalRef,omitempty"`
	UtilityBill         *bool      `json:"utilityBill,omitempty"`
	CallbackUrl         string     `json:"callbackUrl,omitempty"`
	Questionnaire       string     `json:"questionnaire,omitempty"`
}

func (TokenRequest) Validate

func (t TokenRequest) Validate() error

Validate Validates the token request against Idenfy specifications

type TokenResponse

type TokenResponse struct {
	ClientId            string     `json:"clientId"`
	Firstname           string     `json:"firstName,omitempty"`
	Lastname            string     `json:"lastName,omitempty"`
	SuccessUrl          string     `json:"successUrl,omitempty"`
	ErrorUrl            string     `json:"errorUrl,omitempty"`
	UnverifiedUrl       string     `json:"unverifiedUrl,omitempty"`
	Locale              string     `json:"locale,omitempty"`
	ShowInstructions    *bool      `json:"showInstructions,omitempty"`
	ExpiryTime          *int       `json:"expiryTime,omitempty"`
	SessionLength       *int       `json:"sessionLength,omitempty"`
	Country             string     `json:"country,omitempty"`
	Documents           []Document `json:"documents,omitempty"`
	DateOfBirth         *Date      `json:"dateOfBirth,omitempty"`
	DateOfExpiry        *Date      `json:"dateOfExpiry,omitempty"`
	DateOfIssue         *Date      `json:"dateOfIssue,omitempty"`
	Nationality         string     `json:"nationality,omitempty"`
	PersonalNumber      string     `json:"personalNumber,omitempty"`
	DocumentNumber      string     `json:"documentNumber,omitempty"`
	Sex                 string     `json:"sex,omitempty"`
	GenerateDigitString *bool      `json:"generateDigitString,omitempty"`
	Address             string     `json:"address,omitempty"`
	TokenType           Type       `json:"tokenType,omitempty"`
	VideoCallQuestions  []string   `json:"videoCallQuestions,omitempty"`
	ExternalRef         string     `json:"externalRef,omitempty"`
	UtilityBill         *bool      `json:"utilityBill,omitempty"`
	CallbackUrl         string     `json:"callbackUrl,omitempty"`
	Questionnaire       string     `json:"questionnaire,omitempty"`
	Message             string     `json:"message,omitempty"`
	AuthToken           string     `json:"authToken,omitempty"`
	ScanRef             string     `json:"scanRef,omitempty"`
	DigitString         string     `json:"digitString,omitempty"`
}

func (TokenResponse) GetRedirectUrl

func (t TokenResponse) GetRedirectUrl() string

GetRedirectUrl Returns the URL to redirect the client to complete the verification

type Type

type Type string
const (
	DOCUMENT                  Type = "DOCUMENT"
	IDENTIFICATION            Type = "IDENTIFICATION"
	VIDEO_CALL                Type = "VIDEO_CALL"
	VIDEO_CALL_PHOTOS         Type = "VIDEO_CALL_PHOTOS"
	VIDEO_CALL_IDENTIFICATION Type = "VIDEO_CALL_IDENTIFICATION"
)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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