From ae203f06dbc0f5ff9458c25354a3e3ef82042c87 Mon Sep 17 00:00:00 2001 From: Dan6erbond Date: Tue, 25 May 2021 23:58:06 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=91=B7=20Add=20Lint=20on=20PR=20Workf?= =?UTF-8?q?low?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/lint-on-pr.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/lint-on-pr.yml 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 From 615ff5fee398d3976feea2c655c9e8f6d754d48c Mon Sep 17 00:00:00 2001 From: "!anime.x_ror" <16686943+x-ror@users.noreply.github.com> Date: Wed, 26 May 2021 00:59:38 +0300 Subject: [PATCH 2/4] added twitch provider (#22) --- app/src/global.d.ts | 2 ++ app/src/lib/appAuth.ts | 8 ++++++ app/src/routes/login.svelte | 32 +++++++++++++++++++++ src/providers/index.ts | 2 ++ src/providers/twitch.ts | 57 +++++++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 src/providers/twitch.ts diff --git a/app/src/global.d.ts b/app/src/global.d.ts index d648a04..a4a6c44 100644 --- a/app/src/global.d.ts +++ b/app/src/global.d.ts @@ -3,6 +3,8 @@ interface ImportMetaEnv { VITE_GOOGLE_OAUTH_CLIENT_ID: string; VITE_GOOGLE_OAUTH_CLIENT_SECRET: string; + VITE_TWITCH_OAUTH_CLIENT_ID: string; + VITE_TWITCH_OAUTH_CLIENT_SECRET: string; VITE_FACEBOOK_OAUTH_CLIENT_ID: string; VITE_FACEBOOK_OAUTH_CLIENT_SECRET: string; VITE_TWITTER_API_KEY: string; diff --git a/app/src/lib/appAuth.ts b/app/src/lib/appAuth.ts index 315fa63..f337b64 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, @@ -15,6 +16,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: import.meta.env.VITE_FACEBOOK_OAUTH_CLIENT_ID, clientSecret: import.meta.env.VITE_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 + } +} From 5e674c30ee073e525b429b20042abab4e7f9281a Mon Sep 17 00:00:00 2001 From: RaviAnand Mohabir Date: Wed, 26 May 2021 00:01:27 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=8E=A8=20Lint=20and=20prettify=20`twi?= =?UTF-8?q?tch.ts`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/providers/twitch.ts | 81 +++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/src/providers/twitch.ts b/src/providers/twitch.ts index c179f32..810a3e3 100644 --- a/src/providers/twitch.ts +++ b/src/providers/twitch.ts @@ -1,57 +1,58 @@ import { OAuth2Provider, OAuth2ProviderConfig } from "./oauth2"; -import { ucFirst } from "../helpers"; export interface TwitchProfile { - id: string; - login: string; - display_name: string; - type?: string; - broadcaster_type?: string; - description: boolean; - profile_image_url: string; - offline_image_url: string; - view_count: number; - email: string; - created_at: string; + id: string; + login: string; + display_name: string; + type?: string; + broadcaster_type?: string; + description: boolean; + profile_image_url: string; + offline_image_url: string; + view_count: number; + email: string; + created_at: string; } export interface TwitchTokens { - access_token: string; - expires_in: number; - scope: string; - token_type: string; - refresh_token: string; + access_token: string; + expires_in: number; + scope: string; + token_type: string; + refresh_token: string; } type TwitchOAuth2ProviderConfig = OAuth2ProviderConfig; 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", + 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 + TwitchProfile, + TwitchTokens, + TwitchOAuth2ProviderConfig > { - constructor(config: TwitchOAuth2ProviderConfig) { - super({ - ...defaultConfig, - ...config, - }); - } + 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 - } + 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; + } } From d44e3be197a23c43962e26e1761fbf56bdd9be71 Mon Sep 17 00:00:00 2001 From: RaviAnand Mohabir Date: Wed, 26 May 2021 00:01:50 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=94=96=20Version=20bump=20to=20`0.3.6?= =?UTF-8?q?`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8e29bb0..0ff33ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sk-auth", - "version": "0.3.5", + "version": "0.3.6", "description": "Authentication library for use with SvelteKit featuring built-in OAuth providers and zero restriction customization!", "main": "dist/index.js", "types": "dist/index.d.ts",