Dan6erbond / sk-auth

Authentication library for use with SvelteKit featuring built-in OAuth providers and zero restriction customization!
MIT License
577 stars 70 forks source link

[ENHANCEMENT] OAuth Base Provider #12

Closed Dan6erbond closed 3 years ago

Dan6erbond commented 3 years ago

Overview

Implement a OAuth2BaseProvider abstract class, and OAuthProvider that uses config values to perform a standard OAuth flow, which can be overriden to create customized flows, or instantiated using a config object as such:

export class FacebookOAuth2Provider extends OAuth2Provider<FacebookOAuth2ProviderConfig> {
  constructor(config: FacebookOAuth2ProviderConfig) {
    const userProfileFields = config.userProfileFields || defaultConfig.userProfileFields;
    const profileUrl = `${config.profileUrl || defaultConfig.profileUrl}?${
      Array.isArray(userProfileFields) ? userProfileFields.join(",") : userProfileFields
    }`;

    super({
      ...defaultConfig,
      profileUrl,
      ...config,
    });
  }
}

RedditOAuth2Provider provides apiKey and apiSecret as aliases to clientId and clientSecret and implements its own getTokens() method due to the usage of URLFormEncoded HTTP POST requests on the Reddit API.