Skip to content

Commit 6a72f3d

Browse files
halvaradopfalcowinklerbalazsorban44
authored
feat(provider): add Bitbucket provider (#12198)
* 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 <[email protected]> Co-authored-by: Balázs Orbán <[email protected]>
1 parent b45e75a commit 6a72f3d

5 files changed

Lines changed: 262 additions & 0 deletions

File tree

.github/ISSUE_TEMPLATE/2_bug_provider.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ body:
3434
- "Azure DevOps"
3535
- "Battlenet"
3636
- "Beyond Identity"
37+
- "Bitbucket"
3738
- "Box"
3839
- "Bungie"
3940
- "ClickUp"

docs/pages/data/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"azure-devops": "Azure DevOps",
6161
"battlenet": "Battle.net",
6262
"beyondidentity": "Beyond Identity",
63+
"bitbucket": "Bitbucket",
6364
"box": "Box",
6465
"boxyhq-saml": "BoxyHQ SAML",
6566
"bungie": "Bungie",
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import { Callout } from "nextra/components"
2+
import { Code } from "@/components/Code"
3+
4+
<img align="right" src="/img/providers/bitbucket.svg" height="64" width="64" />
5+
6+
# Bitbucket Provider
7+
8+
## Resources
9+
10+
- [Using OAuth on Bitbucket Cloud](https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/)
11+
- [Bitbucket REST API Authentication](https://developer.atlassian.com/cloud/bitbucket/rest/intro/#authentication)
12+
- [Bitbucket REST API Users](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-users/#api-group-users)
13+
14+
## Setup
15+
16+
### Callback URL
17+
18+
<Code>
19+
<Code.Next>
20+
21+
```bash
22+
https://example.com/api/auth/callback/bitbucket
23+
```
24+
25+
</Code.Next>
26+
<Code.Qwik>
27+
28+
```bash
29+
https://example.com/auth/callback/bitbucket
30+
```
31+
32+
</Code.Qwik>
33+
<Code.Svelte>
34+
35+
```bash
36+
https://example.com/auth/callback/bitbucket
37+
```
38+
39+
</Code.Svelte>
40+
</Code>
41+
42+
### Environment Variables
43+
44+
<Code>
45+
<Code.Next>
46+
47+
```bash filename=".env.local"
48+
AUTH_BITBUCKET_ID
49+
AUTH_BITBUCKET_SECRET
50+
```
51+
52+
</Code.Next>
53+
<Code.Qwik>
54+
55+
```bash filename=".env"
56+
AUTH_BITBUCKET_ID
57+
AUTH_BITBUCKET_SECRET
58+
```
59+
60+
</Code.Qwik>
61+
<Code.Svelte>
62+
63+
```bash filename=".env"
64+
AUTH_BITBUCKET_ID
65+
AUTH_BITBUCKET_SECRET
66+
```
67+
68+
</Code.Svelte>
69+
70+
<Code.Express>
71+
72+
```bash filename=".env"
73+
AUTH_BITBUCKET_ID
74+
AUTH_BITBUCKET_SECRET
75+
```
76+
77+
</Code.Express>
78+
</Code>
79+
80+
### Configuration
81+
82+
<Code>
83+
<Code.Next>
84+
85+
```ts filename="@/auth.ts"
86+
import NextAuth from "next-auth"
87+
import Bitbucket from "next-auth/providers/bitbucket"
88+
89+
export const { handlers, auth, signIn, signOut } = NextAuth({
90+
providers: [Bitbucket],
91+
})
92+
```
93+
94+
</Code.Next>
95+
<Code.Qwik>
96+
97+
```ts filename="/src/routes/[email protected]"
98+
import { QwikAuth$ } from "@auth/qwik"
99+
import Bitbucket from "@auth/qwik/providers/bitbucket"
100+
101+
export const { onRequest, useSession, useSignIn, useSignOut } = QwikAuth$(
102+
() => ({
103+
providers: [Bitbucket],
104+
})
105+
)
106+
```
107+
108+
</Code.Qwik>
109+
<Code.Svelte>
110+
111+
```ts filename="/src/auth.ts"
112+
import { SvelteKitAuth } from "@auth/sveltekit"
113+
import Bitbucket from "@auth/sveltekit/providers/bitbucket"
114+
115+
export const { handle, signIn, signOut } = SvelteKitAuth({
116+
providers: [Bitbucket],
117+
})
118+
```
119+
120+
</Code.Svelte>
121+
<Code.Express>
122+
123+
```ts filename="/src/app.ts"
124+
import { ExpressAuth } from "@auth/express"
125+
import Bitbucket from "@auth/express/providers/bitbucket"
126+
127+
app.use("/auth/*", ExpressAuth({ providers: [Bitbucket] }))
128+
```
129+
130+
</Code.Express>
131+
</Code>
Lines changed: 7 additions & 0 deletions
Loading
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* <div class="provider" style={{ display: "flex", justifyContent: "space-between", color: "#fff" }}>
3+
* <span>Built-in <b>Bitbucket</b> integration.</span>
4+
* <a href="https://bitbucket.org">
5+
* <img style={{display: "block"}} src="https://authjs.dev/img/providers/bitbucket.svg" height="48" width="48"/>
6+
* </a>
7+
* </div>
8+
*
9+
* @module providers/bitbucket
10+
*/
11+
12+
import { OAuthConfig, OAuthUserConfig } from "./index.js"
13+
14+
type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>)
15+
16+
/**
17+
* @see https://developer.atlassian.com/cloud/bitbucket/rest/api-group-users/#api-user-get
18+
*/
19+
export interface BitbucketProfile {
20+
display_name: string
21+
links: Record<
22+
LiteralUnion<
23+
"self" | "avatar" | "repositories" | "snippets" | "html" | "hooks"
24+
>,
25+
{ href?: string }
26+
>
27+
created_on: string
28+
type: string
29+
uuid: string
30+
has_2fa_enabled: boolean | null
31+
username: string
32+
is_staff: boolean
33+
account_id: string
34+
nickname: string
35+
account_status: string
36+
location: string | null
37+
}
38+
39+
/**
40+
*
41+
* ### Setup
42+
*
43+
* #### Callback URL
44+
*
45+
* ```ts
46+
* https://example.com/api/auth/callback/bitbucket
47+
* ```
48+
*
49+
* #### Configuration
50+
*
51+
* ```ts
52+
* import { Auth } from "@auth/core"
53+
* import Bitbucket from "@auth/core/providers/bitbucket"
54+
*
55+
* const request = new Request(origin)
56+
* const response = await Auth(request, {
57+
* providers: [
58+
* Bitbucket({
59+
* clientId: process.env.BITBUCKET_CLIENT_ID,
60+
* clientSecret: process.env.BITBUCKET_CLIENT_SECRET,
61+
* })
62+
* ],
63+
* })
64+
* ```
65+
*
66+
* #### Resources
67+
*
68+
* - [Using OAuth on Bitbucket Cloud](https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/)
69+
* - [Bitbucket REST API Authentication](https://developer.atlassian.com/cloud/bitbucket/rest/intro/#authentication)
70+
* - [Bitbucket REST API Users](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-users/#api-group-users)
71+
*
72+
* #### Notes
73+
*
74+
* By default, Auth.js assumes that the Bitbucket provider is
75+
* based on the [OAuth 2](https://www.rfc-editor.org/rfc/rfc6749.html) specification.
76+
*
77+
* :::tip
78+
*
79+
* The Bitbucket provider comes with a [default configuration](https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/providers/bitbucket.ts).
80+
* To override the defaults for your use case, check out [customizing a built-in OAuth provider](https://authjs.dev/guides/configuring-oauth-providers).
81+
*
82+
* :::
83+
*
84+
* :::info **Disclaimer**
85+
*
86+
* If you think you found a bug in the default configuration, you can [open an issue](https://authjs.dev/new/provider-issue).
87+
*
88+
* Auth.js strictly adheres to the specification and it cannot take responsibility for any deviation from
89+
* the spec by the provider. You can open an issue, but if the problem is non-compliance with the spec,
90+
* we might not pursue a resolution. You can ask for more help in [Discussions](https://authjs.dev/new/github-discussions).
91+
*
92+
* :::
93+
*/
94+
export default function Bitbucket(
95+
options: OAuthUserConfig<BitbucketProfile>
96+
): OAuthConfig<BitbucketProfile> {
97+
return {
98+
id: "bitbucket",
99+
name: "Bitbucket",
100+
type: "oauth",
101+
authorization: {
102+
url: "https://bitbucket.org/site/oauth2/authorize",
103+
params: {
104+
scope: "account",
105+
},
106+
},
107+
token: "https://bitbucket.org/site/oauth2/access_token",
108+
userinfo: "https://api.bitbucket.org/2.0/user",
109+
profile(profile) {
110+
return {
111+
name: profile.display_name ?? profile.username,
112+
id: profile.account_id,
113+
image: profile.links.avatar?.href,
114+
}
115+
},
116+
options,
117+
style: {
118+
text: "#fff",
119+
bg: "#205081",
120+
},
121+
}
122+
}

0 commit comments

Comments
 (0)