Skip to main content

Palantir OAuth Client

A library for performing OAuth2 authentication with Multipass in order to obtain credentials for querying Foundry APIs.

This library supports two modes of operation for the Authorization code OAuth2 flow:

  1. Command line prompt: A user will be prompted to navigate to Foundry and enter the resulting authorization_code in their console after successful authentication.

  2. Local webserver: A local webserver will be created to receive the redirect after successful authentication. The token exchange will be performed automatically.

If the offline_access scope is specified, the credential will additionally contain a refresh token. When loading cached credentials (see below), the refresh token will be used to update invalid or expired credentials. In the case credentials cannot be obtained the user will be prompted to log in as above.

Usage

Use the palantir_oauth_client.get_user_credentials() function to authenticate to Foundry APIs.

import requests
from palantir_oauth_client import get_user_credentials

hostname = "127.0.0.1:8080"
client_id = "f5496be223e4db85c6a7c99bc5c2d81a"
credentials = get_user_credentials(["offline_access"], hostname, client_id)

headers = {"Authorization": "Bearer " + credentials.token}
response = requests.get(f"https://{hostname}/multipass/api/me", headers=headers)
print("Hello, {}!".format(response.json().get("username")))

Client Registration

A third-party client application needs to have been created in Multipass and the client_id provided when calling palantir_oauth_client.get_user_credentials(). This client should be registered as a Public client (native or single-page application) when it is not possible to securely store the client_secret. The library uses the PKCE OAuth2 extension for all requests regardless of the type of client that has been registered.

The following redirect URIs should use be specified for each mode of operation:

  1. Command line prompt: https://<hostname>/multipass/api/oauth2/callback

  2. Local webserver: http://127.0.0.1/

Caching

When obtaining credentials using palantir_oauth_client.get_user_credentials() you may specify a palantir_oauth_client.cache.CredentialsCache. There are three implementations:

  1. palantir_oauth_client.cache.READ_WRITE (default): A read-write cache that will persist credentials to disk when offline_access scope is requested. The cached refresh tokens will be used when obtaining credentials where possible to avoid explicit re-authentication.

  2. palantir_oauth_client.cache.REAUTH: A write-only cache that will persist credentials to disk when offline_access scope is requested but will require reauthentication when obtaining credentials.

  3. palantir_oauth_client.cache.NOOP: Always requires reauthentication and never persists credentials to disk.

Persisted credentials will be stored in the default user home directory at ~/.foundry/oauth. Caching should only be used when this home directory is secure and inaccessible by other users who would not otherwise have access to the Foundry credentials.

Contributing

See the CONTRIBUTING.md document. Releases are published to pypi on tag builds and are automatically re-published to conda using conda-forge.

License

This project is made available under the Apache 2.0 License.

Metadata

Release files for palantir-oauth-client 1.6.1

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

Source distribution (sdist)

Source distribution for palantir-oauth-client 1.6.1
File Size Uploaded Provenance Actions
palantir-oauth-client-1.6.1.tar.gz 17.1 kB Without provenance Details for palantir-oauth-client-1.6.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for palantir-oauth-client 1.6.1
File Interpreter ABI Platform Actions
palantir_oauth_client-1.6.1-py3-none-any.whl Python 3 none any Details for palantir_oauth_client-1.6.1-py3-none-any.whl

Total release size: 39.1 kB

Release files / palantir-oauth-client-1.6.1.tar.gz

Download URL palantir-oauth-client-1.6.1.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
113241cb334bc19b2b5c17ad0a350ed32ba766d74155b1d074e68351e485538b
BLAKE2b-256 checksum
How to use checksums
ffc42416181b36c5a6e513bbdd97db1001ad9f60369a5ee45ca7d9f328296d2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.10.2 Linux/5.15.0-1056-aws

Release files / palantir_oauth_client-1.6.1-py3-none-any.whl

Download URL palantir_oauth_client-1.6.1-py3-none-any.whl
Size 22.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9bb52919b0f141e8a36d677a45d32331dc22d4b1a1d7e5452ea836f66e4a0655
BLAKE2b-256 checksum
How to use checksums
f030a56e2af8ced5390dc57bccfc502ddaf1f1993d2a2b840973c853d4b658b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.10.2 Linux/5.15.0-1056-aws

Security for palantir-oauth-client 1.6.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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