Documentation
¶
Overview ¶
Package alice contains functions to interact with Alice Biometrics for doing the KYC.
@author Manuel Sales (assetverse.com 2020/08/03)
The link https://docs.alicebiometrics.com/onboarding/index.html contains how to communicate with Alice for doing the digital on-boarding and KYC/AML compliance. This module implements the calls to Alice backend to obtain the id and tokens used in the online client. The online client using the id, token and the web/android/ios sdk captures the photo, id front, id back and performs the liveness test. When done it communicates with the backend to complete the process generating the certificate and communicating to the entity that needs the KYC (in our case Pecunia)
Alice auth backend is at https://apis.alicebiometrics.com/auth/ui/#/ ; it is required to put in the header the apikey; the following services are used:
- GET /login_token -H "accept: application/json"curl -H "X-Consumer-Custom-ID: User" -H "apikey: ApiKey"; returns a {token:sessionToken}
- GET /backend_token/onboarding -H "accept: application/json" -H "Authorization: bearer sessionToken"; returns a {token:backendToken}
- GET /user_token/onboarding/userId -H "accept: application/json" -H "Authorization: bearer sessionToken"; returns userToken
Alice onboarding backend is at https://apis.alicebiometrics.com/onboarding/ui/#/ ; the following services are used: - POST /user -H "accept: application/json" -H "Content-Type: multipart/form-data" -H "Authorization: bearer backendToken", returns {user_id:userId}
Steps to obtain the userToken: 1 GET login_token(apiKey)>>sessionToken, 2 GET backend_token(sessionToken)>>backendToken, 3 POST user(backendToken)>>userId
Index ¶
- Constants
- Variables
- func CheckReport(userId string, userToken *AuthToken, sd map[string]string, voidBad bool) (code int, raw map[string]interface{}, err error)
- func CreateCertificate(userId, template string, userToken *AuthToken) (certificateId string, err error)
- func DoRequest(backend, path, method string, headerParams, formParams map[string]string, ...) (raw map[string]interface{}, err error)
- func GetCertificate(certificateId, userId, filePath string, userToken *AuthToken) (fileLen int, err error)
- func GetCertificates(userId string, userToken *AuthToken) (certificates []string, tss []int64, last int, err error)
- func GetMultiMap(raw map[string]interface{}, keys ...string) (val interface{}, ok bool)
- func GetMultiMapArr(raw map[string]interface{}, keys ...string) (valArr []string, ok bool)
- func GetMultiMapBool(raw map[string]interface{}, keys ...string) (valBool bool, ok bool)
- func GetMultiMapFlo(raw map[string]interface{}, keys ...string) (valFlo float64, ok bool)
- func GetMultiMapMap(raw map[string]interface{}, keys ...string) (valMap map[string]interface{}, ok bool)
- func GetMultiMapStr(raw map[string]interface{}, keys ...string) (valStr string, ok bool)
- func GetReport(userId string, userToken *AuthToken) (raw map[string]interface{}, err error)
- func GetUser(formParams map[string]string) (userId string, err error)
- func Init(user, apiKey, urlAuth, urlOnboard, basePath string)
- func PrintMultiMap(raw map[string]interface{})
- func WriteFile(filePath string, stream io.Reader) (fileLen int, err error)
- type AuthToken
Constants ¶
const BadExpiry = 2
const BadMrz = 4
const BadPhoto = 5
const DateFormat = 3
const FaceOk = 0.5
Threshold values for the document face and the selfie; if the score returned is >= they are considered valid
const Incomplete = 1
error codes
const SelfieOk = 0.7
const ServiceOnboarding = "onboarding"
ServiceOnboarding Alice onboarding service
Variables ¶
var ApiKey = "!!! PUT YOUR API KEY HERE !!!"
ApiKey the Alice provided apiKey
var BackendToken = make(map[string]AuthToken)
BackendToken map with the current backend tokens for each service
var BasePath = ""
BasePath contains the base path where the files are downloaded if no filePath set
var UrlAuth = "https://apis.alicebiometrics.com/auth"
UrlAuth the url of the Alice auth backend
var UrlOnboard = "https://apis.alicebiometrics.com/onboarding"
UrlOnboard the url of the Alice onboarding backend
var User = "!!! PUT YOUR USER ID HERE !!!"
User the Alice provided user
Functions ¶
func CheckReport ¶
func CheckReport(userId string, userToken *AuthToken, sd map[string]string, voidBad bool) (code int, raw map[string]interface{}, err error)
CheckReport returns a map for the Kyc; if voidBad it voids the selfie/document that not meets the validations
func CreateCertificate ¶
func CreateCertificate(userId, template string, userToken *AuthToken) (certificateId string, err error)
CreateCertificate creates the user certificate (Signed PDF Report) from uploaded and processed data and if al ok returns the certificateId. Once obtained with GET /user/certificate/{certificateId} the certificate can be downloaded
func DoRequest ¶
func DoRequest(backend, path, method string, headerParams, formParams map[string]string, jsonArr []byte, queryParams url.Values, filePath *string) (raw map[string]interface{}, err error)
DoRequest build the request (method POST, GET, ..; depending on the recuest, use the header/query/formParams)
func GetCertificate ¶
func GetCertificate(certificateId, userId, filePath string, userToken *AuthToken) (fileLen int, err error)
GetCertificate downloads the pdf with the certificate.
func GetCertificates ¶
func GetCertificates(userId string, userToken *AuthToken) (certificates []string, tss []int64, last int, err error)
GetCertificates the certificates for a userId; it returns an array of certificates, an array of the certificates timestamp and the index of the last timestamp.
func GetMultiMap ¶
GetMultiMap returns the value of a multimap with the keys provided (if the key can be parsed into a number the multimap is an array and the key is the index)
func GetMultiMapArr ¶
GetMultiMapArr returns the array string value of a multimap with the keys provided
func GetMultiMapBool ¶
GetMultiMapBool returns the boolean value of a multimap with the keys provided
func GetMultiMapFlo ¶
GetMultiMapFlo returns the float value of a multimap with the keys provided
func GetMultiMapMap ¶
func GetMultiMapMap(raw map[string]interface{}, keys ...string) (valMap map[string]interface{}, ok bool)
GetMultiMapMap returns the array string value of a multimap with the keys provided
func GetMultiMapStr ¶
GetMultiMapStr returns the string value of a multimap with the keys provided (as this function is used a lot to get the val it is not called GetMultiMap so it is more efficient)
func GetReport ¶
GetReport obtains json report of a userId from the Alice Onboarding backend using the onboarding backend userToken (if not available the function obtains it automatically). The formParams are optional (can be nil); there are the following ones: device_model device_platform device_platform_version email first_name last_name
func GetUser ¶
GetUser obtains the userId from the Alice Onboarding backend using the onboarding backendToken (if not available the function obtains it automatically). The formParams are optional (can be nil); there are the following ones: device_model device_platform device_platform_version email first_name last_name
func Init ¶
func Init(user, apiKey, urlAuth, urlOnboard, basePath string)
Init initialize the Alice credentials and urls; the values empty are ignored.
func PrintMultiMap ¶
func PrintMultiMap(raw map[string]interface{})
PrintMultiMap prints report decoded json structure
Types ¶
type AuthToken ¶
type AuthToken struct { Token string // token Till int64 // valid till epoch timestamp when expires the session token }
AuthToken struct to contain the token and its expiry (all Alice Auth backend tokens have 1h expiry)
var SessionToken AuthToken
SessionToken the current session token
func AuthBackendToken ¶
AuthBackendToken obtains the backendToken from the Alice Auth backend using the sessionToken (if not available the function obtains it automatically).
func AuthBackendUserToken ¶
AuthBackendUserToken obtains the backend userToken from the Alice Auth backend using the sessionToken (if not available the function obtains it automatically).
func AuthSessionToken ¶
AuthSessionToken obtains the sessionToken from the Alice Auth backend using the apiKey; it also returns the expiry of the token.
func AuthUserToken ¶
AuthUserToken obtains the userToken from the Alice Auth backend using the sessionToken (if not available the function obtains it automatically).