Skip to content
Scalekit Docs
Talk to an EngineerDashboard

Create client

Create the SDK client and run core auth helpers

Create a ScalekitClient with your environment URL, client ID, and client secret. All other clients hang off this instance.

Store credentials in environment variables. Never hard-code secrets. After you create the client, use Sessions to work with sessions or open a domain client such as Organizations or Users.

classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-python/blob/main/scalekit/client.py
#asyncget_authorization_url

Method to get authorization URL

paramredirect_uristr

Redirect URI for SAML SSO

paramoptionsAuthorizationUrlOptions | None

Auth URL options object

returnsNone

Authorization URL

import secrets
from scalekit import AuthorizationUrlOptions
# Security: generate a per-login OAuth state and store it in the session.
# Comparing the returned state on callback prevents login CSRF.
options = AuthorizationUrlOptions()
options.state = secrets.token_urlsafe(32)
options.organization_id = 'org_123456'
# request.session['oauth_state'] = options.state
auth_url = scalekit_client.get_authorization_url(
'https://yourapp.com/auth/callback',
options
)
# Redirect user to auth_url
classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-python/blob/main/scalekit/client.py
#asyncauthenticate_with_code

Method to authenticate with code options

paramcodeAny

authorization_code

paramredirect_uriAny

Redirect URI

paramoptionsCodeAuthenticationOptions

CodeAuthenticationOptions Object

returnsNone

Tokens and claims.

from scalekit import ScalekitClient
@app.get('/auth/callback')
async def auth_callback(request):
code = request.query_params.get('code')
state = request.query_params.get('state')
# Security: reject the callback if state does not match the session value.
if state != request.session.get('oauth_state'):
return {'error': 'invalid state'}, 400
result = scalekit_client.authenticate_with_code(
code,
'https://yourapp.com/auth/callback'
)
request.session['access_token'] = result['access_token']
request.session['user'] = result['user']
return RedirectResponse('/dashboard')
classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-python/blob/main/scalekit/client.py
#asyncget_idp_initiated_login_claims

Method to get IDP initiated login claims

paramidp_initiated_login_tokenstr

IDP initiated login token

paramoptionsOptional[TokenValidationOptions]

Optional request settings.

paramaudienceAny

Token audience.

returnsIdpInitiatedLoginClaims

IdpInitiatedLoginClaims

@app.get('/auth/callback')
async def auth_callback(request):
idp_initiated_login = request.query_params.get('idp_initiated_login')
if idp_initiated_login:
claims = scalekit_client.get_idp_initiated_login_claims(idp_initiated_login)
options = AuthorizationUrlOptions()
options.connection_id = claims['connection_id']
options.organization_id = claims['organization_id']
options.login_hint = claims.get('login_hint')
if claims.get('relay_state'):
options.state = claims['relay_state']
auth_url = scalekit_client.get_authorization_url(
'https://yourapp.com/auth/callback',
options
)
return RedirectResponse(auth_url)
classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-python/blob/main/scalekit/client.py
#asyncvalidate_access_token

Method to validate access token

paramtokenstr

access token

paramoptionsOptional[TokenValidationOptions]

Optional request settings.

paramaudienceAny

Token audience.

returnsbool

bool

is_valid = scalekit_client.validate_access_token(token)
if is_valid:
# Token is valid, proceed with request
pass
classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-python/blob/main/scalekit/client.py
#asyncget_logout_url

Method to get logout URL

paramoptionsLogoutUrlOptions

Logout URL options object

returnsstr

str: The logout URL

options = LogoutUrlOptions()
options.post_logout_redirect_uri = 'https://example.com'
options.state = 'some-state'
logout_url = scalekit_client.get_logout_url(options)
classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-python/blob/main/scalekit/client.py
#asyncverify_webhook_payload

Method to verify webhook payload

paramsecretstr

Secret for webhook verification

paramheadersDict[str, str]

Webhook request headers

parampayloadstr | bytes

Webhook payload in str or bytes

returnsbool

bool

import os
@app.post('/webhooks')
async def webhook_handler(request):
payload = await request.body()
headers = dict(request.headers)
# Security: load the webhook secret from configuration — never hard-code it.
# Skipping signature verification accepts forged webhook payloads as legitimate.
secret = os.environ['SCALEKIT_WEBHOOK_SECRET']
is_valid = scalekit_client.verify_webhook_payload(secret, headers, payload)
if not is_valid:
return {'error': 'invalid signature'}, 401
# Process verified webhook
return {'ok': True}
classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-python/blob/main/scalekit/client.py
#asyncrefresh_access_token

Method to refresh access token using refresh token

paramrefresh_tokenstr

Refresh token to get new access token

returnsNone

dict with access token & refresh token

result = scalekit_client.refresh_access_token(refresh_token)
new_access_token = result['access_token']
new_refresh_token = result['refresh_token']
classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-python/blob/main/scalekit/client.py
#asyncgenerate_client_token

Method to generate access token

paramclient_idstr

Client Id for access token

paramclient_secretstr

Client Secret for access token

paramscopesOptional[list[str]]

OAuth scopes.

returnsstr

access token

classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-python/blob/main/scalekit/client.py
#asyncget_client_access_token

Method to generate an access token using the stored client credentials.

returnsstr

access token string

classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-python/blob/main/scalekit/client.py
#asyncvalidate_access_token_and_get_claims

Method to validate access token and get claims

paramtokenstr

access token

paramoptionsOptional[TokenValidationOptions]

Optional request settings.

paramaudienceAny

Token audience.

returnsDict[str, Any]

claims

classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-python/blob/main/scalekit/client.py
#asyncvalidate_token

Method to validate token

paramtokenstr

token

paramoptionsOptional[TokenValidationOptions]

Optional request settings.

paramaudienceOptional[str]

Optional. audience for validation

returnsDict[str, Any]

payload

classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-python/blob/main/scalekit/client.py
#asyncverify_scopes

Verify that the token contains the required scopes

paramtokenstr

The token to verify

paramrequired_scopeslist[str]

The scopes that must be present in the token

returnsbool

bool: Returns True if all required scopes are present

classScalekitClienthttps://github.com/scalekit-inc/scalekit-sdk-python/blob/main/scalekit/client.py
#asyncverify_interceptor_payload

Method to verify interceptor payload using common verification logic

paramsecretstr

Secret for interceptor verification

paramheadersDict[str, str]

Headers.

parampayloadstr | bytes

Interceptor payload in str or bytes

returnsbool

bool