Skip to main content

Python client library for ID4me protocol - Relying Party side. See:

Project description


Python Relying Party client library for ID4me protocol. For details of the protocol, please visit:

Library offers Relying Party functionality for authentication with Identity Authority and claim request from the Identity Agent..

Specification reference

  • Version: 1.0
  • Revision: 02


pip install id4me-rp-client


Register the client and authorize with Identity Authority

from id4me_rp_client import *

# these imports are just needed in this example
from builtins import input
import json

registrations = dict()

# a routine to save client registration at authority
def save_authority_registration(auth_name, auth_content):
    registrations[auth_name] = auth_content

# a routine to load client registration at authority
def load_authority_registration(auth_name):
    return registrations[auth_name]

# create client object with basic parameters of your app
client = ID4meClient(
    client_name='Foo app',

    # make a discovery of identity authority and register if needed
    # find_authority and save_authority are optional, but when missing client will be registered each time anew
    ctx = client.get_rp_context(

    # get a link to login routine
    link = client.get_consent_url(
       ID4meClaimRequestProperties(reason='To call you by name'),
       ID4meClaimRequestProperties(essential=True, reason='To be able to contact you'),
                OIDCClaim.email_verified: ID4meClaimRequestProperties(reason='To know if your E-mail was verified'),
    print('Please open the link:\n{}'.format(link))

    # Normally code will arrive as query param on client.validateUrl
    code = input('Please enter code: ')
    # Get ID token
    client.get_idtoken(context=ctx, code=code)
    # Get User Info
    userinfo = client.get_user_info(context=ctx)
    print('User Info:\n{}'.format(json.dumps(userinfo, sort_keys=True, indent=4)))    
except ID4meException as e:
    print('Exception: {}'.format(e))


Resolving ""
Checking TXT record "v=OID1;;"
identity_authority =
registering with new identity authority (
destination =
Please open the link:
Please enter code: >? 9jNXCX9OZ4HQLr2YZWKisw.5mSDkoR-5YJQoTp3f1vuxg
User Info:
    "aud": "hmkzay2riyon4", 
    "email": "", 
    "email_verified": true, 
    "exp": 1538762218, 
    "iat": 1538761918, 
    "id4me.identifier": "", 
    "id4me.identity": "", 
    "iss": "", 
    "nbf": 1538761918, 
    "sub": "uiw3pTRRLVaKJqbnbSwr4EVuhEPTHvRgci91RbhYU2rab/YVDqDmqTKzTVAdDMm+", 
    "updated_at": 1538564738

Requesting custom claims

In order to request a custom claim, it's enough to pass its name as a key in userinfo_claims or id_token_claims parameters of ID4meClient.get_consent_url method.


        link = client.get_consent_url(
           ID4meClaimRequestProperties(essential=True, reason='Test other confusing reason'),
                    'id4me.custom': ID4meClaimRequestProperties(essential=True, reason='Custom claim reason')


version date changes
0.0.15 2019-02-27 - NEW FEATURE: Automatically re-register expired client registration
- explicit parameter to enable/block automatic client registration
0.0.14 2019-02-25 No functional changes. Example code in README fixed
0.0.13 2019-02-25 No functional changes. TEST & EXAMPLE for custom claims added
0.0.12 2019-02-21 BUGFIX: Exception when no encryption used but private key missing
0.0.11 2019-02-21 BUGFIX, error when serializing ID4meContext
0.0.10 2019-02-18 API BREAKING CHANGE: client configuration loading callback moved to client object in order to remove secret data from the ID4meContext which can be in some frameworks sent over cookies

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for id4me-rp-client, version 0.0.15
Filename, size File type Python version Upload date Hashes
Filename, size id4me_rp_client-0.0.15-py2.py3-none-any.whl (16.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size id4me-rp-client-0.0.15.tar.gz (16.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page