# LinkedIn (/docs/authentication/linkedin)

LinkedIn 提供商



<Steps>
  <Step>
    ### 获取您的 LinkedIn 凭证 [#获取您的-linkedin-凭证]

    要使用 LinkedIn 登录，您需要一个客户端 ID 和客户端密钥。您可以从 [LinkedIn 开发者门户](https://www.linkedin.com/developers/) 获取它们。

    请确保将重定向 URL 设置为 `http://localhost:3000/api/auth/callback/linkedin`，用于本地开发。生产环境中，您应将其设置为应用程序的 URL。如果更改了认证路由的基本路径，请相应更新重定向 URL。
  </Step>

  <Callout type="info">
    在 LinkedIn 门户的产品部分，您需要 **使用 OpenID Connect 的 LinkedIn 登录** 产品。
  </Callout>

  这里有一些不同的指南：
  [授权码流程（3 腿 OAuth）（已过时）](https://learn.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow)
  [使用 OpenID Connect 的 LinkedIn 登录](https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin-v2?context=linkedin%2Fconsumer%2Fcontext)

  <Step>
    ### 配置提供程序 [#配置提供程序]

    要配置提供程序，您需要导入提供程序并将其传递给认证实例的 `socialProviders` 选项。

    ```ts title="auth.ts"
    import { betterAuth } from "better-auth"

    export const auth = betterAuth({
        socialProviders: {
            linkedin: { // [!code highlight]
                clientId: process.env.LINKEDIN_CLIENT_ID as string, // [!code highlight]
                clientSecret: process.env.LINKEDIN_CLIENT_SECRET as string, // [!code highlight]
            }, // [!code highlight]
        },
    })
    ```

    <Callout>
      LinkedIn 的 `email` 和 `email_verified` 声明被[文档说明为可选](https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin-v2)，当会员未关联已确认邮箱时可能不存在。有关推荐的 `mapProfileToUser` 回退方案，请参阅[处理没有邮箱的提供程序](/docs/concepts/oauth#处理不提供邮箱的提供商)。
    </Callout>
  </Step>

  <Step>
    ### 使用 LinkedIn 登录 [#使用-linkedin-登录]

    要使用 LinkedIn 登录，可以使用客户端提供的 `signIn.social` 函数。`signIn` 函数接受一个包含以下属性的对象：

    * `provider`：要使用的提供程序。应设置为 `linkedin`。

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

    const signIn = async () => {
        const data = await authClient.signIn.social({
            provider: "linkedin"
        })
    }
    ```
  </Step>
</Steps>

