mirror of
https://github.com/Dan6erbond/sk-auth.git
synced 2025-04-14 01:16:30 +02:00
feat: add spotify oauth2 provider
This commit is contained in:
parent
731eabd893
commit
23293cfbcf
59
src/providers/spotify.ts
Normal file
59
src/providers/spotify.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import { OAuth2Provider, OAuth2ProviderConfig } from "./oauth2";
|
||||
|
||||
export interface SpotifyProfile {
|
||||
display_name: string;
|
||||
email: string;
|
||||
external_urls: SpotifyProfileExternalUrls;
|
||||
followers: SpotifyProfileFollowers;
|
||||
href: string;
|
||||
id: string;
|
||||
images: SpotifyProfileImage[];
|
||||
type: string;
|
||||
uri: string;
|
||||
}
|
||||
|
||||
export interface SpotifyProfileImage {
|
||||
height: number;
|
||||
url: string;
|
||||
width: string;
|
||||
}
|
||||
|
||||
export interface SpotifyProfileFollowers {
|
||||
href: string;
|
||||
total: number;
|
||||
}
|
||||
|
||||
export interface SpotifyProfileExternalUrls {
|
||||
spotify: string;
|
||||
}
|
||||
|
||||
export interface SpotifyTokens {
|
||||
access_token: string;
|
||||
token_type: string;
|
||||
expires_in: number;
|
||||
refresh_token: string;
|
||||
scope: string;
|
||||
}
|
||||
|
||||
type SpotifyOAuth2ProviderConfig = OAuth2ProviderConfig<SpotifyProfile, SpotifyTokens>;
|
||||
|
||||
const defaultConfig: Partial<SpotifyOAuth2ProviderConfig> = {
|
||||
id: "spotify",
|
||||
scope: "user-read-email",
|
||||
accessTokenUrl: "https://accounts.spotify.com/api/token",
|
||||
authorizationUrl: "https://accounts.spotify.com/authorize",
|
||||
profileUrl: "https://api.spotify.com/v1/me",
|
||||
};
|
||||
|
||||
export class SpotifyOAuth2Provider extends OAuth2Provider<
|
||||
SpotifyProfile,
|
||||
SpotifyTokens,
|
||||
SpotifyOAuth2ProviderConfig
|
||||
> {
|
||||
constructor(config: SpotifyOAuth2ProviderConfig) {
|
||||
super({
|
||||
...defaultConfig,
|
||||
...config,
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user