Skip to main content

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-abstractions
  • microsoft-kiota-http
  • microsoft-kiota-serialization-json
  • microsoft-kiota-serialization-text
  • microsoft-kiota-serialization-form
  • microsoft-kiota-serialization-multipart
  • httpx

Documentation

License

This project is licensed under the MIT License.

Project details


Download files

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

Source Distribution

adsk_platform_authentication-0.2.10.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

adsk_platform_authentication-0.2.10-py3-none-any.whl (42.1 kB view details)

Uploaded Python 3

File details

Details for the file adsk_platform_authentication-0.2.10.tar.gz.

File metadata

File hashes

Hashes for adsk_platform_authentication-0.2.10.tar.gz
Algorithm Hash digest
SHA256 e8831255e7ac01332c9998687b75ed0be18ef2f384b3d83dee527817ef9c0fda
MD5 b0437160b4c36961708a823c33a359b0
BLAKE2b-256 0caafc4c0791f08a95781231ad6ef6f01e66e530f1bcb169ccf56056a1b5b5c5

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file adsk_platform_authentication-0.2.10-py3-none-any.whl.

File metadata

File hashes

Hashes for adsk_platform_authentication-0.2.10-py3-none-any.whl
Algorithm Hash digest
SHA256 8f56b481072d98ddd430a18337f9d30c4c18137b7b8856c581fc00f196bd46e5
MD5 3e5b5bddc71766b557a777e59beee348
BLAKE2b-256 7ed50a70621b4d48277694691c14a8d81ea7c0c9a14242f3c6c40cd79324b438

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page