diff --git a/.github/workflows/lint-on-pr.yml b/.github/workflows/lint-on-pr.yml new file mode 100644 index 0000000..a69b9da --- /dev/null +++ b/.github/workflows/lint-on-pr.yml @@ -0,0 +1,19 @@ +name: Lint package on pull request +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + with: + node-version: 14 + - run: yarn install + - run: yarn lint diff --git a/app/src/global.d.ts b/app/src/global.d.ts index e7783bb..402a008 100644 --- a/app/src/global.d.ts +++ b/app/src/global.d.ts @@ -14,6 +14,8 @@ declare global { TWITTER_API_SECRET: string; REDDIT_API_KEY: string; REDDIT_API_SECRET: string; + TWITCH_OAUTH_CLIENT_ID: string; + TWITCH_OAUTH_CLIENT_SECRET: string; JWT_SECRET_KEY: string; NODE_ENV: "development" | "production"; PORT?: string; diff --git a/app/src/lib/appAuth.ts b/app/src/lib/appAuth.ts index b05937e..51ca7bc 100644 --- a/app/src/lib/appAuth.ts +++ b/app/src/lib/appAuth.ts @@ -1,5 +1,6 @@ import { SvelteKitAuth } from "sk-auth"; import { + TwitchOAuth2Provider, FacebookOAuth2Provider, GoogleOAuth2Provider, RedditOAuth2Provider, @@ -18,6 +19,13 @@ export const appAuth = new SvelteKitAuth({ return { ...profile, provider: "google" }; }, }), + new TwitchOAuth2Provider({ + clientId: import.meta.env.VITE_TWITCH_OAUTH_CLIENT_ID, + clientSecret: import.meta.env.VITE_TWITCH_OAUTH_CLIENT_SECRET, + profile(profile) { + return { ...profile, provider: "twitch" }; + }, + }), new FacebookOAuth2Provider({ clientId: process.env.FACEBOOK_OAUTH_CLIENT_ID, clientSecret: process.env.FACEBOOK_OAUTH_CLIENT_SECRET, diff --git a/app/src/routes/login.svelte b/app/src/routes/login.svelte index b897ec2..df5cf77 100644 --- a/app/src/routes/login.svelte +++ b/app/src/routes/login.svelte @@ -36,6 +36,38 @@
+ + + + + Sign in with Twitch + + ; + +const defaultConfig: Partial = { + id: "twitch", + scope: "user:read:email", + accessTokenUrl: "https://id.twitch.tv/oauth2/token", + authorizationUrl: "https://id.twitch.tv/oauth2/authorize", + profileUrl: "https://api.twitch.tv/helix/users", +}; + +export class TwitchOAuth2Provider extends OAuth2Provider< + TwitchProfile, + TwitchTokens, + TwitchOAuth2ProviderConfig +> { + constructor(config: TwitchOAuth2ProviderConfig) { + super({ + ...defaultConfig, + ...config, + }); + } + + async getUserProfile(tokens: TwitchTokens): Promise { + const headers = { + "Client-ID": this.config.clientId + "", + Accept: "application/vnd.twitchtv.v5+json", + Authorization: `Bearer ${tokens.access_token}`, + }; + const { + data: [profile], + } = await fetch(this.config.profileUrl!, { headers: headers }).then((res) => res.json()); + return profile; + } +}