# GitHub 单点登录提供商

> Source: https://strapi.nodejs.cn/cms/configurations/sso-providers/github

🌐 GitHub provider SSO configuration

使用你的 GitHub OAuth 凭据和用户电子邮件权限，在 `config/admin` 文件中通过 `passport-github2` 将 GitHub 配置为 Strapi 管理员登录的 SSO 提供者。

🌐 Configure GitHub as an SSO provider for Strapi admin sign-in using `passport-github2` in the `config/admin` file with your GitHub OAuth credentials and user email scope.

本页面解释了如何为[单点登录 (SSO) 功能](/cms/features/sso) 设置 GitHub 提供程序。

🌐 The present page explains how to setup the GitHub provider for the [Single Sign-On (SSO) feature](/cms/features/sso).

:::prerequisites

你已阅读[如何配置 SSO 指南](/cms/configurations/guides/configure-sso)。

🌐 You have read the [How to configure SSO guide](/cms/configurations/guides/configure-sso).

:::

## 安装 {#installation}

🌐 Installation

安装 [passport-github](https://github.com/cfsghost/passport-github)：

```sh
yarn add passport-github2
```

```sh
npm install --save passport-github2
```

## 配置示例 {#configuration-example}

🌐 Configuration example

GitHub SSO 提供程序在 [ `config/admin` 文件](/cms/configurations/admin-panel) 的 `auth.providers` 数组中配置：

🌐 The GitHub SSO provider is configured in the `auth.providers` array of [the `config/admin` file](/cms/configurations/admin-panel):

```js title="/config/admin.js"

const GithubStrategy = require("passport-github2");

module.exports = ({ env }) => ({
  auth: {
    // ...
    providers: [
      {
        uid: "github",
        displayName: "Github",
        icon: "https://cdn1.iconfinder.com/data/icons/logotypes/32/github-512.png",
        createStrategy: (strapi) =>
          new GithubStrategy(
            {
              clientID: env("GITHUB_CLIENT_ID"),
              clientSecret: env("GITHUB_CLIENT_SECRET"),
              scope: ["user:email"],
              callbackURL:
                strapi.admin.services.passport.getStrategyCallbackURL("github"),
            },
            (accessToken, refreshToken, profile, done) => {
              done(null, {
                email: profile.emails[0].value,
                username: profile.username,
              });
            }
          ),
      },
    ],
  },
});

```

```ts title="/config/admin.ts"

  auth: {
    // ...
    providers: [
      {
        uid: "github",
        displayName: "Github",
        icon: "https://cdn1.iconfinder.com/data/icons/logotypes/32/github-512.png",
        createStrategy: (strapi) =>
          new GithubStrategy(
            {
              clientID: env("GITHUB_CLIENT_ID"),
              clientSecret: env("GITHUB_CLIENT_SECRET"),
              scope: ["user:email"],
              callbackURL:
                strapi.admin.services.passport.getStrategyCallbackURL("github"),
            },
            (accessToken, refreshToken, profile, done) => {
              done(null, {
                email: profile.emails[0].value,
                username: profile.username,
              });
            }
          ),
      },
    ],
  },
});

```
