<a id="bitbucket-data-center-oauth2"></a>

# Bitbucket Data Center OAuth2

<a id="backend-class"></a>

## Backend class

For Django, add this class path to `AUTHENTICATION_BACKENDS`. For other
integrations, use the same class path in the framework-specific backend
setting.

| Backend name                  | Class path                                                            |
|-------------------------------|-----------------------------------------------------------------------|
| `bitbucket-datacenter-oauth2` | `social_core.backends.bitbucket_datacenter.BitbucketDataCenterOAuth2` |

Bitbucket Data Center (previously Bitbucket Server) supports the [OAuth 2.0](https://confluence.atlassian.com/bitbucketserver/bitbucket-oauth-2-0-provider-api-1108483661.html) protocol. It supports two types of OAuth 2.0 flows:

1. Authorization code with [Proof Key for Code Exchange (PKCE)](https://datatracker.ietf.org/doc/html/rfc7636)
2. Authorization code

<a id="configuration"></a>

## Configuration

1. Register a new [Application Link](https://confluence.atlassian.com/bitbucketserver/configure-an-incoming-link-1108483657.html) in your Bitbucket Data Center instance.
2. Provide the host URL of your Bitbucket Data Center instance:
   ```default
   SOCIAL_AUTH_BITBUCKET_DATACENTER_OAUTH2_URL = "https://my-bitbucket-server.acme.com"
   ```
3. Fill *Client ID* in `SOCIAL_AUTH_BITBUCKET_DATACENTER_OAUTH2_KEY` and *Client Secret* in `SOCIAL_AUTH_BITBUCKET_DATACENTER_OAUTH2_SECRET` in your project settings:
   ```default
   SOCIAL_AUTH_BITBUCKET_DATACENTER_OAUTH2_KEY = "..."
   SOCIAL_AUTH_BITBUCKET_DATACENTER_OAUTH2_SECRET = "..."
   ```
4. Enable the backend:
   ```default
   SOCIAL_AUTH_AUTHENTICATION_BACKENDS = (
       ...
       "social_core.backends.bitbucket_datacenter.BitbucketDataCenterOAuth2",
       ...
   )
   ```

<a id="extra-configuration"></a>

## Extra Configuration

- You can specify the scope that your application requires:
  ```default
  SOCIAL_AUTH_BITBUCKET_DATACENTER_OAUTH2_SCOPE = ["PUBLIC_REPOS"]
  ```

  You can see all possible values at [Bitbucket Data Center OAuth 2.0 provider API](https://confluence.atlassian.com/bitbucketserver/bitbucket-oauth-2-0-provider-api-1108483661.html#BitbucketOAuth2.0providerAPI-scopes). By default, `PUBLIC_REPOS` is set.
- You can choose to disable PKCE:
  ```default
  SOCIAL_AUTH_BITBUCKET_DATACENTER_OAUTH2_USE_PKCE = False
  ```

  By default, True is set.
- You can specify PKCE challenge method:
  ```default
  SOCIAL_AUTH_BITBUCKET_DATACENTER_OAUTH2_PKCE_CODE_CHALLENGE_METHOD = '...'
  ```

  The possible values for this are `s256` and `plain`.
  By default, `s256` is set.

  You can see more information about PKCE at [RFC7636](https://datatracker.ietf.org/doc/html/rfc7636).
- You can specify the user’s avatar size:
  ```default
  SOCIAL_AUTH_BITBUCKET_DATACENTER_OAUTH2_USER_AVATAR_SIZE = 48
  ```

  This is the size of the user’s avatar requested from the API which is stored in `EXTRA_DATA["avatar_url"]`. By default, `48` is set.
