mirror of
https://github.com/Dan6erbond/sk-auth.git
synced 2024-11-20 19:07:20 +01:00
🎨 Lint and prettify twitch.ts
This commit is contained in:
parent
615ff5fee3
commit
5e674c30ee
@ -1,57 +1,58 @@
|
|||||||
import { OAuth2Provider, OAuth2ProviderConfig } from "./oauth2";
|
import { OAuth2Provider, OAuth2ProviderConfig } from "./oauth2";
|
||||||
import { ucFirst } from "../helpers";
|
|
||||||
|
|
||||||
export interface TwitchProfile {
|
export interface TwitchProfile {
|
||||||
id: string;
|
id: string;
|
||||||
login: string;
|
login: string;
|
||||||
display_name: string;
|
display_name: string;
|
||||||
type?: string;
|
type?: string;
|
||||||
broadcaster_type?: string;
|
broadcaster_type?: string;
|
||||||
description: boolean;
|
description: boolean;
|
||||||
profile_image_url: string;
|
profile_image_url: string;
|
||||||
offline_image_url: string;
|
offline_image_url: string;
|
||||||
view_count: number;
|
view_count: number;
|
||||||
email: string;
|
email: string;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TwitchTokens {
|
export interface TwitchTokens {
|
||||||
access_token: string;
|
access_token: string;
|
||||||
expires_in: number;
|
expires_in: number;
|
||||||
scope: string;
|
scope: string;
|
||||||
token_type: string;
|
token_type: string;
|
||||||
refresh_token: string;
|
refresh_token: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type TwitchOAuth2ProviderConfig = OAuth2ProviderConfig<TwitchProfile, TwitchTokens>;
|
type TwitchOAuth2ProviderConfig = OAuth2ProviderConfig<TwitchProfile, TwitchTokens>;
|
||||||
|
|
||||||
const defaultConfig: Partial<TwitchOAuth2ProviderConfig> = {
|
const defaultConfig: Partial<TwitchOAuth2ProviderConfig> = {
|
||||||
id: "twitch",
|
id: "twitch",
|
||||||
scope: "user:read:email",
|
scope: "user:read:email",
|
||||||
accessTokenUrl: "https://id.twitch.tv/oauth2/token",
|
accessTokenUrl: "https://id.twitch.tv/oauth2/token",
|
||||||
authorizationUrl: "https://id.twitch.tv/oauth2/authorize",
|
authorizationUrl: "https://id.twitch.tv/oauth2/authorize",
|
||||||
profileUrl: "https://api.twitch.tv/helix/users",
|
profileUrl: "https://api.twitch.tv/helix/users",
|
||||||
};
|
};
|
||||||
|
|
||||||
export class TwitchOAuth2Provider extends OAuth2Provider<
|
export class TwitchOAuth2Provider extends OAuth2Provider<
|
||||||
TwitchProfile,
|
TwitchProfile,
|
||||||
TwitchTokens,
|
TwitchTokens,
|
||||||
TwitchOAuth2ProviderConfig
|
TwitchOAuth2ProviderConfig
|
||||||
> {
|
> {
|
||||||
constructor(config: TwitchOAuth2ProviderConfig) {
|
constructor(config: TwitchOAuth2ProviderConfig) {
|
||||||
super({
|
super({
|
||||||
...defaultConfig,
|
...defaultConfig,
|
||||||
...config,
|
...config,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUserProfile(tokens: TwitchTokens): Promise<TwitchProfile> {
|
async getUserProfile(tokens: TwitchTokens): Promise<TwitchProfile> {
|
||||||
const headers = {
|
const headers = {
|
||||||
'Client-ID': this.config.clientId + '',
|
"Client-ID": this.config.clientId + "",
|
||||||
'Accept': 'application/vnd.twitchtv.v5+json',
|
Accept: "application/vnd.twitchtv.v5+json",
|
||||||
'Authorization': `Bearer ${tokens.access_token}`
|
Authorization: `Bearer ${tokens.access_token}`,
|
||||||
};
|
};
|
||||||
const { data: [profile] } = await fetch(this.config.profileUrl!, { headers: headers }).then(res => res.json())
|
const {
|
||||||
return profile
|
data: [profile],
|
||||||
}
|
} = await fetch(this.config.profileUrl!, { headers: headers }).then((res) => res.json());
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user