Paybin

获取你的 Paybin 凭证

要使用 Paybin 登录,你需要通过你的 Paybin 投资组合应用创建一个 OAuth 2.0 客户端。

  1. 登录到你的 Paybin 资源组合
  2. 导航到开发者设置或 OAuth 应用部分
  3. 点击“创建 OAuth 应用”或“新建应用”
  4. 填写必填字段:
    • 应用名称:在授权过程中向用户显示的名称
    • 重定向 URI:在本地开发时设置为 http://localhost:3000/api/auth/callback/paybin。在生产环境中,设置为 https://yourdomain.com/api/auth/callback/paybin。如果更改了认证路由的基础路径,请相应更新重定向 URI。
  5. 创建后,将客户端ID和客户端密钥复制到你的环境变量中。请保持这些凭据的安全。

配置提供程序

要配置提供程序,你需要导入该提供程序并将其传递给身份验证实例的 socialProviders 选项。

auth.ts
import { betterAuth } from "better-auth"

export const auth = betterAuth({
    socialProviders: {
        paybin: { 
            clientId: process.env.PAYBIN_CLIENT_ID as string, 
            clientSecret: process.env.PAYBIN_CLIENT_SECRET as string, 
        }, 
    },
})

Sign In with Paybin

To sign in with Paybin, you can use the signIn.social function provided by the client, where the provider should be set to paybin.

auth-client.ts
import { createAuthClient } from "better-auth/client"
const authClient = createAuthClient()

const signIn = async () => {
    const data = await authClient.signIn.social({
        provider: "paybin"
    })
}

额外配置

【Additional Configuration】

范围

【Scopes】

默认情况下,Paybin 提供商请求以下权限范围:openidemailprofile。你可以根据应用的需求自定义这些权限范围。

【By default, Paybin provider requests the following scopes: openid, email, and profile. You can customize the scopes based on your application's needs.】

有关可用作用域及其说明的完整列表,请参阅 Paybin OIDC 作用域文档

【For a complete list of available scopes and their descriptions, see the Paybin OIDC Scopes Documentation.】

auth.ts
export const auth = betterAuth({
    socialProviders: {
        paybin: {
            clientId: process.env.PAYBIN_CLIENT_ID as string,
            clientSecret: process.env.PAYBIN_CLIENT_SECRET as string,
            scope: ["openid", "email", "profile", "transactions"], 
        },
    },
})

用户资料映射

【User Profile Mapping】

Paybin 根据 OpenID Connect 标准在 ID 令牌中返回用户信息。提供者会自动提取:

  • id 来自 sub 声明
  • name 来自 namepreferred_usernameemail(按优先顺序)
  • email 来自 email 声明
  • image 来自 picture 声明
  • emailVerified 来自 email_verified 声明

【Paybin returns user information in the ID token following OpenID Connect standards. The provider automatically extracts:

  • id from sub claim
  • name from name, preferred_username, or email (in order of preference)
  • email from email claim
  • image from picture claim
  • emailVerified from email_verified claim】

On this page