45 lines
2.7 KiB
Markdown
45 lines
2.7 KiB
Markdown
# Twitch Cloud EBS
|
|
This is a server-side component providing cloud storage and [OAuth Code Grant Flow](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#authorization-code-grant-flow) access to otherwise client-side only software.
|
|
|
|
## Deploying
|
|
|
|
### Cloudflare Workers
|
|
|
|
Previously, there was a "deploy to cloudflare" button here, but it seems to only work with GitHub repos, so you'll have to clone and deploy this yourself.
|
|
|
|
### Docker
|
|
|
|
Previously, this repo produced oci images, but they were inclomlete and more work is needed before they are ready.
|
|
|
|
## Twurple Module
|
|
|
|
https://gitea.sugoidogo.com/sugoidogo/-/packages/npm/@sugoidogo%2Ftwitch-cloud-ebs/
|
|
|
|
This API provides two Twurple modules, one for authorization and one for storage, allowing for easy integration if you're already using the Twurple javascript library.
|
|
the WebStorage module can be used to cache fetched resources from anywhere, but when used as demonstrated below, allows your client to maintain access to previously stored resources from cloud storage via the browser's CacheStorage API.
|
|
|
|
<details><summary>javascript</summary>
|
|
|
|
```javascript
|
|
import { SugoiAuthProvider, WebStorage } from '@sugoidogo/twitch-cloud-ebs'
|
|
import { ApiClient } from '@twurple/ebs';
|
|
|
|
const ebs_host='https://your.ebs.hostname'
|
|
const authProvicder=new SugoiAuthProvider('your-client-id',ebs_host)
|
|
const webStorage=new WebStorage(authProvider,undefined,ebs_host)
|
|
const apiClient = new ApiClient({ authProvider });
|
|
|
|
const config=await webStorage.fetch('config.json').then(response=>response.json())
|
|
```
|
|
|
|
</details>
|
|
|
|
## Usage
|
|
|
|
### `/oauth2/token`
|
|
|
|
This endpoint is a proxy to `https://id.twitch.tv/oauth2/token` that adds the `client_secret` to your request body, in order to allow your client software to get a refresh token using the [OAuth Code Grant Flow](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#authorization-code-grant-flow) without exposing your client secret to end user devices. When this software was written, this was the only way to get a refresh token, and remains the only way to get a non-expiring refresh token, however Twitch has now added the [Device Code Grant Flow](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/#device-code-grant-flow) which grants you a refresh token that expires 30 days after refreshing. Consider if this new flow is acceptable for your application before using this endpoint.
|
|
|
|
### Storage
|
|
|
|
All locations outside of `/oauth` or the provided javascript modules are part of the storage API, which allows you to `GET`, `PUT`, or `DELETE` files from cloud storage, scoped to the client-id and user-id of the token provided in the `authorization` header, which uses the same authorization scheme as the Twitch API. |