기타 소셜 제공자

Better Auth는 Generic OAuth 플러그인을 통해 OAuth2 프로토콜 또는 OpenID Connect(OIDC) 플로우를 구현하는 모든 소셜 제공자를 기본적으로 지원합니다.

기본적으로 지원되지 않는 제공자를 사용하려면 Generic OAuth 플러그인을 사용할 수 있습니다.

설치

인증 설정에 플러그인 추가하기

Generic OAuth 플러그인을 사용하려면 인증 설정에 추가하세요.

auth.ts
import { betterAuth } from "better-auth"
import { genericOAuth } from "better-auth/plugins"

export const auth = betterAuth({
    // ... 기타 설정 옵션
    plugins: [
        genericOAuth({ 
            config: [ 
                { 
                    providerId: "provider-id", 
                    clientId: "test-client-id", 
                    clientSecret: "test-client-secret", 
                    discoveryUrl: "https://auth.example.com/.well-known/openid-configuration", 
                    // ... 기타 설정 옵션
                }, 
                // 필요한 만큼 제공자 추가
            ] 
        }) 
    ]
})

클라이언트 플러그인 추가하기

인증 클라이언트 인스턴스에 Generic OAuth 클라이언트 플러그인을 포함시키세요.

auth-client.ts
import { createAuthClient } from "better-auth/client"
import { genericOAuthClient } from "better-auth/client/plugins"

const authClient = createAuthClient({
    plugins: [
        genericOAuthClient()
    ]
})

Generic OAuth 플러그인의 설치 및 사용에 대한 자세한 내용은 여기를 참조하세요.

사용 예시

Instagram 예시

auth.ts
import { betterAuth } from "better-auth";
import { genericOAuth } from "better-auth/plugins";

export const auth = betterAuth({
  // ... 기타 설정 옵션
  plugins: [
    genericOAuth({
      config: [
        {
          providerId: "instagram",
          clientId: process.env.INSTAGRAM_CLIENT_ID as string,
          clientSecret: process.env.INSTAGRAM_CLIENT_SECRET as string,
          authorizationUrl: "https://api.instagram.com/oauth/authorize",
          tokenUrl: "https://api.instagram.com/oauth/access_token",
          scopes: ["user_profile", "user_media"],
        },
      ],
    }),
  ],
});
sign-in.ts
const response = await authClient.signIn.oauth2({
  providerId: "instagram",
  callbackURL: "/dashboard", // 사용자 인증 후 리다이렉트할 경로
});

Coinbase 예시

auth.ts
import { betterAuth } from "better-auth";
import { genericOAuth } from "better-auth/plugins";

export const auth = betterAuth({
  // ... 기타 설정 옵션
  plugins: [
    genericOAuth({
      config: [
        {
          providerId: "coinbase",
          clientId: process.env.COINBASE_CLIENT_ID as string,
          clientSecret: process.env.COINBASE_CLIENT_SECRET as string,
          authorizationUrl: "https://www.coinbase.com/oauth/authorize",
          tokenUrl: "https://api.coinbase.com/oauth/token",
          scopes: ["wallet:user:read"], // 등등...
        },
      ],
    }),
  ],
});
sign-in.ts
const response = await authClient.signIn.oauth2({
  providerId: "coinbase",
  callbackURL: "/dashboard", // 사용자 인증 후 리다이렉트할 경로
});

On this page