# oauth-sdk-bm

> ## 安装

Latest version **0.0.41** (published 2020-07-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install oauth-sdk-bm
pnpm add oauth-sdk-bm
yarn add oauth-sdk-bm
bun add oauth-sdk-bm
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.41 |
| Published | 2020-07-24 |
| First published | 2020-07-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 16.2 KB |
| Known vulnerabilities | 0 (+25 in 1 direct dependencies) |
| Install scripts | no |
| Author | Joeyzone |
| Maintainers | joeyzone |

## Links

- npm: https://www.npmjs.com/package/oauth-sdk-bm
- Repository: https://github.com/bitmartexchange/bitmart-official-api-docs
- Homepage: https://github.com/bitmartexchange
- Issues: https://github.com/bitmartexchange/bitmart-official-api-docs/issues
- npm.io page: https://npm.io/package/oauth-sdk-bm

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.19.2
- [crypto-js](https://npm.io/package/crypto-js.md) ^4.0.0

## Recent versions

- 0.0.41 (latest) — 2020-07-24
- 0.0.4 — 2020-07-24
- 0.0.32 — 2020-07-24
- 0.0.31 — 2020-07-24
- 0.0.3 — 2020-07-24
- 0.0.2 — 2020-07-24
- 0.0.1 — 2020-07-24

## README

# Bitmart OAuth Nodejs SDK

## 安装

```javascript
  npm i @bitmart/oauth-sdk
```

使用指南


在官方给出的 bitmart 登录链接登录，获取 authorizeCode。然后调用以下方法获取
accessToken 和其他需要的内容

```javascript
  import { createToken, refreshToken } from '@bitmart/oauth-sdk'

  /**
   * 获取token
   * @param clientId 
   * @param authorizeCode 
   * @param clientSecret 
   * @param options 
   */
  createToken('123', '123', '123', {
    url: 'http://api.bitmartdev.com/user-center/oauth/access-token',
    application: 'SG',
  })

  /**
   * 每隔一段时间，token会失效，需要重新获取
   * @param clientId 
   * @param refreshToken 
   * @param clientSecret 
   * @param options 
   */
  refreshToken('123', '123', '123', {
    url: 'http://api.bitmartdev.com/user-center/oauth/access-token/refresh',
    application: 'SG',
  })
  
  // createToken，refreshToken 返回结构如下
  {
    "code": 0,
    "message": "OK",
    "data": {
      "accessToken":"xxxxxxxxxxxx.xxxxxxxxxx.xxxxxxxx",
      "accessSalt":"7YB3FLXO812",
      "refreshToken":"3F0XG5Qx2TlKWIA4cd123",
      "expireIn": 1444
    }
  }

```

额外提供生成签名的方法可供使用
```javascript
  import { createToken, refreshToken } from '@bitmart/oauth-sdk'

  const now = Date.now()
  /**
   * 生成签名
   * @param clientId 
   * @param authorizeCode 
   * @param clientSecret 
   * @param timestamp 
   */
  const sign = createSign('123', '123', '123', now)

```

---
_Source: https://npm.io/package/oauth-sdk-bm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
