https://github.com/instafluff/comfytwitch
Comfiest Way to Add Serverless Twitch Authentication
https://github.com/instafluff/comfytwitch
Last synced: 11 months ago
JSON representation
Comfiest Way to Add Serverless Twitch Authentication
- Host: GitHub
- URL: https://github.com/instafluff/comfytwitch
- Owner: instafluff
- License: mit
- Created: 2020-01-20T23:50:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-03-27T03:18:13.000Z (about 2 years ago)
- Last Synced: 2024-11-09T22:41:22.127Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 93.8 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ComfyTwitch
Comfiest Way to Add Serverless Twitch Authentication
**ComfyTwitch** lets you integrate Twitch authentication for websites without a server ***SUPER EASILY*** in just a few lines of code. It automatically caches the authentication in the browser so that users do not have to log in every single visit.
## Instafluff ##
> *Like these projects? The best way to support my open-source projects is by becoming a Comfy Sponsor on GitHub!*
> https://github.com/sponsors/instafluff
> *Come and hang out with us at the Comfiest Corner on Twitch!*
> https://twitch.tv/instafluff
## Demo ##
To see how it works, check out this static webpage that authenticates using Twitch OAuth: [https://www.instafluff.tv/ComfyTwitch](https://www.instafluff.tv/ComfyTwitch)
## Instructions ##
#### Prequisites
1. Create a Twitch application from [https://dev.twitch.tv/console/apps/create](https://dev.twitch.tv/console/apps/create) to generate a Twitch Client ID
2. Add an OAuth Redirect URL to your Twitch application for the authentication to redirect the user to afterwards. A local example would look like: `http://localhost:8800/index.html`
#### Website
1. Download `comfytwitch.min.js` from the `web` folder or include from the JSDeliver CDN and add into every page you need authenticated:
```javascript
```
OR
```javascript
```
2. Check for Twitch authentication using `ComfyTwitch.Check()` for whether or not the user is logged in.
***The authentication is cached in the browser so that the user does not have to log in every time.***
```html
const clientId = "YOUR-CLIENT-ID";
const baseUrl = window.location.origin;
ComfyTwitch.Check()
.then( result => {
if( result ) {
// Logged In
}
else {
// Logged Out
}
});
```
3. Add Twitch Log-In by calling `ComfyTwitch.Login()` on a button click or through a separate page, passing in the Client ID, the same Redirect URI as set in your Twitch application, and the [Twitch Permission Scopes](https://dev.twitch.tv/docs/authentication/#scopes) you need:
```javascript
ComfyTwitch.Login( "YOUR-CLIENT-ID", `http://localhost:8800/index.html`, [ "user:read:email" ] );
```
4. Add Twitch Log-out by calling `ComfyTwitch.Logout()`
## Additional Functions ##
- **GetUser**`( clientId, userId )`
- Retrieve a Twitch user's information
```javascript
let user = await ComfyTwitch.GetUser( "YOUR-CLIENT-ID", "TWITCH-USER-ID" );
```