Package: yoti
Yoti Python SDKWelcome to the Yoti Python SDK. This repo contains the tools and step by step instructions you need to quickly integrate your Python back-end with Yoti so that your users can share their identity details with your application in a secure and trusted way.Table of ContentsAn Architectural view-
High level overview of integrationReferences-
Guides before you startRequirements-
Everything you need to get startedInstalling the SDK-
How to install our SDKSDK Project import-
How to install the SDK to your projectConfiguration-
Entry point explanationHandling Users-
How to manage usersRunning the examples-
How to retrieve a Yoti profile using the tokenAPI Coverage-
Attributes definedSupport-
Please feel free to reach outAn Architectural ViewBefore 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 can be configured in the Yoti Hub when you create/update your application. For more information on how to create an application please check ourdeveloper 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 and the profile decryption in step 8.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 theUser-Agentheader in order to provide different responses for desktop and mobile clients.ReferencesAES-256 symmetric encryptionRSA pkcs asymmetric encryptionProtocol buffersBase64 dataRequirementsTo see the versions of Python this SDK is compatible with, see thethe GitHub workflow tests filefile.Installing the SDKTo import the Yoti SDK inside your project, simply run the following command from your terminal:pipinstallyotiSDK Project ImportYou can reference the project URL by adding the following import:importyoti_python_sdkConfigurationAfter creating your application on theYoti Hub, you need to download the.PEMkey and save itoutsidethe repo (keep it private).The variables required for the SDK to work are found in the tabs on your Yoti application's settings page (Yoti Hub). These are:YOTI_SCENARIO_ID- This is used to configure the Yoti Login Button (seeFront End Integration).YOTI_CLIENT_SDK_ID- This is the SDK identifier generated by Yoti Hub in the Key tab when you create your app. Note this is not your Application Identifier which is needed by your client-side code.YOTI_KEY_FILE_PATH- This is the path to the application .pem file, we recommend keeping your .pem file outside of your repository. It can be downloaded only once from the Keys tab in your Yoti Hub. (e.g. /home/user/.ssh/access-security.pem).Please do not open the pem fileas this might corrupt the key and you will need to create a new application.One way to configure these environment variables is to use an .env file. There are.env.examplefiles supplied in theDjangoandFlaskexample projects, which you can rename to.envand enter your settings into this file.Do not use quotes when entering your environment variablesExample Initialisationfromyoti_python_sdkimportClient@app.route('/profile')defauth():client=Client(YOTI_CLIENT_SDK_ID,YOTI_KEY_FILE_PATH)activity_details=client.get_activity_details(request.args['token'])Handling UsersWhen 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:client=Client(YOTI_CLIENT_SDK_ID,YOTI_KEY_FILE_PATH)activity_details=client.get_activity_details(token)profile=activity_details.profileselfie=profile.selfie.valuegiven_names=profile.given_names.valuefamily_name=profile.family_name.valuefull_name=profile.full_name.valuephone_number=profile.phone_number.valuedate_of_birth=profile.date_of_birth.valuepostal_address=profile.postal_address.valuestructured_postal_address=profile.structured_postal_address.valuegender=profile.gender.valuenationality=profile.nationality.valueemail_address=profile.email_address.valueremember_me_id=activity_details.user_idparent_remember_me_id=activity_details.parent_remember_me_idreceipt_id=activity_details.receipt_idtimestamp=activity_details.timestampbase64_selfie_uri=activity_details.base64_selfie_uriYou can retrieve the anchors, sources and verifiers for each attribute as follows:given_names_attribute=profile.given_namesgiven_names_anchors=given_names_attribute.anchorsgiven_names_sources=given_names_attribute.sourcesgiven_names_verifiers=given_names_attribute.verifiersYou can also retrieve further properties from these respective anchors in the following way:source_anchor=given_names_sources[0]value=source_anchor.valuesub_type=source_anchor.sub_typetimestamp=source_anchor.signed_timestamporigin_server_certs=source_anchor.origin_server_certsIf you have chosenVerify Conditionon theYoti Hubwith the age condition of "Over 18", you can retrieve the user information as follows:age_verification_attribute=profile.get_attribute("age_over:18")You can retrieve the sources and verifiers in the same way as detailed above.Running the ExamplesFrom theYoti Hub:Set the application domain of your app tolocalhost:5000Set the scenario callback URL to/yoti/authWith DockerTo run the Flask or Django container:Clone this repositoryChange directory to the example project directory withcd examples/yoti_example_flaskforFlaskORcd examples/yoti_example_djangoforDjangoMake sure the environment variablesYOTI_SCENARIO_ID,YOTI_CLIENT_SDK_IDandYOTI_KEY_FILE_PATHare set using an .env file (instructions in theConfigurationsection).Please note that with Docker, the .pem file must reside in a location within where docker is being run from, so it should be placed somewhere under the respectiveyoti_example_flask/yoti_example_djangofolders.Rebuild the images if you have modified the docker-compose.yml file withdocker-compose build --no-cacheStart the container withdocker-compose upNavigate tohttps://localhost:5000Running LocallyFollow instructions in the README for each example:Profile - DjangoProfile - FlaskDoc ScanAPI CoverageActivity DetailsRemember Me IDuser_idParent Remember Me IDparent_remember_me_idReceiptIDreceipt_idTimestamptimestampProfileprofilePhotoselfieGiven Namesgiven_namesFamily Namefamily_nameFull Namefull_nameMobile Numberphone_numberEmail Addressemail_addressDate of Birthdate_of_birthAddresspostal_addressStructured Postal Addressstructured_postal_addressGendergenderNationalitynationalityApplication Profileapplication_profileNameapplication_nameURLapplication_urlLogoapplication_logoReceipt Background Colorapplication_receipt_bg_colorBase64 Selfie URIbase64_selfie_uriSupportFor any questions or support please emailclientsupport@yoti.com.
Please provide the following to get you up and working as quickly as possible:Computer typeOS versionVersion of Python being usedScreenshotOnce 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.Windows ConfigurationIf you're using Windows and you haven't installed Cryptography before, you might need to set two environment variables for Cryptography to install (it is a requirement of the Yoti package):setLIB=C:\OpenSSL-Win64\lib;%LIB%setINCLUDE=C:\OpenSSL-Win64\include;%INCLUDE%WhereOpenSSL-Win64is the location that you have installed OpenSSL to. Seeherefor more information.