# agora-access-token

> ```shell npm i agora-access-token ```

Latest version **2.0.4** (published 2020-05-04) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install agora-access-token
pnpm add agora-access-token
yarn add agora-access-token
bun add agora-access-token
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2020-05-04 |
| First published | 2019-03-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 39.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | plutoless |

## Links

- npm: https://www.npmjs.com/package/agora-access-token
- Homepage: https://github.com/AgoraIO/Tools/tree/master/DynamicKey/AgoraDynamicKey/nodejs
- npm.io page: https://npm.io/package/agora-access-token

## Dependencies (2)

- [cuint](https://npm.io/package/cuint.md) 0.2.2
- [crc-32](https://npm.io/package/crc-32.md) 1.2.0

## Recent versions

- 2.0.4 (latest) — 2020-05-04
- 2.0.3 — 2020-04-26
- 2.0.2 — 2020-03-08
- 2.0.1 — 2019-12-16
- 2.0.0 — 2019-12-16
- 1.0.2-alpha.2 — 2019-03-06
- 1.0.2-alpha.1 — 2019-03-06
- 1.0.2 — 2019-03-06
- 1.0.1 — 2019-03-05
- 1.0.0 — 2019-03-05

## README

# How to use
## Install

```shell
npm i agora-access-token
```

## Import
```javascript
const {RtcTokenBuilder, RtmTokenBuilder, RtcRole, RtmRole} = require('agora-access-token')
```

### Generate
```javascript
// Rtc Examples
const appID = '<Your app ID>';
const appCertificate = '<Your app certificate>';
const channelName = '<The channel this token is generated for>';
const uid = 2882341273;
const account = "2882341273";
const role = RtcRole.PUBLISHER;

const expirationTimeInSeconds = 3600

const currentTimestamp = Math.floor(Date.now() / 1000)

const privilegeExpiredTs = currentTimestamp + expirationTimeInSeconds

// IMPORTANT! Build token with either the uid or with the user account. Comment out the option you do not want to use below.

// Build token with uid
const tokenA = RtcTokenBuilder.buildTokenWithUid(appID, appCertificate, channelName, uid, role, privilegeExpiredTs);
console.log("Token With Integer Number Uid: " + tokenA);

// Build token with user account
const tokenB = RtcTokenBuilder.buildTokenWithAccount(appID, appCertificate, channelName, account, role, privilegeExpiredTs);
console.log("Token With UserAccount: " + tokenB);
```

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