> For the complete documentation index, see [llms.txt](https://authing.gitbook.io/authing/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://authing.gitbook.io/authing/extensibility/pipeline/context-object.md).

# context 对象

## 属性 <a href="#variables" id="variables"></a>

| 属性名               | 类型     | 说明                                                                     |
| ----------------- | ------ | ---------------------------------------------------------------------- |
| protocol          | string | 认证协议。具体说明见下文。                                                          |
| connection        | string | 身份提供方。具体说明见下文。                                                         |
| ldapConfiguration | object | ldap 配置，在为 ldap 认证的情况下带有。具体说明见下文。                                      |
| samlConfiguration | object | saml 配置，在为 saml 认证的情况下带有。具体说明见下文。                                      |
| oidcConfiguration | object | OIDC 应用配置，在为 OIDC 认证的情况下带有。具体说明见下文。                                    |
| data              | object | GraphQL POST 请求数据。如在注册前 Pipeline 中，开发者可以获取邮箱、手机号、注册方式等信息。**详细字段请见下文**。 |
| headers           | object | 原始请求头信息。                                                               |
| userPool          | object | 用户池详细信息。处于安全考虑，这里不包含 secret 和  token。具体说明见下文。                          |
| ip                | string | 请求者 IP。                                                                |
| geo               | object | 包含了请求者的地址信息以及经纬度坐标。具体说明见下文。                                            |

## protocol

认证协议。

| 可能值    | 说明                                                                                           |
| ------ | -------------------------------------------------------------------------------------------- |
| basic  | 普通认证模式，基于用户名密码、手机号验证码。                                                                       |
| social | 社会化登录认证默认，当使用 Authing 集成的社会化登录手段登录时为此值。                                                      |
| ldap   | 使用 LDAP 进行认证。有关如何接入 LDAP 请见 [配置 LDAP 服务](/authing/authentication/ldap/ldap.md)。              |
| saml   | 使用 SAML 进行认证。有关如何接入 SAML 请见 [接入 SAML](/authing/authentication/use-saml.md)。                  |
| oidc   | 使用 OIDC 协议认证。有关如何接入 OIDC 请见[使用 OIDC 授权](/authing/authentication/oidc/oidc-authorization.md)。 |

## connection

身份提供方。

| 可能值                               | 说明                                                                                                                                                                                       |
| --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| authing                           | 如使用用户名密码、手机号验证码，基于 Authing 的数据库进行验证。                                                                                                                                                     |
| ldap:\<LDAP服务ID>                  | 使用 lDAP 协议进行登录。 一个 Authing LDAP 服务对应一个 Authing 用户目录或第三方用户目录，详情请见 [配置 LDAP服务](/authing/authentication/ldap/ldap.md) 和 [使用 Authing 的 LDAP 用户目录](/authing/authentication/ldap/ldap-idp.md)。 |
| saml:\<SAML  Idp 服务 ID>           | 使用 SAML 协议进行登录。有关如何接入 SAML 请见 [接入 SAML](/authing/authentication/use-saml.md)。                                                                                                            |
| oidc:\<OIDC 应用 ID>                | 使用 OIDC 协议认证。有关如何接入 OIDC 请见 [使用 OIDC 授权](/authing/authentication/oidc/oidc-authorization.md)。                                                                                            |
| social:github                     | 使用 GitHub 登录。详情见[接入 GitHub 登录](/authing/social-login/web/github.md)。                                                                                                                     |
| <p></p><p>social:wechat-pc </p>   | 微信 PC 扫码登录。详情见[接入微信 PC 扫码登录](/authing/social-login/web/wechat-pc.md)。                                                                                                                    |
| social:wechat-miniprogram         | 使用微信小程序登录。详情见[接入微信小程序登录](/authing/social-login/miniprogram/miniprogram.md)。                                                                                                              |
| social:wechat-app                 | 使用微信移动应用登录。详情见[接入移动端 APP 微信登录](/authing/social-login/mobile/wechat.md)。                                                                                                                  |
| social:app2wxapp                  | 在移动应用 App 中拉起小程序登录。详情见[接入移动端 APP 拉起小程序登录](/authing/social-login/miniprogram/app2wxapp.md)。                                                                                               |
| social:wechat-officialaccount-web | 使用微信公众号网页授权登录。详情见[接入微信公众号网页授权登录](/authing/social-login/web/wechat-mp.md)。                                                                                                                |
| social:qq-web                     | 使用 QQ 网页版登录。详情见[接入 QQ 登录](/authing/social-login/web/qq.md)。                                                                                                                              |
| social:weibo-web                  | 使用微博网页版登录。详情见[接入微博登录](/authing/social-login/web/weibo.md)。                                                                                                                               |
| social:dingtalk-web               | 使用钉钉网页版登录。详情见[接入钉钉登录](/authing/social-login/web/dingtalk.md)。                                                                                                                            |
| social:alipay-mobile              | 使用支付宝 APP 登录。详情见[接入移动 APP 支付宝登录](/authing/social-login/mobile/alipay.md)。                                                                                                                |
| social:wechatwork-web             | 企业微信网页授权登录。详情见[企业微信网页授权登录](/authing/social-login/web/wechatwork-web.md)。                                                                                                                 |
| social:wechatwork-qrconnect       | 企业微信扫码登录。详情见[企业微信扫码登录](/authing/social-login/web/wechatwork-qrconnect.md)。                                                                                                               |

## data 对象 <a href="#data-object" id="data-object"></a>

注册前、注册后 Pipeline 中 data 对象部分请求字段如下：详情请见 [Authing GraphQL 调试器](https://authing.cn/graphiql/) **用户鉴权** - **注册**接口。

{% hint style="warning" %}
email, phone, unionid 等字段不一定同时存在，使用前请先判断其是否存在！如&#x20;

```javascript
const email = context.data.userInfo.email
if(email) {
    // 表示是用邮箱注册
    // 可以进行邮箱注册白名单的逻辑
    
    if(!email.endsWith('example.com')){
        return callback(new Error('Access Denied!'))
    }
}
```

{% endhint %}

| 字段名                       | 类型     | 说明                                                                                                                                                                 |
| ------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| userInfo                  | object | 用户注册所填的数据，如邮箱、手机号、浏览器 UA 等。                                                                                                                                        |
| userInfo.registerInClient | string | 注册用户池                                                                                                                                                              |
| userInfo.registerMethod   | string | 注册方式。若开发者自己使用  SDK 开发使用此接口，最好提供注册方式。如未提供，Authing 将从其他是否提供 `unionid`，`email`, `phone`， `username` 四个字段推测注册方式（优先级递减，比如同时提供 `unionid` 和 `email`，会被视为 `unionid` 方式注册）。 |
| userInfo.unionid          | string | 社会化登录的 unionid。                                                                                                                                                    |
| userInfo.email            | string | 邮箱。                                                                                                                                                                |
| userInfo.phone            | string | 手机号。                                                                                                                                                               |
| userInfo.photo            | string | 用户头像。                                                                                                                                                              |

认证后 Pipeline 中 data 对象部分请求字段如下：详情请见 [Authing GraphQL 调试器](https://authing.cn/graphiql/) **用户鉴权** - **登录**接口。

{% hint style="warning" %}
这些字段不一定全部存在，使用前请先判断是否存在！
{% endhint %}

| 字段名              | 类型     | 说明             |
| ---------------- | ------ | -------------- |
| registerInClient | string | 用户池 ID         |
| phone            | string | 手机号            |
| phoneCode        | string | 手机号验证码         |
| unionid          | string | 社会化登录  unionid |
| openid           | string | 社会化登录 openid   |
| email            | string | 邮箱             |
| lastIP           | string | 登录  IP         |
| browser          | string | 浏览器            |

## userPool 对象 <a href="#userpool-object" id="userpool-object"></a>

| 字段名              | 类型      | 说明                |
| ---------------- | ------- | ----------------- |
| \_id             | string  | 用户池 ID            |
| name             | string  | 用户池名称             |
| logo             | string  | 用户池图标             |
| registerDisabled | boolean | 是否关闭注册            |
| userPoolTypeList | array   | 用户池类型列表。每个类型内容如下： |

```javascript
{
      "_id": "5e193ceb71edb858dc54b8ef",
      "name": 'Web',
      "description": 'Web Application',
      "example": 'Web SDK',
      "image": ''
}
```

## geo 属性 <a href="#geo" id="geo"></a>

示例数据：

```javascript
{
	"address": "湖南省长沙市",
	"address_detail": {
		"city": "长沙市",
		"city_code": "430100",
		"district": "",
		"province": "湖南省",
		"street": "",
		"street_number": ""
	},
	"point": {
		"x": "112.6534116",
		"y": "27.96920845"
	}
}
```

## oidcConfiguration

* \_id： OIDC 应用 ID。
* clientId: 用户池 ID。
* redirect\_uris: 回调链接列表。
* token\_endpoint\_auth\_method:  换取 token 认证模式。
* grant\_types: 授权模式。
* id\_token\_signed\_response\_alg:  id\_token 签名算法。
* authorization\_code\_expire: authorization\_code 有效时间，单位为秒。

```javascript
{
  image: 'https://usercontents.authing.cn/oauth/applications/Flw6fw74vCzeZR17ApcRARSxIE7A',
  redirect_uris: [ 'http://localhost:8888/oidc/handle' ],
  token_endpoint_auth_method: 'client_secret_post',
  grant_types: [ 'authorization_code', 'refresh_token' ],
  response_types: [ 'code' ],
  id_token_signed_response_alg: 'HS256',
  isDeleted: false,
  isDefault: true,
  authorization_code_expire: '600',
  id_token_expire: '3600',
  access_token_expire: '3600',
  cas_expire: '3600',
  _id: "5d9f78ace01c86293a9c0857",
  name: 'OIDC 应用名称',
  domain: 'domain',
  clientId: '5d9f78acb02d3e14484cfc37',
  description: '',
  when: 2019-10-10T18:30:04.784Z,
  client_id: '5d9f78ace01c86293a9c0857',
  client_secret: '6536f317ca56779ea9b0c4bde4869c66',
  __v: 0,
  css: '/* \n' +
    '  在此编辑认证页面的 css 代码\n' +
    '  如：\n' +
    '  body {\n' +
    '    background: #6699 !important;\n' +
    '  } \n' +
    '  用于修改背景色\n' +
    '*/',
  customStyles: {
    forceLogin: true,
    hideQRCode: false,
    hideUP: false,
    hideUsername: false,
    hideRegister: false,
    hidePhone: false,
    hideSocial: false,
    hideClose: false,
    placeholder: {
      username: '请输入用户名',
      email: '请输入邮箱',
      password: '请输入密码',
      confirmPassword: '请确认密码',
      verfiyCode: '请输入验证码',
      newPassword: '请输入新密码',
      phone: '请输入手机号',
      phoneCode: '4 位验证码'
    },
    qrcodeScanning: { interval: 1500, tips: '使用微信扫码登录' }
  }
}
```
