Skip to content

Get up and running with Citadel Bridge and the API in minutes

License

Notifications You must be signed in to change notification settings

mgdelmonte/quickstart

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

Let's get you started with Citadel by walking through this Quickstart app. You'll need a set of API keys which you can request via email [email protected].

You'll have two different API keys (client_id, access_key) and a public_key for initiating the widget, and we'll start in the Sandbox environment.

Set up the Quickstart

Once you have your API keys, it's time to run the Citadel Quickstart app locally. You have two options - running with docker and docker-compose or starting with python and virtual env

Quickstart with docker/docker-compose

Requirements: docker and docker-compose are available.

After you have to write your SECRET_KEY, CLIENT_ID and PUBLIC_KEY to the .env file.

Content of .env has to look like this:

API_URL=https://prod.citadelid.com/v1/
API_PUBLIC_KEY=<YOUR PUBLIC KEY HERE>
API_SECRET=<YOUR SECRET KEY MUST BE HERE>
API_CLIENT_ID=<YOUR CLIENT_ID HERE>
API_PRODUCT_TYPE=employment OR income
  • make python_docker

After running this command, you should see:

web_1  | ======================================== ENVIRONMENT ======================================== 
web_1  |  https://prod.citadelid.com/v1/ 
web_1  |  {
web_1  |     "X-Access-Secret": "<YOUR SECRET_KEY HERE>",
web_1  |     "X-Access-Client-Id": "<YOUR CLIENT_ID HERE>",
web_1  |     "Content-Type": "application/json;charset=UTF-8"
web_1  | } 
web_1  |  ============================================================================================== 
web_1  | 
web_1  |  * Serving Flask app "server" (lazy loading)
web_1  |  * Environment: development
web_1  |  * Debug mode: on
web_1  |  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
web_1  |  * Restarting with stat
web_1  |  * Debugger is active!
web_1  |  * Debugger PIN: 593-914-178

To access the app, open http://127.0.0.1:5000/ in your browser.

Quickstart with python and virtual env

Requirements: python --version must print into console Python 3.8.X

After you have to write your SECRET_KEY, CLIENT_ID and PUBLIC_KEY to the .env file.

Content of .env have to look like this:

API_URL=https://prod.citadelid.com/v1/
API_PUBLIC_KEY=<YOUR PUBLIC KEY HERE>
API_SECRET=<YOUR SECRET KEY MUST BE HERE>
API_CLIENT_ID=<YOUR CLIENT_ID HERE>
API_PRODUCT_TYPE=employment, income or admin
  • make python_local
======================================== ENVIRONMENT ======================================== 
 https://prod.citadelid.com/v1/ 
 {
    "X-Access-Secret": "sandbox-a6908e6a533605baddd8d8a9d9fda6cf31aa3e0a",
    "X-Access-Client-Id": "d2f856c7d0b845129feaa8e955462779",
    "Content-Type": "application/json;charset=UTF-8"
} 
 ============================================================================================== 

 * Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
 * Serving Flask app "server" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

To access the app, open http://127.0.0.1:5000/ in your browser.

Run you first verification

Overview

Quickstart app emulates the experience of an applicant going through a background check/income verification and visiting the applicant portal.

Before using Citadel for verification, applicants filled out the form.

To streamline the process and make employment/income verification easy and instant, we "hide" the form behind the button.

If the verification is successful via Citadel, then we show to the applicant the data that we found in their payroll account.

If the verification isn't successful or the applicant decided to exit Citadel's widget, the applicant will see the form, fill it out and the verification can be done via an existing verification process.

Successful verification

After opening the Quickstart app running locally, click the Verify employment/Verify income button, search for a company, eg Facebook and select any provider.

Use the Sandbox credentials to simulate a successful login.

username: goodlogin
password: goodpassword

Once you have entered your credentials and moved to the next screen, you have succesfully done your first verification.

The API call will be executed and the data will be loaded into the fields of the form.

No verification

Now click Add employer button, search for a company, eg Facebook and select any provider.

Click exit icon at the top right of the widget and you'll see the empty form.

Successful administration

If using the admin product type, after opening the Quickstart app running locally click the Connect button and select any provider. Enter Skx8LTnyrLiw4SYk8xfkRwOt5OGQbNulypqdsqd for the API Key and click submit. The API call will be executed and the data will be loaded into the drop downs.

What happened under the hood

Token exchange flow

First we initiate the widget using your public_key.

        const bridge = CitadelBridge.init({
          clientName: 'Citadel Quickstart',
          companyMappingId: null,
          key: '{{ public_key }}',
          product: '{{ product_type}}',
          trackingInfo: 'any data for tracking current user',
          onLoad: function () {
            console.log('loaded');
            successClosing = null
          },
          onEvent: function (eventType) {
            console.log('event: ', eventType);
          },
          onSuccess: async function (token) {
            console.log('token: ', token);

            successClosing = true

            const content = document.querySelector('.spinnerContainer');

            content.classList.remove('hidden');
            let verificationInfo;
            try {
              verificationInfo = await apiRequests.getVerificationInfoByToken(token);
            } catch(e) {
              console.error(e)
              content.classList.add('hidden');
              return;
            }
            content.classList.add('hidden');

            if (!verificationInfo.length) {
              return;
            }

            setUserInfo(verificationInfo[0]);

            renderEmploymentHistory(verificationInfo);
          },
          onError: function () {
            console.log('error');
          },
          onClose: function () {
            console.log('closed');
            if (successClosing !== true) {
              renderEmploymentHistory([{ company: { address: {} } }]);
            }
          },
        });
        window.bridge = bridge;
      })();

Once widget is initiated, we receive public_token that can be exchange for access_token that will be used to access data via API and that will be unique for this verification.

API calls

After receiving the access_token we can make API calls and pass the data to the frontend to show in the app.

    def get_verification_info_by_token(self, access_token: str) -> Any:
        class VerificationRequest(TypedDict):
            access_token: str

        request_data: VerificationRequest = {'access_token': access_token}

        return requests.post(
            self.API_URL + 'verifications/employments/',
            json=request_data,
            headers=self.API_HEADERS,
        ).json()

When verification was successful, we show the form and populate it with data that we received from the backend:

          onSuccess: async function (token) {
            console.log('token: ', token);

            successClosing = true

            const content = document.querySelector('.spinnerContainer');

            content.classList.remove('hidden');
            let verificationInfo;
            try {
              verificationInfo = await apiRequests.getVerificationInfoByToken(token);
            } catch(e) {
              console.error(e)
              content.classList.add('hidden');
              return;
            }
            content.classList.add('hidden');

            if (!verificationInfo.length) {
              return;
            }

            setUserInfo(verificationInfo[0]);

            renderEmploymentHistory(verificationInfo);
          },

And if the widget was closed, we show the form that the applicant can fill out:

          onClose: function () {
            console.log('closed');
            if (successClosing !== true) {
              renderEmploymentHistory([{ company: { address: {} } }]);
            }
          },

About

Get up and running with Citadel Bridge and the API in minutes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 56.1%
  • Ruby 26.5%
  • Python 10.1%
  • JavaScript 5.8%
  • Makefile 0.9%
  • Dockerfile 0.5%
  • Shell 0.1%