twitch-oauth
Version:
Authenticate users with Twitch.
74 lines (51 loc) • 1.61 kB
Markdown
Authenticate users with Twitch.
```shell
npm install twitch-oauth
yarn add twitch-oauth
```
```typescript
import { TwitchOAuth } from 'twitch-oauth';
// Initialize client.
const client = new TwitchOAuth({
clientId: '..............',
clientSecret: '..........',
redirectUri: '...........',
scope: [
"user:read:email",
"......"
],
// Optional, can be "token" or "code" (code is by default and recommended)
method: "code"
});
// Get the auth redirect url.
client.authenticate(); // Returns https://id.twitch.tv/oauth2/authorize?....
// Get access and refresh token using the code that twitch sends the frontend.
client.verifyCodeResponse(code: string)
.then(console.log);
// Check if access token still valid.
client.validate(access_token: string);
// Refresh expired token.
client.refresh(refresh_token: string);
```
```javascript
// If uses require function you will need to use .default
// For import in typescript, this is not required
const { TwitchOAuth } = require('twitch-oauth').default;
```
Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/sammwyy/twitch-oauth/issues).
Give a ⭐️ if this project helped you!
Or buy me a coffeelatte 🙌🏾
[](https://ko-fi.com/sammwy) | [Patreon](https://patreon.com/sammwy)
Copyright © 2022 [Sammwy](https://github.com/sammwyy).
This project is [MIT](LICENSE) licensed.