Skip to content

Commit

Permalink
feat(provider): add Bitbucket provider (#12198)
Browse files Browse the repository at this point in the history
* feat(provider): add Bitbucket provider for authentication

* simplify bitbucket.ts

* add bitbucket.svg

* align doc structure with other providers

* simplify config/options

* format

* chore(docs): add missing documentation in `getting-started/providers`

* chore: update callback URLs in `bitbucket` provider

* chore: remove `pnpm-lock.yaml`

* chore: restore `pnpm-lock.yaml` file from `main`

* Update manifest.json

* Update bitbucket.mdx

* Update index.ts

* Update index.ts

* Update 2_bug_provider.yml

* Update index.ts

---------

Co-authored-by: Falco Winkler <8613031+falcowinkler@users.noreply.github.com>
Co-authored-by: Balázs Orbán <info@balazsorban.com>
  • Loading branch information
3 people authored Jan 22, 2025
1 parent b45e75a commit 6a72f3d
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/2_bug_provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ body:
- "Azure DevOps"
- "Battlenet"
- "Beyond Identity"
- "Bitbucket"
- "Box"
- "Bungie"
- "ClickUp"
Expand Down
1 change: 1 addition & 0 deletions docs/pages/data/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"azure-devops": "Azure DevOps",
"battlenet": "Battle.net",
"beyondidentity": "Beyond Identity",
"bitbucket": "Bitbucket",
"box": "Box",
"boxyhq-saml": "BoxyHQ SAML",
"bungie": "Bungie",
Expand Down
131 changes: 131 additions & 0 deletions docs/pages/getting-started/providers/bitbucket.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { Callout } from "nextra/components"
import { Code } from "@/components/Code"

<img align="right" src="/img/providers/bitbucket.svg" height="64" width="64" />

# Bitbucket Provider

## Resources

- [Using OAuth on Bitbucket Cloud](https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/)
- [Bitbucket REST API Authentication](https://developer.atlassian.com/cloud/bitbucket/rest/intro/#authentication)
- [Bitbucket REST API Users](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-users/#api-group-users)

## Setup

### Callback URL

<Code>
<Code.Next>

```bash
https://example.com/api/auth/callback/bitbucket
```

</Code.Next>
<Code.Qwik>

```bash
https://example.com/auth/callback/bitbucket
```

</Code.Qwik>
<Code.Svelte>

```bash
https://example.com/auth/callback/bitbucket
```

</Code.Svelte>
</Code>

### Environment Variables

<Code>
<Code.Next>

```bash filename=".env.local"
AUTH_BITBUCKET_ID
AUTH_BITBUCKET_SECRET
```

</Code.Next>
<Code.Qwik>

```bash filename=".env"
AUTH_BITBUCKET_ID
AUTH_BITBUCKET_SECRET
```

</Code.Qwik>
<Code.Svelte>

```bash filename=".env"
AUTH_BITBUCKET_ID
AUTH_BITBUCKET_SECRET
```

</Code.Svelte>

<Code.Express>

```bash filename=".env"
AUTH_BITBUCKET_ID
AUTH_BITBUCKET_SECRET
```

</Code.Express>
</Code>

### Configuration

<Code>
<Code.Next>

```ts filename="@/auth.ts"
import NextAuth from "next-auth"
import Bitbucket from "next-auth/providers/bitbucket"

export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [Bitbucket],
})
```

</Code.Next>
<Code.Qwik>

```ts filename="/src/routes/plugin@auth.ts"
import { QwikAuth$ } from "@auth/qwik"
import Bitbucket from "@auth/qwik/providers/bitbucket"

export const { onRequest, useSession, useSignIn, useSignOut } = QwikAuth$(
() => ({
providers: [Bitbucket],
})
)
```

</Code.Qwik>
<Code.Svelte>

```ts filename="/src/auth.ts"
import { SvelteKitAuth } from "@auth/sveltekit"
import Bitbucket from "@auth/sveltekit/providers/bitbucket"

export const { handle, signIn, signOut } = SvelteKitAuth({
providers: [Bitbucket],
})
```

</Code.Svelte>
<Code.Express>

```ts filename="/src/app.ts"
import { ExpressAuth } from "@auth/express"
import Bitbucket from "@auth/express/providers/bitbucket"

app.use("/auth/*", ExpressAuth({ providers: [Bitbucket] }))
```

</Code.Express>
</Code>
7 changes: 7 additions & 0 deletions docs/public/img/providers/bitbucket.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 122 additions & 0 deletions packages/core/src/providers/bitbucket.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* <div class="provider" style={{ display: "flex", justifyContent: "space-between", color: "#fff" }}>
* <span>Built-in <b>Bitbucket</b> integration.</span>
* <a href="https://bitbucket.org">
* <img style={{display: "block"}} src="https://authjs.dev/img/providers/bitbucket.svg" height="48" width="48"/>
* </a>
* </div>
*
* @module providers/bitbucket
*/

import { OAuthConfig, OAuthUserConfig } from "./index.js"

type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>)

/**
* @see https://developer.atlassian.com/cloud/bitbucket/rest/api-group-users/#api-user-get
*/
export interface BitbucketProfile {
display_name: string
links: Record<
LiteralUnion<
"self" | "avatar" | "repositories" | "snippets" | "html" | "hooks"
>,
{ href?: string }
>
created_on: string
type: string
uuid: string
has_2fa_enabled: boolean | null
username: string
is_staff: boolean
account_id: string
nickname: string
account_status: string
location: string | null
}

/**
*
* ### Setup
*
* #### Callback URL
*
* ```ts
* https://example.com/api/auth/callback/bitbucket
* ```
*
* #### Configuration
*
* ```ts
* import { Auth } from "@auth/core"
* import Bitbucket from "@auth/core/providers/bitbucket"
*
* const request = new Request(origin)
* const response = await Auth(request, {
* providers: [
* Bitbucket({
* clientId: process.env.BITBUCKET_CLIENT_ID,
* clientSecret: process.env.BITBUCKET_CLIENT_SECRET,
* })
* ],
* })
* ```
*
* #### Resources
*
* - [Using OAuth on Bitbucket Cloud](https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/)
* - [Bitbucket REST API Authentication](https://developer.atlassian.com/cloud/bitbucket/rest/intro/#authentication)
* - [Bitbucket REST API Users](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-users/#api-group-users)
*
* #### Notes
*
* By default, Auth.js assumes that the Bitbucket provider is
* based on the [OAuth 2](https://www.rfc-editor.org/rfc/rfc6749.html) specification.
*
* :::tip
*
* The Bitbucket provider comes with a [default configuration](https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/providers/bitbucket.ts).
* To override the defaults for your use case, check out [customizing a built-in OAuth provider](https://authjs.dev/guides/configuring-oauth-providers).
*
* :::
*
* :::info **Disclaimer**
*
* If you think you found a bug in the default configuration, you can [open an issue](https://authjs.dev/new/provider-issue).
*
* Auth.js strictly adheres to the specification and it cannot take responsibility for any deviation from
* the spec by the provider. You can open an issue, but if the problem is non-compliance with the spec,
* we might not pursue a resolution. You can ask for more help in [Discussions](https://authjs.dev/new/github-discussions).
*
* :::
*/
export default function Bitbucket(
options: OAuthUserConfig<BitbucketProfile>
): OAuthConfig<BitbucketProfile> {
return {
id: "bitbucket",
name: "Bitbucket",
type: "oauth",
authorization: {
url: "https://bitbucket.org/site/oauth2/authorize",
params: {
scope: "account",
},
},
token: "https://bitbucket.org/site/oauth2/access_token",
userinfo: "https://api.bitbucket.org/2.0/user",
profile(profile) {
return {
name: profile.display_name ?? profile.username,
id: profile.account_id,
image: profile.links.avatar?.href,
}
},
options,
style: {
text: "#fff",
bg: "#205081",
},
}
}

0 comments on commit 6a72f3d

Please sign in to comment.