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 for authentication #12198

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -36,6 +36,7 @@ body:
- "Beyond Identity"
- "Box"
- "Bungie"
- "Bitbucket"
- "ClickUp"
- "Cognito"
- "Concept2"
Expand Down
3 changes: 2 additions & 1 deletion docs/pages/data/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@
"yandex": "Yandex",
"zitadel": "ZITADEL",
"zoho": "Zoho",
"zoom": "Zoom"
"zoom": "Zoom",
"bitbucket": "Bitbucket"
},
"providersEmail": {
"forwardemail": "Forward Email",
Expand Down
2 changes: 0 additions & 2 deletions packages/adapter-supabase/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ export function SupabaseAdapter(options: SupabaseAdapterOptions): Adapter {

if (error) throw error

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { id, ...verificationToken } = data

return format<VerificationToken>(verificationToken)
Expand All @@ -223,7 +222,6 @@ export function SupabaseAdapter(options: SupabaseAdapterOptions): Adapter {
if (error) throw error
if (!data) return null

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { id, ...verificationToken } = data

return format<VerificationToken>(verificationToken)
Expand Down
150 changes: 150 additions & 0 deletions packages/core/src/providers/bitbucket.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/**
* <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,
* })
* ],
* })
* ```
* #### 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.
*
* #### Registration
*
* - [Login](https://bitbucket.org/)
* - [Workspaces](https://bitbucket.org/account/workspaces/)
* - Settings > Workspace settings > OAuth consumers > Add consumer
* Name: Auth.js,
* Description: Auth.js,
* Callback URL: https://example.com/api/auth/callback/bitbucket
* Permissions: Account: Read Email Write
* Click "Save"
* Copy the "Key" and "Secret" to your `.env.local` file.
*
* #### 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)
*
* :::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(
config: OAuthUserConfig<BitbucketProfile>
): OAuthConfig<BitbucketProfile> {
return {
id: "bitbucket",
name: "Bitbucket",
type: "oauth",
authorization: {
url: `https://bitbucket.org/site/oauth2/authorize`,
params: {
response_type: "code",
scope: "account",
},
},
token: {
url: "https://bitbucket.org/site/oauth2/access_token",
params: {
grant_type: "authorization_code",
},
},
userinfo: {
url: "https://api.bitbucket.org/2.0/user",
async request({ tokens, provider }) {
return await fetch(provider.userinfo?.url as URL, {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${tokens.access_token}`,
},
}).then((response) => response.json())
},
},
profile(profile) {
return {
name: profile.display_name ?? profile.username,
id: profile.account_id,
image: profile.links.avatar?.href,
}
},
issuer: "https://bitbucket.org",
options: config,
style: {
text: "#fff",
bg: "#205081",
},
}
}

Check warning on line 150 in packages/core/src/providers/bitbucket.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/providers/bitbucket.ts#L1-L150

Added lines #L1 - L150 were not covered by tests
Loading