# Obtain user_access_token(Mini Program)

After obtaining the login credential `code` through the [login](https://open.feishu.cn/document/uYjL24iN/uYzMuYzMuYzM) API, you can get the session_key and user information by sending a request to the server

This API is applicable to [Mini Program login](https://open.feishu.cn/document/uYjL24iN/uETO5QjLxkTO04SM5kDN) and [Component login](https://open.feishu.cn/document/uAjLw4CM/uYjL24iN/block/guide/open-ability/block-login).

##  Request

Facts | &nbsp;
---|---
HTTP URL | https://open.feishu.cn/open-apis/mina/v2/tokenLoginValidate
HTTP Method | POST
Supported app types | Custom App、Store App
Required scopes<br>**The permissions required to call this API. You can call the API with any of the permissions** | None

###  Request header

Name | Type | Required | Description
---|---|---|---
Authorization | string | Yes | `app_access_token`<br>**Value format**: "Bearer `access_token`"<br>**Example value**: "Bearer t-7f1bcd13fc57d46bac21793a18e560"<br>[Learn more about how to obtain and use access_token](https://open.feishu.cn/document/ukTMukTMukTM/uMTNz4yM1MjLzUzM)
Content-Type | string | Yes | **Fixed value**: "application/json; charset=utf-8"

### Request body
Parameter | Type | Required | Description 
-- | -- | -- | -- 
code | string | Yes | The  code obtained at [login](https://open.feishu.cn/document/uYjL24iN/uYzMuYzMuYzM)

###  Example request body
```json
{
     "code": "2ef0bb04e272d274"
}
```

##  Response
###  Response body

Name | Type | Description
---|---|---
code | int | Error code. A value other than 0 indicates failure
msg | string | Error description
data | \- | \-
&emsp;∟&nbsp;open_id | string | [Open ID](https://open.feishu.cn/document/home/user-identity-introduction/open-id) of the user, which is used to identify the user in an app
&emsp;∟&nbsp;employee_id | string | [User ID](https://open.feishu.cn/document/home/user-identity-introduction/user-id) of the user, which is the unique identifier of an in-service employee in the company <br>**This field is returned only when the following permission is enabled**:<br>Obtain user ID(contact:user.employee_id:readonly)
&emsp;∟&nbsp;session_key | string | Session key
&emsp;∟&nbsp;tenant_key | string | Unique identifier of the user's company
&emsp;∟&nbsp;access_token | string | [user_access_token](https://open.feishu.cn/document/ukTMukTMukTM/uMTNz4yM1MjLzUzM), the user's access token
&emsp;∟&nbsp;expires_in | int | [user_access_token](https://open.feishu.cn/document/ukTMukTMukTM/uMTNz4yM1MjLzUzM) expiration timestamp
&emsp;∟&nbsp;refresh_token | string | The token used to refresh the user's access_token; it is valid for 30 days. For Refresh access_token API description, please refer to the [documentation](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/authen-v1/authen/refresh_access_token)

###  Example response body
```json
{
    "code": 0,
    "msg": "success",
    "data": {
    	"open_id": "ou_194fcfc5e4b78db556a040ff5e42c0",
    	"employee_id":"6c486g",
    	"union_id":"ou_be2c1742f2bb189469bdd33f0b1516",
    	"session_key": "e3aeb7df000c835365c630dac91bcf",
    	"tenant_key":"2c5914ac018f97",
    	"access_token":"u-tpwcnx2XzIcq8yHyJ6KL",
    	"expires_in":1565512680,
    	"refresh_token":"ur-W9dGvBJyVtwZmrwh0vBn"
    }
}
```

###  Error code

HTTPStatus code | Error code | Description | Possible cause and suggestion
---|---|---|---
200 | 10202 | access token invalid | Check whether  access_token  has expired
200 | 10213 | code appid not match | 1. The app that is used to obtain the code must be the same one that calls the API. Check whether the API is called by another app<br>2. The code can only be used once. Check whether it was reused or expired
200 | 10226 | invalid code | code invalid, check whether it was invalid or expired
200 | 10228 | user to app has no visibility | Invisible to the user

## Known issues
The returned data will contain a union_id, which is obsolete and is not the same concept as the [union_id](https://open.feishu.cn/document/home/user-identity-introduction/union-id) commonly used in open platforms. Please do not use it; if necessary, it can be obtained by [Get individual user information](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/acs-v1/user/get)