Autodesk Platform: Authentication SDK for Python
Project description
autodesk-authentication - Autodesk Authentication SDK for Python
A Python SDK providing a Fluent API for the Autodesk Authentication APIs, generated from the official OpenAPI specifications using Microsoft Kiota.
Installation
pip install adsk-platform-authentication
Quick Start
from autodesk_authentication import AuthenticationClient
# Initialize the Authentication client
auth_client = AuthenticationClient()
2-Legged Token (Client Credentials)
import os
from autodesk_authentication import AuthenticationClient
client_id = os.environ["APS_CLIENT_ID"]
client_secret = os.environ["APS_CLIENT_SECRET"]
auth_client = AuthenticationClient()
token = await auth_client.helper.get_two_legged_token(
client_id,
client_secret,
scopes=["data:read", "data:write", "account:read"],
)
print(f"Access Token: {token.access_token}")
print(f"Expires At: {token.expires_at}")
Auto-Refreshing Token
from autodesk_authentication import AuthenticationClient, InMemoryTokenStore
auth_client = AuthenticationClient()
token_store = InMemoryTokenStore()
get_token = auth_client.helper.create_two_legged_auto_refresh_token(
client_id,
client_secret,
scopes=["data:read", "data:write"],
token_store=token_store,
)
# This callable auto-refreshes when the token is about to expire
access_token = await get_token()
Using Scope Enum
from autodesk_authentication import AuthenticationClient, AuthenticationScope
auth_client = AuthenticationClient()
token = await auth_client.helper.get_two_legged_token(
client_id,
client_secret,
scopes=[AuthenticationScope.DATA_READ, AuthenticationScope.ACCOUNT_READ],
)
3-Legged Authentication (Authorization Code)
from autodesk_authentication import AuthenticationClient, AuthenticationClientHelper, AuthenticationScope
# Step 1: Generate the login URL
login_url = AuthenticationClientHelper.create_authentication_url(
client_id=client_id,
redirect_uri="http://localhost:3000/callback",
scope=[AuthenticationScope.DATA_READ, AuthenticationScope.VIEWABLES_READ],
)
print(f"Open this URL in a browser: {login_url}")
# Step 2: Extract the code from the callback URL
code = AuthenticationClientHelper.extract_code_from_url(callback_url)
3-Legged with PKCE
from autodesk_authentication import AuthenticationClientHelper, AuthenticationScope
# Generate PKCE challenge
code_verifier, code_challenge = AuthenticationClientHelper.create_pkce_code_challenge()
# Build the PKCE login URL
login_url = AuthenticationClientHelper.create_pkce_authentication_url(
client_id=client_id,
redirect_uri="http://localhost:3000/callback",
scope=[AuthenticationScope.DATA_READ],
code_challenge=code_challenge,
)
Refresh a 3-Legged Token
auth_client = AuthenticationClient()
refreshed = await auth_client.helper.refresh_three_legged_token(
client_id=client_id,
client_secret=client_secret,
refresh_token="REFRESH_TOKEN_FROM_PREVIOUS_AUTH",
)
print(f"New access token: {refreshed.access_token}")
Get User Info
auth_client = AuthenticationClient()
user_info = await auth_client.helper.get_user_info(three_legged_token="YOUR_3L_TOKEN")
print(f"Name: {user_info.name}, Email: {user_info.email}")
Using the .api Property
The full generated API surface is accessible via auth_client.api:
# Direct API call (equivalent to what .helper methods do internally)
from autodesk_authentication.generated_code.authentication.v2.token.token_post_request_body import (
TokenPostRequestBody,
)
from autodesk_authentication.generated_code.models.granttype import Granttype
body = TokenPostRequestBody()
body.grant_type = Granttype.Client_credentials
body.scope = "data:read"
result = await auth_client.api.authentication.v2.token.post(
body,
request_configuration=lambda r: r.headers.add("Authorization", auth_string),
)
Custom HTTP Client
You can provide your own httpx.AsyncClient instance:
import httpx
http_client = httpx.AsyncClient(timeout=60.0)
auth_client = AuthenticationClient(http_client=http_client)
Error Handling
from kiota_abstractions.api_error import APIError
try:
token = await auth_client.helper.get_two_legged_token(client_id, client_secret, scopes)
except APIError as e:
print(f"Request failed: {e.message}")
print(f"Status code: {e.response_status_code}")
Requirements
- Python 3.10 or later
- Valid Autodesk Platform Services (APS) application credentials
Dependencies
microsoft-kiota-abstractionsmicrosoft-kiota-httpmicrosoft-kiota-serialization-jsonmicrosoft-kiota-serialization-textmicrosoft-kiota-serialization-formmicrosoft-kiota-serialization-multiparthttpx
Documentation
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file adsk_platform_authentication-0.2.10.tar.gz.
File metadata
- Download URL: adsk_platform_authentication-0.2.10.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8831255e7ac01332c9998687b75ed0be18ef2f384b3d83dee527817ef9c0fda
|
|
| MD5 |
b0437160b4c36961708a823c33a359b0
|
|
| BLAKE2b-256 |
0caafc4c0791f08a95781231ad6ef6f01e66e530f1bcb169ccf56056a1b5b5c5
|
Provenance
The following attestation bundles were made for adsk_platform_authentication-0.2.10.tar.gz:
Publisher:
publishPyPi.yml on adsk-duszykf/Adsk.Platform.Toolkit.Python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
adsk_platform_authentication-0.2.10.tar.gz -
Subject digest:
e8831255e7ac01332c9998687b75ed0be18ef2f384b3d83dee527817ef9c0fda - Sigstore transparency entry: 979983610
- Sigstore integration time:
-
Permalink:
adsk-duszykf/Adsk.Platform.Toolkit.Python@22fa158425f9f5214f5d3194a0b2916a650ef050 -
Branch / Tag:
refs/tags/v0.2.10 - Owner: https://github.com/adsk-duszykf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publishPyPi.yml@22fa158425f9f5214f5d3194a0b2916a650ef050 -
Trigger Event:
push
-
Statement type:
File details
Details for the file adsk_platform_authentication-0.2.10-py3-none-any.whl.
File metadata
- Download URL: adsk_platform_authentication-0.2.10-py3-none-any.whl
- Upload date:
- Size: 42.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f56b481072d98ddd430a18337f9d30c4c18137b7b8856c581fc00f196bd46e5
|
|
| MD5 |
3e5b5bddc71766b557a777e59beee348
|
|
| BLAKE2b-256 |
7ed50a70621b4d48277694691c14a8d81ea7c0c9a14242f3c6c40cd79324b438
|
Provenance
The following attestation bundles were made for adsk_platform_authentication-0.2.10-py3-none-any.whl:
Publisher:
publishPyPi.yml on adsk-duszykf/Adsk.Platform.Toolkit.Python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
adsk_platform_authentication-0.2.10-py3-none-any.whl -
Subject digest:
8f56b481072d98ddd430a18337f9d30c4c18137b7b8856c581fc00f196bd46e5 - Sigstore transparency entry: 979983644
- Sigstore integration time:
-
Permalink:
adsk-duszykf/Adsk.Platform.Toolkit.Python@22fa158425f9f5214f5d3194a0b2916a650ef050 -
Branch / Tag:
refs/tags/v0.2.10 - Owner: https://github.com/adsk-duszykf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publishPyPi.yml@22fa158425f9f5214f5d3194a0b2916a650ef050 -
Trigger Event:
push
-
Statement type: