Skip to main content

WebCase NUBUBankId

SDK for NBU's BankID authorization.

  • Simple API client to collect user data.
  • Small wrapper for EUSignCP library for a simpler data manipulation.
  • Python social auth integration: Authorization Backend.

Installation

pip install wc-bankid-nbu
  1. Create folder to store certificates:

    • By default it's: /data/certificates.
    • Here: https://iit.com.ua/downloads. Find and upload to this folder 2 certficate files:
      • CACertificates.p7b
      • CACertificates.Test.p7b
    • Then 2 certificates like EU-*.cer and private key Key-6.dat also should be placed there. You will get them from bankid authority.
  2. This step is optional, but desirable. Create a folder, like /data/lib or something like that for EUSignCP C Library to store there.

    wc-bankid-nbu has a default built in binaries, but it would be better to have them in a separate folder.

    You may copy them from wc_bankid_nbu/contrib/eu_sign/linux/64 or 32 folder to your special one.

  3. Then all your scripts/server/etc. must run with an LD_LIBRARY_PATH=/data/lib environment variable set to a EUSignCP C Library folder path.

Usage

This example will be for django. But there is only a configuration, that can be easily changed for any other project.

settings.py

# Private key location path and it's password
# This must be provided:
WC_BANKID_NBU_SIGNER_PRIVATE_KEY_PATH = '/data/certificates/Key-6.dat'
WC_BANKID_NBU_SIGNER_PRIVATE_KEY_PASS = '12345677'
# This parameters are optional. The defaults for them are:
# Path to a certificates folder.
WC_BANKID_NBU_SIGNER_FILE_STORE_PATH = '/data/certificates'
# EUSignCP module, if you need a custom one.
WC_BANKID_NBU_SIGNER_MODULE = 'wc_bankid_nbu.contrib.eu_sign.EUSignCP'
# Name of the sign certificate.
WC_BANKID_NBU_SIGNER_CERTIFICATES_SIGN_NAME = 'EU-5B63D88375D92018040000002E3D0000B1950000.cer'
# Name of the distribution certificate.
WC_BANKID_NBU_SIGNER_CERTIFICATES_DISTRIBUTION_NAME = 'EU-5B63D88375D92018040000002E3D0000B2950000.cer'

Simple user data querying

from wc_bankid_nbu import (
  PersonalPhysicalDataQuery, APIClient, PersonalInfoDTO,
  TAddress, TDocument, FPerson, FAddress, FDocument,
)
# Signer settings that was resolved from django configuration.
from wc_bankid_nbu.contrib.django.conf import signer_settings
from wc_bankid_nbu import APIClient, Signer


user_data_query = (
  # Type of data query.
  PersonalPhysicalDataQuery()
  # General user fields list that we wish to get.
  .fields(
    FPerson.FIRST_NAME, FPerson.MIDDLE_NAME, FPerson.LAST_NAME,
    FPerson.BIRTH_DAY, FPerson.SEX,

    FPerson.PHONE, FPerson.EMAIL, FPerson.RNOKPP,
    FPerson.IS_HIGH_RISK, FPerson.IS_PEPS, FPerson.IS_RESTRICTED,
    FPerson.IS_TERRORIST,

    FPerson.IS_UA_RESIDENT,
  )
  # We only need an actual user's address.
  # First parameter is Type of address we need, other parameters - required
  # address fields.
  .address(
    TAddress.FACTUAL,
    FAddress.COUNTRY, FAddress.REGION, FAddress.DISTRICT, FAddress.CITY,
    FAddress.STREET, FAddress.STREET_NUMBER, FAddress.FLAT_NUMBER,
  )
  # But two documents: Passport in for of a book and international one.
  # The same principle is for a `.scans()` data.
  .document(
    TDocument.PASSPORT_BOOK,
    FDocument.NAME,
    FDocument.SERIES, FDocument.NUMBER,
    FDocument.ISSUED_BY, FDocument.ISSUED_BY_COUNTRY,
    FDocument.ISSUED_AT, FDocument.EXPIRED_AT,
  )
  .document(
    TDocument.PASSPORT_INTERNATIONAL,
    FDocument.NAME,
    FDocument.SERIES, FDocument.NUMBER,
    FDocument.ISSUED_BY, FDocument.ISSUED_BY_COUNTRY,
    FDocument.ISSUED_AT, FDocument.EXPIRED_AT,
  )
)

client = APIClient(signer=Signer(signer_settings))
data = client.get_personal_data(user_data_query, access_token)

print(data['data'])
# > User information.
print(data['certificate'])
# > Information about certificate.

Social auth backend

auth_backend.py

from functools import cached_property

from wc_bankid_nbu.contrib.social_core.backends import BankIDNBUBaseBackend
# Signer settings that was resolved from django configuration.
from wc_bankid_nbu.contrib.django.conf import signer_settings
from wc_bankid_nbu import APIClient, Signer, TestAPIClient


__all__ = "BankIDNBU",


class BankIDNBU(BankIDNBUBaseBackend):
  # User data query could be changed like so:
  # PERSONAL_DATA_QUERY = PersonalPhysicalDataQuery().fields(...)

  @cached_property
  def client(self):
    ClientClass = TestAPIClient if self.setting('DEBUG') else APIClient

    return ClientClass(signer=Signer(signer_settings))

TODO

  • [_] Social auth pipeline integrations.

Metadata

Release files for wc-bankid-nbu 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wc-bankid-nbu 0.1.4
File Size Uploaded
wc-bankid-nbu-0.1.4.tar.gz 6.1 MB Details

Release files / wc-bankid-nbu-0.1.4.tar.gz

Download URL wc-bankid-nbu-0.1.4.tar.gz
Size 6.1 MB
Tags Source
SHA-256 checksum
How to use checksums
b1eddc99ceedfd4bedd244b71ed5f7d0eb8e0254dae70f739e2b160b8d65f63c
BLAKE2b-256 checksum
How to use checksums
42e39d1e08bcecde2945004d2e944c550fe5c8bb212f89279b9572a2f01cbd49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.1.4 This release

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page