Authorize a user
Learn how to authorize users for successful tool execution with Agent Auth.
Scalekit provides a completely managed authentication platform to handle complex OAuth2.0, API Keys, Bearer Tokens and any other API authentication protocols required by third party applications to execute tool calls on behalf of users.
This managed authentication handling enables you to build powerful agents without having to worry about handling user authentication and API authentication across different applications like Salesforce, Hubspot, GMail, Google Calendar etc.
Authorize a user
Section titled “Authorize a user”If you are building an agent that needs to execute actions on behalf of a user, your agent needs to get authorization from user to give access to their application.
The following code sample helps your agent complete user authorization required to make a successful authenticated tool call.
link_response = actions.get_authorization_link( connection_name="gmail", # connection name to which the user needs to grant access identifier="user_123" # unique user id)print(f"click on the link to authorize gmail", link_response.link)input(f"Press Enter after authorizing gmail...")const linkResponse = await connectedAccounts.getMagicLinkForConnectedAccount({ connector: 'gmail', // connection name to which the user needs to grant access identifier: 'user_123', // unique user id});console.log('click on the link to authorize gmail', linkResponse.link);// In production, redirect the user to linkResponse.link to complete the OAuth flowCheck Authorization Status
Section titled “Check Authorization Status”If you would like to check whether the user has completed authorization for a given application,
response = actions.get_or_create_connected_account( connection_name="gmail", identifier="user_123")connected_account = response.connected_accountprint(f"Authorization status of the connected account", connected_account.status)const response = await connectedAccounts.getOrCreateConnectedAccount({ connector: 'gmail', identifier: 'user_123',});const connectedAccount = response.connectedAccount;console.log('Authorization status of the connected account', connectedAccount?.status);