# wechaty-token

> Wechaty Token Based Authentication Manager

Latest version **1.0.6** (published 2021-11-28) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install wechaty-token
pnpm add wechaty-token
yarn add wechaty-token
bun add wechaty-token
```

Provides the command `wechaty-token`.

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2021-11-28 |
| First published | 2021-08-02 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=16 |
| Dependencies | 4 |
| Unpacked size | 130.7 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Huan LI |
| Maintainers | zixia |
| Keywords | wechaty, token |

## Links

- npm: https://www.npmjs.com/package/wechaty-token
- Repository: https://github.com/wechaty/token
- Homepage: https://github.com/wechaty/token#readme
- Issues: https://github.com/wechaty/token/issues
- npm.io page: https://npm.io/package/wechaty-token

## Dependencies (4)

- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [brolog](https://npm.io/package/brolog.md) ^1.14.2
- [cmd-ts](https://npm.io/package/cmd-ts.md) ^0.7.0
- [cockatiel](https://npm.io/package/cockatiel.md) ^2.0.2

## Recent versions

- 1.0.6 (latest) — 2021-11-28
- 1.1.2 (next) — 2022-01-19
- 1.1.1 — 2022-01-16
- 1.0.5 — 2021-11-28
- 0.5.8 — 2021-08-25
- 0.5.7 — 2021-08-25
- 0.5.5 — 2021-08-25
- 0.4.4 — 2021-08-15
- 0.4.3 — 2021-08-04
- 0.4.2 — 2021-08-04
- 0.3.1 — 2021-08-03
- 0.2.1 — 2021-08-02
- 0.1.7 — 2021-08-02
- 0.1.4 — 2021-08-02
- 0.1.2 — 2021-08-02
- … 1 more at https://npm.io/package/wechaty-token/versions

## README

# wechaty-token

[![NPM](https://github.com/wechaty/token/actions/workflows/npm.yml/badge.svg)](https://github.com/wechaty/token/actions/workflows/npm.yml)
[![NPM Version](https://badge.fury.io/js/wechaty-token.svg)](https://badge.fury.io/js/wechaty-token)
[![npm (tag)](https://img.shields.io/npm/v/wechaty-token/next.svg)](https://www.npmjs.com/package/wechaty-token?activeTab=versions)
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-blue.svg)](https://www.typescriptlang.org/)

![wechaty token](docs/images/wechaty-token.png)

Wechaty Token Based Authentication Manager

## Install

```sh
npm install -g wechaty-token
```

## CLI Usage

```sh
$ wechaty-token --help

wechaty-token <subcommand>
> Wechaty utility for discovering and generating tokens

where <subcommand> can be one of:

- generate - Generate a new Wechaty Token
- discover - Wechaty TOKEN Service Discovery

For more help, try running `wechaty-token <subcommand> --help`
```

### Wechaty Token Discovery

```sh
$ wechaty-token discover --help

wechaty-token discover
> Wechaty TOKEN Service Discovery

ARGUMENTS:
  <str> - Wechaty Puppet Service TOKEN

FLAGS:
  --help, -h - show help
```

Example:

```sh
# Discover a valid token (in-service)
$ wechaty-token discover puppet_IN-SERVICE-TOKEN
{
  "host": "1.2.3.4",
  "port": 5678
}
$ echo $?
0

# Discover a unvalid token (out-of-service)
$ wechaty-token discover puppet_OUT-OF-SERVICE-TOKEN
NotFound
$ echo $?
1
```

### Generate Wechaty Token

```sh
$ wechaty-token generate --help

wechaty-token generate
> Generate a new Wechaty Token

OPTIONS:
  --type, -t <str> - The type of the Wechaty Puppet Service [optional]

FLAGS:
  --help, -h - show help
```

Example:

```sh
# Generate a UUID token (`uuid` will be the default type)
$ wechaty-token generate
uuid_1fab726b-e3d3-40ce-8b7b-d3bd8c9fd280

# Generate token with type `foo`
$ wechaty-token generate --type foo
foo_1fab726b-e3d3-40ce-8b7b-d3bd8c9fd280
```

## gRPC Resolver Usage

We now can use `wechaty:///${TOKEN}` as gRPC address for Wechaty Service Token Discovery.

The `WechatyResolver` is for resolve the above address and help gRPC to connect to the right host and port.

```ts
import { WechatyResolver } from 'wechaty-token'
WechatyResolver.setup()
// That's it! You can use `wechaty:///${TOKEN}` as gRPC address now!
// const routeguide = grpc.loadPackageDefinition(packageDefinition).routeguide;
// client = new routeguide.RouteGuide('wechaty:///${TOKEN}',
//                                     grpc.credentials.createInsecure());
// See: https://grpc.io/docs/languages/node/basics/
```

See:

- [gRPC Name Resolution](https://github.com/grpc/grpc/blob/master/doc/naming.md)
- [Wechaty Puppet Service Code](https://github.com/wechaty/wechaty-puppet-service/blob/3a0285432e6916720c40604c61bcea6be5f63ab5/src/client/puppet-service.ts#L284-L285)

## History

### master v1.0 (Nov 28, 2021)

1. ES Module support
1. TypeScript 4.5
1. Wechaty Token Discovery output `JSON.stringify` format

### v0.5 (Sep 8, 2021)

1. Wechaty Token format standard released: `SNI_UUID`
    1. `SNI` will be used as Server Indicator Name (SNI) when we are using TLS
    1. `UUID` is a standard UUID format (v4)
1. add `wechatyToken.sni` support.

### v0.4 (Aug 15, 2021)

1. Use `cockatiel` to implement `RetryPolicy`
1. Use `nock` to implement HTTP unit testing
1. Implemented [#1](https://github.com/wechaty/token/issues/1)

### v0.2 master (Aug 2, 2021)

1. `wechaty-token` CLI released
1. gRPC Resolver for Wechaty: Enabled `xds` like schema `wechaty:///uuid_TOKEN` for gRPC client

### v0.0.1 (Aug 1, 2021)

Inited

## Author

[Huan LI](https://github.com/huan) ([李卓桓](http://linkedin.com/in/zixia)), Google Developer Expert (Machine Learning), zixia@zixia.net

[![Profile of Huan LI (李卓桓) on StackOverflow](https://stackexchange.com/users/flair/265499.png)](https://stackexchange.com/users/265499)

## Copyright & License

- Code & Docs © 2018-now Huan LI \<zixia@zixia.net\>
- Code released under the Apache-2.0 License
- Docs released under Creative Commons

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