Skip to content
Scalekit Docs
Talk to an Engineer Dashboard

Authorize a user

Generate an authorization link, send it to your user, and confirm their connected account is active before your agent executes tools.

Once a connection is configured, your users need to grant your agent access to their account. This happens once per user per connection. Scalekit stores their tokens and keeps them fresh automatically.

The flow is:

  1. Create a connected account for the user
  2. Generate an authorization link and send it to the user
  3. The user completes the OAuth consent screen
  4. The connected account becomes ACTIVE. Your agent can now execute tools.
Section titled “Create a connected account and generate a link”
# Create or retrieve the connected account for this user
response = actions.get_or_create_connected_account(
connection_name="gmail",
identifier="user_123" # your app's unique user ID
)
connected_account = response.connected_account
# Generate the authorization link if the account is not yet active
if connected_account.status != "ACTIVE":
link_response = actions.get_authorization_link(
connection_name="gmail",
identifier="user_123"
)
auth_url = link_response.link
# Redirect or send auth_url to the user

How you deliver the link depends on your application:

  • Web app: redirect the user to auth_url directly if they’re in an active browser session
  • Email or notification: send the link when the user isn’t actively in your app, or when connecting at their own pace is acceptable
  • In-app prompt: show a button (“Connect Gmail”) when you want to prompt connection at a specific moment in the user’s workflow

Once the user opens the link and approves the OAuth consent screen, Scalekit exchanges the authorization code for tokens and marks the connected account ACTIVE. You do not need to handle the OAuth callback yourself.

Check the connected account status before executing tools. Tokens can expire or be revoked, so generate a new authorization link using the same flow when that happens.

response = actions.get_or_create_connected_account(
connection_name="gmail",
identifier="user_123"
)
connected_account = response.connected_account
# ACTIVE: ready for tool calls
# PENDING: user has not completed the OAuth flow
# EXPIRED: tokens expired, re-authorization required
# REVOKED: user revoked access from the provider
if connected_account.status != "ACTIVE":
link_response = actions.get_authorization_link(
connection_name="gmail",
identifier="user_123"
)
# Redirect or send link_response.link to the user