# Authorize a user

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

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.

```python
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...")
```

```typescript
const linkResponse = await actions.getAuthorizationLink({
  connectionName: '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 flow
```

## Check Authorization Status

If you would like to check whether the user has completed authorization for a given application,

```python
response = actions.get_or_create_connected_account(
    connection_name="gmail",
    identifier="user_123"
)
connected_account = response.connected_account
print(f"Authorization status of the connected account", connected_account.status)
```

```typescript
const response = await actions.getOrCreateConnectedAccount({
  connectionName: 'gmail',
  identifier: 'user_123',
});
const connectedAccount = response.connectedAccount;
console.log('Authorization status of the connected account', connectedAccount?.status);
```