Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(provider): add Bitbucket provider #12198

Merged
merged 18 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
},
}
}
Loading