mirror of
https://github.com/Dan6erbond/sk-auth.git
synced 2025-11-07 01:19:24 +01:00
🎨 Add RedditOAuthProvider.profileHandler for general use and stripping of payload
This commit is contained in:
parent
7d1f92d593
commit
7c454575ef
@ -32,53 +32,9 @@ export const appAuth = new SvelteKitAuth({
|
|||||||
new RedditOAuthProvider({
|
new RedditOAuthProvider({
|
||||||
apiKey: import.meta.env.VITE_REDDIT_API_KEY,
|
apiKey: import.meta.env.VITE_REDDIT_API_KEY,
|
||||||
apiSecret: import.meta.env.VITE_REDDIT_API_SECRET,
|
apiSecret: import.meta.env.VITE_REDDIT_API_SECRET,
|
||||||
profile({
|
profile(profile) {
|
||||||
is_employee,
|
profile = RedditOAuthProvider.profileHandler(profile);
|
||||||
has_external_account,
|
return { ...profile, provider: "reddit" };
|
||||||
snoovatar_img,
|
|
||||||
verified,
|
|
||||||
id,
|
|
||||||
over_18,
|
|
||||||
is_gold,
|
|
||||||
is_mod,
|
|
||||||
awarder_karma,
|
|
||||||
has_verified_email,
|
|
||||||
is_suspended,
|
|
||||||
icon_img,
|
|
||||||
pref_nightmode,
|
|
||||||
awardee_karma,
|
|
||||||
password_set,
|
|
||||||
link_karma,
|
|
||||||
total_karma,
|
|
||||||
name,
|
|
||||||
created,
|
|
||||||
created_utc,
|
|
||||||
comment_karma,
|
|
||||||
}) {
|
|
||||||
return {
|
|
||||||
is_employee,
|
|
||||||
has_external_account,
|
|
||||||
snoovatar_img,
|
|
||||||
verified,
|
|
||||||
id,
|
|
||||||
over_18,
|
|
||||||
is_gold,
|
|
||||||
is_mod,
|
|
||||||
awarder_karma,
|
|
||||||
has_verified_email,
|
|
||||||
is_suspended,
|
|
||||||
icon_img,
|
|
||||||
pref_nightmode,
|
|
||||||
awardee_karma,
|
|
||||||
password_set,
|
|
||||||
link_karma,
|
|
||||||
total_karma,
|
|
||||||
name,
|
|
||||||
created,
|
|
||||||
created_utc,
|
|
||||||
comment_karma,
|
|
||||||
provider: "reddit",
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|||||||
@ -8,55 +8,57 @@ interface RedditOAuthProviderConfig extends OAuth2ProviderConfig {
|
|||||||
duration?: "temporary" | "permanent";
|
duration?: "temporary" | "permanent";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const redditProfileHandler = ({
|
||||||
|
is_employee,
|
||||||
|
has_external_account,
|
||||||
|
snoovatar_img,
|
||||||
|
verified,
|
||||||
|
id,
|
||||||
|
over_18,
|
||||||
|
is_gold,
|
||||||
|
is_mod,
|
||||||
|
awarder_karma,
|
||||||
|
has_verified_email,
|
||||||
|
is_suspended,
|
||||||
|
icon_img,
|
||||||
|
pref_nightmode,
|
||||||
|
awardee_karma,
|
||||||
|
password_set,
|
||||||
|
link_karma,
|
||||||
|
total_karma,
|
||||||
|
name,
|
||||||
|
created,
|
||||||
|
created_utc,
|
||||||
|
comment_karma,
|
||||||
|
}) => ({
|
||||||
|
is_employee,
|
||||||
|
has_external_account,
|
||||||
|
snoovatar_img,
|
||||||
|
verified,
|
||||||
|
id,
|
||||||
|
over_18,
|
||||||
|
is_gold,
|
||||||
|
is_mod,
|
||||||
|
awarder_karma,
|
||||||
|
has_verified_email,
|
||||||
|
is_suspended,
|
||||||
|
icon_img,
|
||||||
|
pref_nightmode,
|
||||||
|
awardee_karma,
|
||||||
|
password_set,
|
||||||
|
link_karma,
|
||||||
|
total_karma,
|
||||||
|
name,
|
||||||
|
created,
|
||||||
|
created_utc,
|
||||||
|
comment_karma,
|
||||||
|
});
|
||||||
|
|
||||||
const defaultConfig: Partial<RedditOAuthProviderConfig> = {
|
const defaultConfig: Partial<RedditOAuthProviderConfig> = {
|
||||||
id: "reddit",
|
id: "reddit",
|
||||||
scope: "identity",
|
scope: "identity",
|
||||||
duration: "temporary",
|
duration: "temporary",
|
||||||
profile: ({
|
profile: redditProfileHandler,
|
||||||
is_employee,
|
|
||||||
has_external_account,
|
|
||||||
snoovatar_img,
|
|
||||||
verified,
|
|
||||||
id,
|
|
||||||
over_18,
|
|
||||||
is_gold,
|
|
||||||
is_mod,
|
|
||||||
awarder_karma,
|
|
||||||
has_verified_email,
|
|
||||||
is_suspended,
|
|
||||||
icon_img,
|
|
||||||
pref_nightmode,
|
|
||||||
awardee_karma,
|
|
||||||
password_set,
|
|
||||||
link_karma,
|
|
||||||
total_karma,
|
|
||||||
name,
|
|
||||||
created,
|
|
||||||
created_utc,
|
|
||||||
comment_karma,
|
|
||||||
}) => ({
|
|
||||||
is_employee,
|
|
||||||
has_external_account,
|
|
||||||
snoovatar_img,
|
|
||||||
verified,
|
|
||||||
id,
|
|
||||||
over_18,
|
|
||||||
is_gold,
|
|
||||||
is_mod,
|
|
||||||
awarder_karma,
|
|
||||||
has_verified_email,
|
|
||||||
is_suspended,
|
|
||||||
icon_img,
|
|
||||||
pref_nightmode,
|
|
||||||
awardee_karma,
|
|
||||||
password_set,
|
|
||||||
link_karma,
|
|
||||||
total_karma,
|
|
||||||
name,
|
|
||||||
created,
|
|
||||||
created_utc,
|
|
||||||
comment_karma,
|
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export class RedditOAuthProvider extends OAuth2Provider<RedditOAuthProviderConfig> {
|
export class RedditOAuthProvider extends OAuth2Provider<RedditOAuthProviderConfig> {
|
||||||
@ -67,6 +69,8 @@ export class RedditOAuthProvider extends OAuth2Provider<RedditOAuthProviderConfi
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static profileHandler = redditProfileHandler;
|
||||||
|
|
||||||
async getSigninUrl({ host }: ServerRequest, state: string) {
|
async getSigninUrl({ host }: ServerRequest, state: string) {
|
||||||
const endpoint = "https://www.reddit.com/api/v1/authorize";
|
const endpoint = "https://www.reddit.com/api/v1/authorize";
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user