---
# System prepended metadata

title: BillLoader OpenAPI Authentication

---

# BillLoader OpenAPI Authentication  
## Authorization Method

> การยืนยันตัวตนสำหรับการเรียกใช้งานในทุกๆ API ต้องแนบ Header Request ดังต่อไปนี้

**Header Request**
| Parameter                  | Description                                | Schema  |
| -------------------------- | ------------------------------------------ | ------- |
| authorization (*required*) | JWT Token start with "Bearer "             |string   |

> ซึ่งสามารถร้องข้อได้ที่ API [OpenApiAuthentication](#POST-apiv1AuthenticationOpenApiAuthentication)

### Authentication data 

| Environment         | Endpoint | Username | Password | Initial authString |
| ------------------- | -------- | -------- | -------- | ------------------ |
|  ***                | ***      | ***      | ***      | ***                |

### `POST /api/v1/Authentication/OpenApiAuthentication`

**Body Request**

| Parameter         | Description          | Schema |
| ----------------- | ------------------   | ------ |
| authString        | encyp string         | string |

> วิธีการสร้าง [authString](#Preparing-authString) หรือทำการ POST request ไปที่ [GenerateOpenApiEncrypPayload](https://bill-loader-api.builk.com/api/v1/Authentication/GenerateOpenApiEncrypPayload) 
> **หมายเหตุ** สร้างครั้งเดียวใช้ได้ตลอดเว้นแต่ต้องการปรับเปลี่ยน expired ของ access token สูงสุด 3600 วินาที (1 ชั่วโมง)

**Response**

| Parameter   | Description        | Schema |
| ----------- | -----------------  | ------ |
| data        | object return      | object |
| status      |                    | number |
| message     | detail of error    | string |

**Object**

| Parameter    | Description                                      | Schema |
| -----------  | -----------------------------------------------  | ------ |
| accessToken  | jwt token for attachment in header every request | object |
| expiredToken | expired of token in format unix time             | number |

#### Example Request
```    
"authString..."
```

#### Example Response 
```json
{
  "code": 200,
  "message": "Success",
  "timestamp": "2021-02-22T06:21:48.5741764Z",
  "data": {
    "accessToken": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJGYWN0b3JpbmdHdWlkIjoiZDgyZjdjN2MtYTljOS00NmNjLTk0YzItYzI3ODk5NDJkOGQ4IiwibmJmIjoxNjEzOTc0OTA4LCJleHAiOjE2MTM5Nzg1MDgsImlhdCI6MTYxMzk3NDkwOCwiaXNzIjoiYmlsbC1sb2FkZXIuYnVpbGsuY29tIiwiYXVkIjoiZXh0ZXJuYWwtYXV0aC1zZXJ2aWNlIn0.aJ_OdlWP9rJGq_96casoGM5DHv10cyshVDykGbMeMy0",
    "expiredToken": 1613978508
  }
}
```

### `Preparing authString`

**Json Body**

| Parameter         | Description          | Schema |
| ----------------- | ------------------   | ------ |
| userName          |         | string |
| password          |          | string |
| expiredRequest    | expire token countdown after request (units in second) | number |

```json
    {
      "userName": "testUserName",
      "password": "testPassword",
      "expiredRequest": 3600
    } 
```
> encrypt json string with algorithm RSA 2048 Public key
```xml 
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgHD0cv4PdB3yTNL3eJZC
72VZ6AWRjxg/tv4p1s53/2uzcN1HJjKkcnklO6h7w6AZB9WXnXaiwemJux7oDGsq
Ett1Ejx9ayGUI30iKy7WE40Aw5fHKDNWNP2LXTDJ6P6JQhY4kp4T3od3R2ESHCau
VHWelX6+OE8XoPoa5f48/yfQoPcVl/Y/Ig9gNEovT57B6fhp7wM2YKgronaQS1+X
6jqLIryRDkNW6nhJDuTNGx2kCckq/AWzHlSb7Iooi6Iqhy4ZmF+sJhQzhvesaz//
VgnPN06UIbfbo0yVfKhx2JwGYuVJSXzpv0Z5MiD685Jp5LRpaYuxVRRCwqfaVO8s
6wIDAQAB
-----END PUBLIC KEY-----
```
