svelte.sk-auth/src/providers/google.ts
Dan6erbond 47cf0f1250
[ENHANCEMENT] Enhanced Types, Improved OAuth2 Configuration and Bug Fixes (#16)
* 🐛 Refactor `getPath` to `getUrl` and add `getPath` to fix detection of routes

* 🐛 Dynamically build `RegExp` with `basePath`

*  Add `ucFirst` helper

*  Add profile and tokens typing, add `contentType` to config for token fetch and use config in `RedditOAuth2Provider` instead of `getToken` override

* ✏️ Update imports in demo app
2021-05-24 16:30:17 +02:00

39 lines
984 B
TypeScript

import { OAuth2Provider, OAuth2ProviderConfig } from "./oauth2";
export interface GoogleProfile {
sub: string;
name: string;
give_name: string;
picture: string;
email: string;
email_verified: boolean;
locale: string;
}
export interface GoogleTokens {
access_token: string;
expires_in: number;
scope: string;
token_type: string;
id_token: string;
}
type GoogleOAuth2ProviderConfig = OAuth2ProviderConfig<GoogleProfile, GoogleTokens>;
const defaultConfig: Partial<GoogleOAuth2ProviderConfig> = {
id: "google",
scope: ["openid", "profile", "email"],
accessTokenUrl: "https://accounts.google.com/o/oauth2/token",
authorizationUrl: "https://accounts.google.com/o/oauth2/auth",
profileUrl: "https://openidconnect.googleapis.com/v1/userinfo",
};
export class GoogleOAuth2Provider extends OAuth2Provider<GoogleOAuth2ProviderConfig> {
constructor(config: GoogleOAuth2ProviderConfig) {
super({
...defaultConfig,
...config,
});
}
}