|
| 1 | +# Bitbucket Authentication |
| 2 | + |
| 3 | +When GCM is triggered by Git, it will check the `host` parameter passed |
| 4 | +to it. If this parameter contains `bitbucket.org` it will trigger Bitbucket |
| 5 | +authentication and prompt you for credentials. In this scenario, you have two |
| 6 | +options for authentication: `OAuth` or `Password/Token`. |
| 7 | + |
| 8 | +### OAuth |
| 9 | + |
| 10 | +The dialog GCM presents for authentication contains two tabs. The first tab |
| 11 | +(labeled `Browser`) will trigger OAuth Authentication. Clicking the `Sign in |
| 12 | +with your browser` button opens a browser request to |
| 13 | +`_https://bitbucket.org/site/oauth2/authorize?response_type=code&client_id={consumerkey}&state=authenticated&scope={scopes}&redirect_uri=http://localhost:34106/_`. This triggers a flow on Bitbucket requiring you to log in |
| 14 | +(and potentially complete 2FA) to authorize GCM to access Bitbucket with the |
| 15 | +specified scopes. GCM will then spawn a temporary local webserver, listening on |
| 16 | +port 34106, to handle the OAuth redirect/callback. Assuming you successfully |
| 17 | +log into Bitbucket and authorize GCM, this callback will include the appropriate |
| 18 | +tokens for GCM to handle authencation. These tokens are then stored in your |
| 19 | +configured [credential store][credstores] and are returned to Git. |
| 20 | + |
| 21 | +### Password/Token |
| 22 | + |
| 23 | +**Note:** Bitbucket Data Center, also known as Bitbucket Server or Bitbucket On |
| 24 | +Premises, only supports Basic Authentication - please follow the below |
| 25 | +instructions if you are using this product. |
| 26 | + |
| 27 | +The dialog GCM presents for authentication contains two tabs. The second tab |
| 28 | +(labeled `Password/Token`) will trigger Basic Authentication. This tab contains |
| 29 | +two fields, one for your username and one for your password or token. If the |
| 30 | +`username` parameter was passed into GCM, that will pre-populate the username |
| 31 | +field, although it can be overridden. Enter your username (if needed) and your |
| 32 | +password or token (i.e. Bitbucket App Password) and click `Sign in`. |
| 33 | + |
| 34 | +:rotating_light: Requirements for App Passwords :rotating_light: |
| 35 | + |
| 36 | +If you are planning to use an [App Password][app-password] for basic |
| 37 | +authentication, it must at a minimum have _Account Read_ permissions (as shown |
| 38 | +below). If your App Password does not have these permissions, you will be |
| 39 | +re-prompted for credentials on every interaction with the server. |
| 40 | + |
| 41 | +![][app-password-example] |
| 42 | + |
| 43 | +When your username and password are submitted, GCM will attempt to retrieve a |
| 44 | +basic authentication token for these credentials via the Bitbucket REST API. If |
| 45 | +this is successful, the credentials, username, and password/token are stored in |
| 46 | +your configured [credential store][credstores] and are returned to Git. |
| 47 | + |
| 48 | +If the API request fails with a 401 return code, the entered username/password |
| 49 | +combination is invalid; nothing is stored and nothing is returned to Git. In |
| 50 | +this scenario, re-attempt authentication, ensuring your credentials are correct. |
| 51 | + |
| 52 | +If the API request fails with a 403 (Forbidden) return code, the username and |
| 53 | +password are valid, but 2FA is enabled on the corresponding Bitbucket Account. |
| 54 | +In this scenario, you will be prompted to complete the OAuth authentication |
| 55 | +process. If this is successful, the credentials, username, and password/token |
| 56 | +are stored in your configured [credential store][credstores] and are returned to |
| 57 | +Git. |
| 58 | + |
| 59 | +[app-password]: https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/ |
| 60 | +[app-password-example]: img/app-password.png |
| 61 | +[credstores]: ./credstores.md |
0 commit comments