mirror of
https://github.com/Dan6erbond/sk-auth.git
synced 2025-04-09 01:16:54 +02:00
* 🐛 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
39 lines
984 B
TypeScript
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,
|
|
});
|
|
}
|
|
}
|