rp_python_sdk 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,414 @@
1
+ Metadata-Version: 2.1
2
+ Name: rp_python_sdk
3
+ Version: 0.3.0
4
+ Summary: Python SDK for Relying Parties to enable simple integration with the Digital Identity ecosystem
5
+ License: MIT
6
+ Author: Erik Pragt
7
+ Author-email: erik.pragt@connectid.com.au
8
+ Requires-Python: >=3.12,<4.0
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Requires-Dist: authlib (>=1.3.0,<2.0.0)
13
+ Requires-Dist: dataclass-wizard (>=0.22.3,<0.23.0)
14
+ Requires-Dist: requests (>=2.31.0,<3.0.0)
15
+ Description-Content-Type: text/markdown
16
+
17
+ # Python SDK for Relying Parties
18
+
19
+ [![rp-python-sdk](https://github.com/connectid-tools/rp-python-sdk/actions/workflows/python-app.yml/badge.svg)](https://github.com/connectid-tools/rp-python-sdk/actions/workflows/python-app.yml)
20
+
21
+ rp-python-sdk is an SDK that allows Relying Parties to easily integrate with the Digital Identity ecosystem
22
+ using the Python programming language.
23
+
24
+ # Getting Started
25
+
26
+ You will need a Python 3.12 (or greater).
27
+
28
+ - [quickstart](#quickstart)
29
+ - [pyenv/pyenv-virtualenv](#pyenvpyenv-virtualenv)
30
+ - [poetry](#poetry)
31
+ - [reference](#reference)
32
+
33
+ ## pyenv/pyenv-virtualenv
34
+
35
+ - make sure `pyenv` is installed
36
+ - make sure `pyenv-virtualenv` is installed
37
+ - install python `3.12`, for example `3.12.0`
38
+ ```bash
39
+ pyenv install 3.12.0
40
+ ```
41
+ - create a virtual environment
42
+ ```bash
43
+ pyenv virtualenv 3.12.0 rp-python-sdk
44
+ ```
45
+ - activate the virtual environment
46
+ ```bash
47
+ pyenv activate rp-python-sdk
48
+ ```
49
+ (if this fails, add the following to .zshrc):
50
+
51
+ ```bash
52
+ eval "$(pyenv init -)"
53
+ eval "$(pyenv virtualenv-init -)"
54
+ ```
55
+
56
+ - make sure `pip` and `setuptools` are up-to-date
57
+ ```bash
58
+ pip install --upgrade pip setuptools
59
+ ```
60
+
61
+ ## poetry
62
+
63
+ - install poetry
64
+ ```bash
65
+ pip install --upgrade poetry
66
+ ```
67
+ - install the application runtime dependencies
68
+ ```bash
69
+ poetry install --only main
70
+ ```
71
+ - install the application test dependencies
72
+ ```bash
73
+ poetry install --with test
74
+ ```
75
+ - install the application dev, test dependencies
76
+ ```bash
77
+ poetry install --with test,dev
78
+ ```
79
+ - install the dependencies but not the current project
80
+ ```bash
81
+ poetry install --no-root --with test,dev
82
+ ```
83
+
84
+ ## running tests
85
+
86
+ To run all the test, you can execute the following:
87
+
88
+ ```bash
89
+ poetry run pytest
90
+ ```
91
+
92
+ To run a selection of the tests, for example, run all the unit tests:
93
+
94
+ ```bash
95
+ poetry run pytest -v -m "not conformance"
96
+ ```
97
+
98
+ To only run the Conformance test, execute the following:
99
+
100
+ ```bash
101
+ poetry run pytest -v -m conformance
102
+ ```
103
+
104
+ ## pre-commit
105
+
106
+ This project use `pre-commit`. A `.pre-commit-config.yaml` is included.
107
+
108
+ Run `pre-commit install` to install the Git hooks.
109
+
110
+
111
+ ## reference
112
+
113
+ - poetry
114
+ - [Installation](https://python-poetry.org/docs/#installation)
115
+ - [Installing poetry manually](https://python-poetry.org/docs/#installing-manually)
116
+ - [Managing dependencies](https://python-poetry.org/docs/managing-dependencies/)
117
+ - pre-commit
118
+ - [Installation](https://pre-commit.com/#install)
119
+ - [Usage](https://pre-commit.com/#usage)
120
+ - [Supported hooks](https://pre-commit.com/hooks.html)
121
+
122
+ ## certificates
123
+
124
+ At the moment, there's a challenge to get the certificate loading to work well. This results in the following error:
125
+
126
+ `[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)')`
127
+
128
+ To fix this, you can run the following command:
129
+
130
+ `ln -s ~/.pyenv/versions/3.12.0/envs/python-template-3-12/lib/python3.12/site-packages/certifi/cacert.pem cert.pem`
131
+
132
+ And combine the `[connectid-sandbox-ca.pem](certs%2Fconnectid-sandbox-ca.pem)` with the `cert.pem` output.
133
+
134
+ # Process Overview Sequence Diagram
135
+
136
+ The expected interactions between the Relying Party and RP Connector as part of a standard flow are shown in the diagram below.
137
+
138
+ The key steps are:
139
+
140
+ * Retrieve the list of Participants so the user can be prompted to choose their identity provider (IDP)
141
+ * Send a Pushed Authorisation Request (PAR) to the selected IDP with the requested claims and redirect the user to their IDP
142
+ * Use the callback querystring to retrieve the access token and identity token with the claims the user has consented to share
143
+
144
+ ```mermaid
145
+ sequenceDiagram
146
+ Customer->>+Relying Party: Use Digital ID
147
+ Relying Party->>+rp-java-sdk: getParticipants()
148
+ rp-java-sdk-->>-Relying Party: Participant metadata
149
+ Relying Party-->>-Customer: Display IDP Selector
150
+ Customer->>+Relying Party: Select IDP
151
+ Relying Party->>+rp-java-sdk: sendPushedAuthorisationRequest()
152
+ rp-java-sdk-->>-Relying Party: authUrl, codeVerifier, state, nonce
153
+ Note right of Relying Party: The RP must associate the codeVerifier,<br/>state and nonce with the user<br/>to use when retrieving claims
154
+ Relying Party-->>-Customer: redirect to IDP using authUrl
155
+ Customer->>+IDP: redirect to AuthUrl
156
+ IDP->>IDP: Authenticate & Capture Consent
157
+ IDP-->>-Customer: Redirect customer to RP callback URI
158
+ Customer->>+Relying Party: redirect to callback URL
159
+ Relying Party->>+rp-java-sdk: retrievetokens()
160
+ rp-java-sdk-->>-Relying Party: access and identity tokens
161
+ Relying Party-->>-Customer: Display outcome
162
+ ```
163
+
164
+ # SDK Operations
165
+
166
+ The expected usage and key points for each of the main SDK operations is described in detail below.
167
+
168
+ ## get_participants
169
+
170
+ This allows the list of Identity Providers within the scheme to be retrieved, so that the Relying Party can display them
171
+ to the user and allow the user to choose which Identity Provider they will use to prove their identity.
172
+
173
+ Note that by default the SDK is configured to only return Identity Providers that are fully certified. If you wish to test
174
+ one of the uncertified Identity Providers you will need to set the `include_uncertified_participants` configuration
175
+ option to `true`. (This should only be done in a test environment, and should never be done in production.)
176
+
177
+ You may also set the `required_claims` and `required_participant_certifications` configuration options to filter
178
+ the list of IDPs returned based on the needs of your use case (eg: if you require IDPs to be TDIF certified).
179
+
180
+ ```python
181
+ from rp_python_sdk.relying_party_client_sdk import RelyingPartyClientSdk
182
+ from rp_python_sdk.sdk_config import SdkConfig, CustomConfig
183
+
184
+
185
+ client = RelyingPartyClientSdk(
186
+ config=SdkConfig(
187
+ signing_key="the actual signing key here",
188
+ transport_key='certs/transport.key',
189
+ transport_pem='certs/transport.pem',
190
+ signing_pem='certs/signing.pem',
191
+ ca_pem='certs/connectid-sandbox-ca-with-root-certs.pem',
192
+ application_redirect_uri='https://tpp.localhost/cb',
193
+ registry_participants_uri='https://data.directory.sandbox.connectid.com.au/participants',
194
+ client_id='https://rp.directory.sandbox.connectid.com.au/openid_relying_party/280518db-9807-4824-b080-324d94b45f6a',
195
+ signing_kid='1X8udt28NY8NiSS8OJFvabv63K5igyFx5pM5ajKlMx8',
196
+ custom_config=CustomConfig(
197
+ enable_auto_compliance_verification=False
198
+ )
199
+ ),
200
+ )
201
+
202
+ participants = client.get_participants()
203
+ ```
204
+
205
+ The response will contain List of Organisations and their Authorisation Server, with an object structure similar to below.
206
+
207
+ They key fields of interest are:
208
+
209
+ * `CustomerFriendlyName` - this is the name of the Bank to display to the customer
210
+ * `CustomerFriendlyLogoUri` - this is a logo for the Bank that can be displayed alongside the bank name
211
+ * `AuthorisationServerId` - this uniquely identifies the authorisation server. It will be needed as part of the next call
212
+ in the flow to identify the Authorisation Server to send the PAR to.
213
+
214
+ Note that in the response there may be:
215
+
216
+ * multiple organisations - each Bank will be its own organisation
217
+ * multiple authorisation servers per bank - a Bank may have different authorisation servers for its different brands (or potentially
218
+ to differentiate Business Banking from Retail Banking).
219
+
220
+ <!--
221
+ TO DO: Suggest further instructions such as: The IDP selector needs to present all authorisation servers from all active organisations (status='Active')
222
+ -->
223
+
224
+ ```json
225
+ [
226
+ {
227
+ "Status": "Active",
228
+ "OrgDomainRoleClaims": [],
229
+ "AuthorisationServers": [
230
+ {
231
+ "PayloadSigningCertLocationUri": "https://auth.bank4.directory.sandbox.connectid.com.au/na",
232
+ "ParentAuthorisationServerId": null,
233
+ "OpenIDDiscoveryDocument": "https://auth.bank4.directory.sandbox.connectid.com.au/.well-known/openid-configuration",
234
+ "CustomerFriendlyName": "Bank W",
235
+ "CustomerFriendlyDescription": "Bank4",
236
+ "TermsOfServiceUri": null,
237
+ "ApiResources": [],
238
+ "AutoRegistrationSupported": true,
239
+ "CustomerFriendlyLogoUri": "https://static.relyingparty.net/BankW.svg",
240
+ "SupportsDCR": false,
241
+ "AuthorisationServerCertifications": [],
242
+ "SupportsCiba": false,
243
+ "DeveloperPortalUri": null,
244
+ "NotificationWebhookAddedDate": null,
245
+ "AuthorisationServerId": "cde44c30-9138-4b58-ba50-221833d14319"
246
+ },
247
+ {
248
+ "PayloadSigningCertLocationUri": "https://auth.bank3.directory.sandbox.connectid.com.au/na",
249
+ "ParentAuthorisationServerId": null,
250
+ "OpenIDDiscoveryDocument": "https://auth.bank3.directory.sandbox.connectid.com.au/.well-known/openid-configuration",
251
+ "CustomerFriendlyName": "Bank N",
252
+ "CustomerFriendlyDescription": "Bank3",
253
+ "TermsOfServiceUri": null,
254
+ "ApiResources": [],
255
+ "AutoRegistrationSupported": true,
256
+ "CustomerFriendlyLogoUri": "https://static.relyingparty.net/BankN.svg",
257
+ "SupportsDCR": false,
258
+ "AuthorisationServerCertifications": [],
259
+ "SupportsCiba": false,
260
+ "DeveloperPortalUri": null,
261
+ "NotificationWebhookAddedDate": null,
262
+ "AuthorisationServerId": "22c2d67e-4d95-414a-b51a-ca863e9d691d"
263
+ }
264
+ ],
265
+ "OrgDomainClaims": [],
266
+ "Size": null,
267
+ "RegistrationId": null,
268
+ "OrganisationId": "ed63c5b4-4dcb-4867-bd8b-e2b04a0ab04b",
269
+ "City": "Banksville",
270
+ "Postcode": "4103",
271
+ "AddressLine2": "Bank Town",
272
+ "RegisteredName": "RefBank",
273
+ "AddressLine1": "1 Reference Bank Street",
274
+ "LegalEntityName": "Reference Bank",
275
+ "OrganisationName": "Reference Banks",
276
+ "Country": "AU",
277
+ "RegistrationNumber": "ABN 123 456 7890",
278
+ "CreatedOn": "2021-12-14T23:09:03.581Z",
279
+ "Tag": null,
280
+ "ParentOrganisationReference": "",
281
+ "CompanyRegister": "ABN",
282
+ "CountryOfRegistration": "AU"
283
+ },
284
+ {
285
+ "Status": "Active",
286
+ "OrgDomainRoleClaims": [],
287
+ "AuthorisationServers": [
288
+ {
289
+ "PayloadSigningCertLocationUri": "https://mtls.partner.idp.test.commbank.com.au/pf/JWKS",
290
+ "ParentAuthorisationServerId": null,
291
+ "OpenIDDiscoveryDocument": "https://mtls.partner.idp.test.commbank.com.au/.well-known/openid-configuration",
292
+ "CustomerFriendlyName": "Commonwealth Bank",
293
+ "CustomerFriendlyDescription": "Test IDP for CBA",
294
+ "TermsOfServiceUri": null,
295
+ "ApiResources": [],
296
+ "AutoRegistrationSupported": true,
297
+ "CustomerFriendlyLogoUri": "https://www.commbank.com.au/test.svg",
298
+ "SupportsDCR": false,
299
+ "AuthorisationServerCertifications": [],
300
+ "SupportsCiba": false,
301
+ "DeveloperPortalUri": null,
302
+ "NotificationWebhookAddedDate": null,
303
+ "AuthorisationServerId": "355df9aa-bf8f-4cec-aa4d-78b10356762e"
304
+ }
305
+ ],
306
+ "OrgDomainClaims": [],
307
+ "Size": null,
308
+ "RegistrationId": "",
309
+ "OrganisationId": "adf2af89-2782-4058-86d9-ff3a9068e4a5",
310
+ "City": "Sydney",
311
+ "Postcode": "2000",
312
+ "AddressLine2": "201 Sussex Street",
313
+ "RegisteredName": "Commonwealth Bank of Australia",
314
+ "AddressLine1": "Ground Floor Tower 1",
315
+ "LegalEntityName": "Commonwealth Bank of Australia",
316
+ "OrganisationName": "Commonwealth Bank of Australia",
317
+ "Country": "AU",
318
+ "RegistrationNumber": "ABN 48 123 123 124",
319
+ "CreatedOn": "2022-03-14T00:42:29.202Z",
320
+ "Tag": null,
321
+ "ParentOrganisationReference": "",
322
+ "CompanyRegister": "ABN",
323
+ "CountryOfRegistration": "AU"
324
+ }
325
+ ]
326
+ ```
327
+
328
+ ## get_fallback_provider_participants()
329
+
330
+ This allows the list of Fallback Identity Providers (ie: manual document based verification) within the scheme to be retrieved,
331
+ so that the Relying Party can use them as a fallback option if the user does not have a relationship
332
+ with one of the identity providers. Note that there is only expected to be a single Fallback Provider authorisation
333
+ server for the Scheme.
334
+
335
+ It is expected that clients will only use this method if they are building their own IDP selector and need to
336
+ identify the scheme Fallback Identity Provider.
337
+
338
+ Note that there is only expected to be a single Fallback Provider for the scheme (so only one participant with one
339
+ auth server should be returned here).
340
+
341
+ ```python
342
+ participants = client.get_fallback_provider_participants()
343
+ ```
344
+
345
+ The response will contain a list of Organisations and their Authorisation Servers, with the same return type as for `get_participants()`.
346
+
347
+ ## send_pushed_authorisation_request(authorisation_server_id, essential_claims, voluntary_claims, purpose)
348
+
349
+ This sends a Pushed Authorisation Request to the specified Identity Server requesting the list of supplied claims.
350
+ `send_pushed_authorisation_request(authorisation_server_id)` requests a default list of essential claims:
351
+ `"name", "given_name", "middle_name", "family_name", "phone_number", "email", "address", "birthdate", "txn"`.
352
+ The response will include the `authUrl` which is the URL that the user needs to be redirected to, so they can complete the authorisation process.
353
+
354
+ Function parameters are:
355
+
356
+ * `authorisationServerId` - identifies the authorisation server to send the PAR to
357
+ * `essentialClaims` - a set of the essential identity claim names that are to be retrieved for the user. Note that permitted claim names
358
+ are defined in section 6 of the [Digital ID Identity Assurance Profile](https://docs.sandbox.connectid.com.au/docs/network-documentation/technical-specifications/) specification.
359
+ * `voluntaryClaims` - a set of the voluntary identity claim names that are to be retrieved for the user. Note that permitted claim names
360
+ are defined in section 6 of the [Digital ID Identity Assurance Profile](https://docs.sandbox.connectid.com.au/docs/network-documentation/technical-specifications/) specification.
361
+ * `purpose` - the purpose to be displayed to the consumer on the IDP consent screen to indicate why their data is being requested to be shared. If not supplied, the default purpose configured in the SDK config will be used.
362
+
363
+ The method will return a `PARResponse` with properties for: `authUrl`, `code_verifier`, `state`, `nonce`, `xFapiInteractionId`. The properties represent:
364
+
365
+ * `authUrl` - the URL that the user agent must be redirected to in order to complete the authorisation process with their Identity Provider
366
+ * `xFapiInteractionId` - a unique identifier for this interaction with the Authorisation Server, that was sent in the `x-fapi-interaction-id` request
367
+ header to the server. Intended as a correlation id for diagnosing issues between the client and the authorisation server.
368
+
369
+ The `codeVerifier`, `state` and `nonce` are all associated with this specific PAR and are required when retrieving the
370
+ token claims when the user has authorised the request. You must securely associate these with your user request
371
+ so that you can use them on the subsequent call.
372
+
373
+ ## retrieve_tokens(authorisation_server_id, callback_queries, code_verifier, state, nonce)
374
+
375
+ This retrieves the access and identity token containing the claims that the user has consented to share with the
376
+ Relying Party. It uses the authorisation code provided in the callback from the IDP and exchanges this for the access and
377
+ identity token with the claims. The tokens are then returned to the API caller.
378
+
379
+ The required function parameters are:
380
+
381
+ * `authorisationServerId` - identifies the authorisation server providing the user information
382
+ * `callbackQueries` - a `CallbackBody` that contains the query string parameters returned in the callback from the Authorisation Server
383
+ * `codeVerifier` - from the response to the PAR for this identity request
384
+ * `state` - from the response to the PAR for this identity request
385
+ * `nonce` - from the response to the PAR for this identity request
386
+
387
+ The method will return a `Tokenset` that contains the access_token and id_token with the requested claims along
388
+ with a unique `x-fapi-interaction-id` that was used for this request to the authorisation server.
389
+
390
+ ## Conformance test
391
+
392
+ An automated conformance test has been added. To execute the conformance test, a token is required,
393
+ which can be created on the [OpenID Foundation conformance suite](https://www.certification.openid.net/tokens.html) page.
394
+
395
+ This token needs to be set as an environment variable named `CONFORMANCE_API_TOKEN`, for example:
396
+
397
+ ```bash
398
+ export CONFORMANCE_API_TOKEN=<token here>
399
+ ```
400
+
401
+ After this, running `poetry run pytest -v -m conformance` will run the conformance test, and produce a test report.
402
+
403
+ The test results are also available on GitHub after a successful merge to the main branch.
404
+
405
+ ## Release Notes
406
+
407
+ ### 0.3.0 (April 5, 2024)
408
+ - Added participant / auth server filtering
409
+
410
+ ### 0.2.0 (March 30, 2024)
411
+ - Implemented all endpoints
412
+
413
+ ### 0.1.0 (March 27, 2024)
414
+ - Initial version
@@ -0,0 +1,16 @@
1
+ rp_python_sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ rp_python_sdk/endpoints/get_participants.py,sha256=AexSjIIpUR337Tzrdk24Tr_4te3FVsyEc5K94n-Br-Q,4862
3
+ rp_python_sdk/endpoints/pushed_authorisation_request.py,sha256=A4sh5y1Io7o0Sq3LfU8gTQyZNnSwTwfc2Zfl3UazL5o,7820
4
+ rp_python_sdk/endpoints/retrieve_tokens.py,sha256=VEu4YDrDK3l2dFHmvPNmoP-JOKGYEFBDIHEvSsBvaKY,10371
5
+ rp_python_sdk/endpoints/user_info.py,sha256=OklfukQK8JlN6XTIECGSwQifMyCQhcy1aBr-Zdy2NQs,1745
6
+ rp_python_sdk/endpoints/util/fapi.py,sha256=Ig5hGTaADuC8xSDXlrApDByFhFcED7mk9QRhAYWRfbE,1234
7
+ rp_python_sdk/filters/participant_filters.py,sha256=tICb7KRC1GfBZsMif0tYOmMD0ezX5Gj74xZRcVQJ_6I,4646
8
+ rp_python_sdk/model.py,sha256=ossWahCzBG_MLs_GDq4lh0tBK2xgPkmZweGBsag6tXI,3763
9
+ rp_python_sdk/relying_party_client_sdk.py,sha256=cDO5SkPMBvLZLRAEfU4UaExFMflTeMOG5VQfkDrRz1c,2227
10
+ rp_python_sdk/relying_party_client_sdk_exception.py,sha256=oODQi4wo3lSY3IXXVd6AZl_HLcBCg3ibu_a_MSPyXQU,58
11
+ rp_python_sdk/sdk_config.py,sha256=DYz4ZzT3Af96CWDJmtsUY2T27tQ8kIxYYhypUKhCgaI,2759
12
+ rp_python_sdk/setup_logger.py,sha256=YGcGEc_C2AR3YPCTxav53oQ2SdBUiVD4FzM_w0UXZMA,346
13
+ rp_python_sdk-0.3.0.dist-info/LICENSE,sha256=eBxSWT9nCsY1PWnwgPcAYvvW0RBVbC18FiHmVVnonYQ,1069
14
+ rp_python_sdk-0.3.0.dist-info/METADATA,sha256=uXmqsHv_u1KPLR0fFETLeKX9PYiRADHIlXk5AfMHPrw,17640
15
+ rp_python_sdk-0.3.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
16
+ rp_python_sdk-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 1.9.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any