@hamur/auth 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +14 -2
- package/dist/chunks/bun-index-0grce57w.js +47 -0
- package/dist/chunks/bun-index-nn9z2k40.js +92 -0
- package/dist/chunks/bun-index-pmpez2a8.js +10 -0
- package/dist/chunks/bun-index-r6757s88.js +206 -0
- package/dist/src/adapters/angular.js +63 -0
- package/dist/src/adapters/html.js +29 -0
- package/dist/src/adapters/preact.js +37 -0
- package/dist/src/adapters/react.js +32 -0
- package/dist/src/adapters/solid.js +45 -0
- package/dist/src/adapters/svelte.js +44 -0
- package/dist/src/adapters/vue.js +55 -0
- package/dist/src/index.js +688 -0
- package/dist/src/middleware.js +45 -0
- package/dist/src/route-middleware.js +42 -0
- package/dist/src/server/index.js +2971 -0
- package/dist/types/src/adapters/angular.d.ts +32 -0
- package/dist/types/src/adapters/html.d.ts +15 -0
- package/dist/types/src/adapters/preact.d.ts +19 -0
- package/dist/types/src/adapters/react.d.ts +19 -0
- package/dist/types/src/adapters/solid.d.ts +25 -0
- package/dist/types/src/adapters/svelte-session.d.ts +8 -0
- package/dist/types/src/adapters/svelte-webauthn.d.ts +8 -0
- package/dist/types/src/adapters/svelte.d.ts +5 -0
- package/dist/types/src/adapters/vue.d.ts +25 -0
- package/dist/types/src/build/access-tokens.d.ts +4 -0
- package/dist/types/src/build/client.d.ts +4 -0
- package/dist/types/src/build/dev-key.d.ts +6 -0
- package/dist/types/src/build/email.d.ts +4 -0
- package/dist/types/src/build/guards.d.ts +4 -0
- package/dist/types/src/build/module-entry.d.ts +3 -0
- package/dist/types/src/build/oauth.d.ts +8 -0
- package/dist/types/src/build/session.d.ts +6 -0
- package/dist/types/src/build/single-use.d.ts +15 -0
- package/dist/types/src/build/webauthn.d.ts +7 -0
- package/dist/types/src/client/webauthn.d.ts +37 -0
- package/dist/types/src/index.d.ts +43 -0
- package/dist/types/src/middleware.d.ts +4 -0
- package/dist/types/src/module.d.ts +3 -0
- package/dist/types/src/options.d.ts +4 -0
- package/dist/types/src/route-middleware.d.ts +2 -0
- package/dist/types/src/runtime/middleware/auth.d.ts +3 -0
- package/dist/types/src/runtime/middleware/guest.d.ts +3 -0
- package/dist/types/src/runtime/payload.d.ts +2 -0
- package/dist/types/src/runtime/plugin.d.ts +2 -0
- package/dist/types/src/runtime/store.d.ts +28 -0
- package/dist/types/src/runtime/targets.d.ts +4 -0
- package/dist/types/src/server/access-token.d.ts +27 -0
- package/dist/types/src/server/auth-link.d.ts +15 -0
- package/dist/types/src/server/door.d.ts +4 -0
- package/dist/types/src/server/endpoint.d.ts +8 -0
- package/dist/types/src/server/guard.d.ts +12 -0
- package/dist/types/src/server/hooks.d.ts +5 -0
- package/dist/types/src/server/index.d.ts +88 -0
- package/dist/types/src/server/oauth/atproto-dns.d.ts +1 -0
- package/dist/types/src/server/oauth/atproto-fetch.d.ts +13 -0
- package/dist/types/src/server/oauth/atproto-metadata.d.ts +1 -0
- package/dist/types/src/server/oauth/atproto.d.ts +36 -0
- package/dist/types/src/server/oauth/cookie.d.ts +17 -0
- package/dist/types/src/server/oauth/dpop.d.ts +4 -0
- package/dist/types/src/server/oauth/handler.d.ts +101 -0
- package/dist/types/src/server/oauth/oidc.d.ts +20 -0
- package/dist/types/src/server/oauth/providers/apple.d.ts +26 -0
- package/dist/types/src/server/oauth/providers/atlassian.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/auth0.d.ts +9 -0
- package/dist/types/src/server/oauth/providers/authentik.d.ts +9 -0
- package/dist/types/src/server/oauth/providers/azureb2c.d.ts +11 -0
- package/dist/types/src/server/oauth/providers/battledotnet.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/box.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/catalog.d.ts +12 -0
- package/dist/types/src/server/oauth/providers/cloudflare.d.ts +11 -0
- package/dist/types/src/server/oauth/providers/cognito.d.ts +9 -0
- package/dist/types/src/server/oauth/providers/discord.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/dropbox.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/facebook.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/gitea.d.ts +9 -0
- package/dist/types/src/server/oauth/providers/github.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/gitlab.d.ts +9 -0
- package/dist/types/src/server/oauth/providers/google.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/heroku.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/hubspot.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/instagram.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/keycloak.d.ts +11 -0
- package/dist/types/src/server/oauth/providers/kick.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/line.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/linear.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/linkedin.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/livechat.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/mastodon.d.ts +9 -0
- package/dist/types/src/server/oauth/providers/microsoft.d.ts +9 -0
- package/dist/types/src/server/oauth/providers/okta.d.ts +9 -0
- package/dist/types/src/server/oauth/providers/ory.d.ts +9 -0
- package/dist/types/src/server/oauth/providers/osu.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/paypal.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/polar.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/preset.d.ts +74 -0
- package/dist/types/src/server/oauth/providers/riotgames.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/roblox.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/salesforce.d.ts +9 -0
- package/dist/types/src/server/oauth/providers/seznam.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/shopifyCustomer.d.ts +9 -0
- package/dist/types/src/server/oauth/providers/slack.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/spotify.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/steam.d.ts +23 -0
- package/dist/types/src/server/oauth/providers/strava.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/tiktok.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/twitch.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/vk.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/wechat.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/workos.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/x.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/xsuaa.d.ts +9 -0
- package/dist/types/src/server/oauth/providers/yandex.d.ts +5 -0
- package/dist/types/src/server/oauth/providers/zendesk.d.ts +9 -0
- package/dist/types/src/server/oauth/providers/zitadel.d.ts +9 -0
- package/dist/types/src/server/personal.d.ts +5 -0
- package/dist/types/src/server/session.d.ts +20 -0
- package/dist/types/src/server/token-requests.d.ts +5 -0
- package/dist/types/src/server/token.d.ts +17 -0
- package/dist/types/src/server/totp.d.ts +28 -0
- package/dist/types/src/server/webauthn/cbor.d.ts +16 -0
- package/dist/types/src/server/webauthn/cose.d.ts +17 -0
- package/dist/types/src/server/webauthn/data.d.ts +20 -0
- package/dist/types/src/server/webauthn/handler.d.ts +63 -0
- package/dist/types/src/single-use.d.ts +17 -0
- package/dist/types/src/types.d.ts +88 -0
- package/package.json +122 -4
- package/src/adapters/AuthState.svelte +14 -0
- package/src/adapters/angular.ts +80 -0
- package/src/adapters/html.ts +39 -0
- package/src/adapters/preact.ts +53 -0
- package/src/adapters/react.ts +49 -0
- package/src/adapters/solid.ts +64 -0
- package/src/adapters/svelte-session.ts +21 -0
- package/src/adapters/svelte-webauthn.ts +20 -0
- package/src/adapters/svelte.ts +5 -0
- package/src/adapters/vue.ts +70 -0
- package/src/build/access-tokens.ts +44 -0
- package/src/build/client.ts +16 -0
- package/src/build/dev-key.ts +29 -0
- package/src/build/email.ts +32 -0
- package/src/build/guards.ts +12 -0
- package/src/build/module-entry.ts +8 -0
- package/src/build/oauth.ts +54 -0
- package/src/build/session.ts +54 -0
- package/src/build/single-use.ts +104 -0
- package/src/build/webauthn.ts +28 -0
- package/src/client/webauthn.ts +129 -0
- package/src/env.d.ts +84 -0
- package/src/index.ts +44 -0
- package/src/middleware.ts +9 -0
- package/src/module.ts +26 -0
- package/src/options.ts +241 -0
- package/src/route-middleware.ts +2 -0
- package/src/runtime/middleware/auth.ts +16 -0
- package/src/runtime/middleware/guest.ts +17 -0
- package/src/runtime/payload.ts +40 -0
- package/src/runtime/plugin.ts +12 -0
- package/src/runtime/store.ts +72 -0
- package/src/runtime/targets.ts +9 -0
- package/src/server/access-token.ts +130 -0
- package/src/server/auth-link.ts +95 -0
- package/src/server/door.ts +33 -0
- package/src/server/endpoint.ts +33 -0
- package/src/server/guard.ts +41 -0
- package/src/server/hooks.ts +13 -0
- package/src/server/index.ts +96 -0
- package/src/server/oauth/atproto-dns.ts +3 -0
- package/src/server/oauth/atproto-fetch.ts +67 -0
- package/src/server/oauth/atproto-metadata.ts +20 -0
- package/src/server/oauth/atproto.ts +292 -0
- package/src/server/oauth/cookie.ts +38 -0
- package/src/server/oauth/dpop.ts +32 -0
- package/src/server/oauth/handler.ts +377 -0
- package/src/server/oauth/oidc.ts +283 -0
- package/src/server/oauth/providers/apple.ts +108 -0
- package/src/server/oauth/providers/atlassian.ts +20 -0
- package/src/server/oauth/providers/auth0.ts +29 -0
- package/src/server/oauth/providers/authentik.ts +29 -0
- package/src/server/oauth/providers/azureb2c.ts +41 -0
- package/src/server/oauth/providers/battledotnet.ts +21 -0
- package/src/server/oauth/providers/box.ts +19 -0
- package/src/server/oauth/providers/catalog.ts +73 -0
- package/src/server/oauth/providers/cloudflare.ts +34 -0
- package/src/server/oauth/providers/cognito.ts +29 -0
- package/src/server/oauth/providers/discord.ts +19 -0
- package/src/server/oauth/providers/dropbox.ts +26 -0
- package/src/server/oauth/providers/facebook.ts +19 -0
- package/src/server/oauth/providers/gitea.ts +29 -0
- package/src/server/oauth/providers/github.ts +33 -0
- package/src/server/oauth/providers/gitlab.ts +29 -0
- package/src/server/oauth/providers/google.ts +19 -0
- package/src/server/oauth/providers/heroku.ts +28 -0
- package/src/server/oauth/providers/hubspot.ts +27 -0
- package/src/server/oauth/providers/instagram.ts +32 -0
- package/src/server/oauth/providers/keycloak.ts +31 -0
- package/src/server/oauth/providers/kick.ts +26 -0
- package/src/server/oauth/providers/line.ts +19 -0
- package/src/server/oauth/providers/linear.ts +34 -0
- package/src/server/oauth/providers/linkedin.ts +20 -0
- package/src/server/oauth/providers/livechat.ts +19 -0
- package/src/server/oauth/providers/mastodon.ts +29 -0
- package/src/server/oauth/providers/microsoft.ts +29 -0
- package/src/server/oauth/providers/okta.ts +29 -0
- package/src/server/oauth/providers/ory.ts +29 -0
- package/src/server/oauth/providers/osu.ts +19 -0
- package/src/server/oauth/providers/paypal.ts +19 -0
- package/src/server/oauth/providers/polar.ts +19 -0
- package/src/server/oauth/providers/preset.ts +206 -0
- package/src/server/oauth/providers/riotgames.ts +19 -0
- package/src/server/oauth/providers/roblox.ts +19 -0
- package/src/server/oauth/providers/salesforce.ts +29 -0
- package/src/server/oauth/providers/seznam.ts +19 -0
- package/src/server/oauth/providers/shopifyCustomer.ts +47 -0
- package/src/server/oauth/providers/slack.ts +27 -0
- package/src/server/oauth/providers/spotify.ts +19 -0
- package/src/server/oauth/providers/steam.ts +162 -0
- package/src/server/oauth/providers/strava.ts +20 -0
- package/src/server/oauth/providers/tiktok.ts +22 -0
- package/src/server/oauth/providers/twitch.ts +32 -0
- package/src/server/oauth/providers/vk.ts +36 -0
- package/src/server/oauth/providers/wechat.ts +39 -0
- package/src/server/oauth/providers/workos.ts +19 -0
- package/src/server/oauth/providers/x.ts +19 -0
- package/src/server/oauth/providers/xsuaa.ts +29 -0
- package/src/server/oauth/providers/yandex.ts +26 -0
- package/src/server/oauth/providers/zendesk.ts +29 -0
- package/src/server/oauth/providers/zitadel.ts +29 -0
- package/src/server/personal.ts +17 -0
- package/src/server/session.ts +150 -0
- package/src/server/token-requests.ts +13 -0
- package/src/server/token.ts +81 -0
- package/src/server/totp.ts +165 -0
- package/src/server/webauthn/cbor.ts +154 -0
- package/src/server/webauthn/cose.ts +95 -0
- package/src/server/webauthn/data.ts +50 -0
- package/src/server/webauthn/handler.ts +510 -0
- package/src/single-use.ts +41 -0
- package/src/types.ts +91 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { providerJSON } from "../handler.ts"
|
|
3
|
+
import { presetHandler, userOf, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
4
|
+
|
|
5
|
+
/** Instagram documents its answers wrapped as `{ data: [ … ] }`; a flat answer is taken as it is. */
|
|
6
|
+
const unwrap = (answer: Record<string, unknown>): unknown => (Array.isArray(answer.data) ? answer.data[0] : answer)
|
|
7
|
+
|
|
8
|
+
export const instagram: OAuthPreset = {
|
|
9
|
+
name: "instagram",
|
|
10
|
+
record: () => ({
|
|
11
|
+
authorizationURL: "https://www.instagram.com/oauth/authorize",
|
|
12
|
+
tokenURL: "https://api.instagram.com/oauth/access_token",
|
|
13
|
+
scope: ["instagram_business_basic"],
|
|
14
|
+
tokenAuth: "client_secret_post",
|
|
15
|
+
pkce: false,
|
|
16
|
+
tokenRequest: async ({ event, url, headers, body }) =>
|
|
17
|
+
userOf(unwrap(await providerJSON(event, url, { method: "POST", headers, body }, "token request"))),
|
|
18
|
+
// graph.instagram.com documents the token as the access_token query parameter.
|
|
19
|
+
profile: ({ event, tokens }) => {
|
|
20
|
+
const target = new URL("https://graph.instagram.com/me")
|
|
21
|
+
target.searchParams.set("fields", "user_id,username,name,account_type,profile_picture_url")
|
|
22
|
+
target.searchParams.set("access_token", tokens.access_token)
|
|
23
|
+
return providerJSON(event, target.href, { headers: { accept: "application/json" } }, "user request")
|
|
24
|
+
},
|
|
25
|
+
mapUser: (profile) => userOf(unwrap(profile)),
|
|
26
|
+
}),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Sign in with Instagram (Instagram API with Instagram Login); `user` is the Graph `GET /me` profile. */
|
|
30
|
+
export function oauthInstagram(options: OAuthPresetOptions): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
31
|
+
return presetHandler(instagram, options)
|
|
32
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { originOf, presetHandler, requireKey, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
3
|
+
|
|
4
|
+
export interface KeycloakConfig {
|
|
5
|
+
/** The Keycloak server, `https://sso.example.com`; required. */
|
|
6
|
+
serverURL?: string
|
|
7
|
+
/** The realm; required. */
|
|
8
|
+
realm?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const keycloak: OAuthPreset<KeycloakConfig> = {
|
|
12
|
+
name: "keycloak",
|
|
13
|
+
record: (config) => {
|
|
14
|
+
const base = `${originOf(requireKey("keycloak", config, "serverURL"))}/realms/${encodeURIComponent(requireKey("keycloak", config, "realm"))}/protocol/openid-connect`
|
|
15
|
+
return {
|
|
16
|
+
authorizationURL: `${base}/auth`,
|
|
17
|
+
tokenURL: `${base}/token`,
|
|
18
|
+
userURL: `${base}/userinfo`,
|
|
19
|
+
scope: ["openid"],
|
|
20
|
+
tokenAuth: "client_secret_basic",
|
|
21
|
+
mapUser: (profile) => profile,
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Sign in with Keycloak; `user` is the OpenID userinfo. */
|
|
27
|
+
export function oauthKeycloak(
|
|
28
|
+
options: OAuthPresetOptions & KeycloakConfig,
|
|
29
|
+
): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
30
|
+
return presetHandler(keycloak, options)
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { providerJSON } from "../handler.ts"
|
|
3
|
+
import { presetHandler, userOf, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
4
|
+
|
|
5
|
+
export const kick: OAuthPreset = {
|
|
6
|
+
name: "kick",
|
|
7
|
+
record: () => ({
|
|
8
|
+
authorizationURL: "https://id.kick.com/oauth/authorize",
|
|
9
|
+
tokenURL: "https://id.kick.com/oauth/token",
|
|
10
|
+
scope: ["user:read"],
|
|
11
|
+
tokenAuth: "client_secret_post",
|
|
12
|
+
profile: ({ event, tokens }) =>
|
|
13
|
+
providerJSON(
|
|
14
|
+
event,
|
|
15
|
+
"https://api.kick.com/public/v1/users",
|
|
16
|
+
{ headers: { authorization: `Bearer ${tokens.access_token}`, accept: "application/json" } },
|
|
17
|
+
"user request",
|
|
18
|
+
),
|
|
19
|
+
mapUser: (profile) => userOf(profile.data?.[0]),
|
|
20
|
+
}),
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Sign in with Kick; `user` is the first of `GET /public/v1/users`'s `data`. */
|
|
24
|
+
export function oauthKick(options: OAuthPresetOptions): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
25
|
+
return presetHandler(kick, options)
|
|
26
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { presetHandler, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
3
|
+
|
|
4
|
+
export const line: OAuthPreset = {
|
|
5
|
+
name: "line",
|
|
6
|
+
record: () => ({
|
|
7
|
+
authorizationURL: "https://access.line.me/oauth2/v2.1/authorize",
|
|
8
|
+
tokenURL: "https://api.line.me/oauth2/v2.1/token",
|
|
9
|
+
userURL: "https://api.line.me/v2/profile",
|
|
10
|
+
scope: ["openid", "profile"],
|
|
11
|
+
tokenAuth: "client_secret_post",
|
|
12
|
+
mapUser: (profile) => profile,
|
|
13
|
+
}),
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Sign in with Line; `user` is the `GET /v2/profile` profile (`userId`, `displayName`, `pictureUrl`). */
|
|
17
|
+
export function oauthLine(options: OAuthPresetOptions): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
18
|
+
return presetHandler(line, options)
|
|
19
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { providerJSON } from "../handler.ts"
|
|
3
|
+
import { presetHandler, userOf, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
4
|
+
|
|
5
|
+
export const linear: OAuthPreset = {
|
|
6
|
+
name: "linear",
|
|
7
|
+
record: () => ({
|
|
8
|
+
authorizationURL: "https://linear.app/oauth/authorize",
|
|
9
|
+
tokenURL: "https://api.linear.app/oauth/token",
|
|
10
|
+
scope: ["read"],
|
|
11
|
+
tokenAuth: "client_secret_post",
|
|
12
|
+
profile: ({ event, tokens }) =>
|
|
13
|
+
providerJSON(
|
|
14
|
+
event,
|
|
15
|
+
"https://api.linear.app/graphql",
|
|
16
|
+
{
|
|
17
|
+
method: "POST",
|
|
18
|
+
headers: {
|
|
19
|
+
authorization: `Bearer ${tokens.access_token}`,
|
|
20
|
+
accept: "application/json",
|
|
21
|
+
"content-type": "application/json",
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify({ query: "{ viewer { id name displayName email avatarUrl } }" }),
|
|
24
|
+
},
|
|
25
|
+
"user request",
|
|
26
|
+
),
|
|
27
|
+
mapUser: (profile) => userOf(profile.data?.viewer),
|
|
28
|
+
}),
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Sign in with Linear; `user` is the GraphQL `viewer` (`id`, `name`, `displayName`, `email`, `avatarUrl`). */
|
|
32
|
+
export function oauthLinear(options: OAuthPresetOptions): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
33
|
+
return presetHandler(linear, options)
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { presetHandler, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
3
|
+
|
|
4
|
+
export const linkedin: OAuthPreset = {
|
|
5
|
+
name: "linkedin",
|
|
6
|
+
record: () => ({
|
|
7
|
+
authorizationURL: "https://www.linkedin.com/oauth/v2/authorization",
|
|
8
|
+
tokenURL: "https://www.linkedin.com/oauth/v2/accessToken",
|
|
9
|
+
userURL: "https://api.linkedin.com/v2/userinfo",
|
|
10
|
+
scope: ["openid", "profile", "email"],
|
|
11
|
+
tokenAuth: "client_secret_post",
|
|
12
|
+
pkce: false,
|
|
13
|
+
mapUser: (profile) => profile,
|
|
14
|
+
}),
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Sign in with LinkedIn; `user` is the OpenID userinfo. */
|
|
18
|
+
export function oauthLinkedIn(options: OAuthPresetOptions): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
19
|
+
return presetHandler(linkedin, options)
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { presetHandler, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
3
|
+
|
|
4
|
+
export const livechat: OAuthPreset = {
|
|
5
|
+
name: "livechat",
|
|
6
|
+
record: () => ({
|
|
7
|
+
authorizationURL: "https://accounts.livechat.com/",
|
|
8
|
+
tokenURL: "https://accounts.livechat.com/v2/token",
|
|
9
|
+
userURL: "https://accounts.livechat.com/v2/accounts/me",
|
|
10
|
+
scope: [],
|
|
11
|
+
tokenAuth: "client_secret_post",
|
|
12
|
+
mapUser: (profile) => profile,
|
|
13
|
+
}),
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Sign in with LiveChat; `user` is the `GET /v2/accounts/me` account. */
|
|
17
|
+
export function oauthLiveChat(options: OAuthPresetOptions): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
18
|
+
return presetHandler(livechat, options)
|
|
19
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { originOf, presetHandler, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
3
|
+
|
|
4
|
+
export interface MastodonConfig {
|
|
5
|
+
/** The instance; default `https://mastodon.social`. */
|
|
6
|
+
baseURL?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const mastodon: OAuthPreset<MastodonConfig> = {
|
|
10
|
+
name: "mastodon",
|
|
11
|
+
record: ({ baseURL = "https://mastodon.social" }) => {
|
|
12
|
+
const base = originOf(baseURL)
|
|
13
|
+
return {
|
|
14
|
+
authorizationURL: `${base}/oauth/authorize`,
|
|
15
|
+
tokenURL: `${base}/oauth/token`,
|
|
16
|
+
userURL: `${base}/api/v1/accounts/verify_credentials`,
|
|
17
|
+
scope: ["read:accounts"],
|
|
18
|
+
tokenAuth: "client_secret_post",
|
|
19
|
+
mapUser: (profile) => profile,
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Sign in with Mastodon; `user` is the `verify_credentials` account. */
|
|
25
|
+
export function oauthMastodon(
|
|
26
|
+
options: OAuthPresetOptions & MastodonConfig,
|
|
27
|
+
): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
28
|
+
return presetHandler(mastodon, options)
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { presetHandler, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
3
|
+
|
|
4
|
+
export interface MicrosoftConfig {
|
|
5
|
+
/** `common` (default), `organizations`, `consumers` or a tenant id or domain. */
|
|
6
|
+
tenant?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const microsoft: OAuthPreset<MicrosoftConfig> = {
|
|
10
|
+
name: "microsoft",
|
|
11
|
+
record: ({ tenant = "common" }) => {
|
|
12
|
+
const base = `https://login.microsoftonline.com/${encodeURIComponent(tenant)}/oauth2/v2.0`
|
|
13
|
+
return {
|
|
14
|
+
authorizationURL: `${base}/authorize`,
|
|
15
|
+
tokenURL: `${base}/token`,
|
|
16
|
+
userURL: "https://graph.microsoft.com/v1.0/me",
|
|
17
|
+
scope: ["User.Read"],
|
|
18
|
+
tokenAuth: "client_secret_post",
|
|
19
|
+
mapUser: (profile) => profile,
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Sign in with a Microsoft account; `user` is the Graph `GET /me` profile. */
|
|
25
|
+
export function oauthMicrosoft(
|
|
26
|
+
options: OAuthPresetOptions & MicrosoftConfig,
|
|
27
|
+
): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
28
|
+
return presetHandler(microsoft, options)
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { originOf, presetHandler, requireKey, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
3
|
+
|
|
4
|
+
export interface OktaConfig {
|
|
5
|
+
/** The Okta org, `example.okta.com`; required. */
|
|
6
|
+
domain?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const okta: OAuthPreset<OktaConfig> = {
|
|
10
|
+
name: "okta",
|
|
11
|
+
record: (config) => {
|
|
12
|
+
const base = originOf(requireKey("okta", config, "domain"))
|
|
13
|
+
return {
|
|
14
|
+
authorizationURL: `${base}/oauth2/v1/authorize`,
|
|
15
|
+
tokenURL: `${base}/oauth2/v1/token`,
|
|
16
|
+
userURL: `${base}/oauth2/v1/userinfo`,
|
|
17
|
+
scope: ["openid", "profile", "email"],
|
|
18
|
+
tokenAuth: "client_secret_basic",
|
|
19
|
+
mapUser: (profile) => profile,
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Sign in with Okta; `user` is the OpenID userinfo. */
|
|
25
|
+
export function oauthOkta(
|
|
26
|
+
options: OAuthPresetOptions & OktaConfig,
|
|
27
|
+
): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
28
|
+
return presetHandler(okta, options)
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { originOf, presetHandler, requireKey, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
3
|
+
|
|
4
|
+
export interface OryConfig {
|
|
5
|
+
/** The project URL, `<slug>.projects.oryapis.com` or a custom domain; required. */
|
|
6
|
+
domain?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const ory: OAuthPreset<OryConfig> = {
|
|
10
|
+
name: "ory",
|
|
11
|
+
record: (config) => {
|
|
12
|
+
const base = originOf(requireKey("ory", config, "domain"))
|
|
13
|
+
return {
|
|
14
|
+
authorizationURL: `${base}/oauth2/auth`,
|
|
15
|
+
tokenURL: `${base}/oauth2/token`,
|
|
16
|
+
userURL: `${base}/userinfo`,
|
|
17
|
+
scope: ["openid", "email"],
|
|
18
|
+
tokenAuth: "client_secret_basic",
|
|
19
|
+
mapUser: (profile) => profile,
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Sign in with Ory; `user` is the OpenID userinfo. */
|
|
25
|
+
export function oauthOry(
|
|
26
|
+
options: OAuthPresetOptions & OryConfig,
|
|
27
|
+
): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
28
|
+
return presetHandler(ory, options)
|
|
29
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { presetHandler, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
3
|
+
|
|
4
|
+
export const osu: OAuthPreset = {
|
|
5
|
+
name: "osu",
|
|
6
|
+
record: () => ({
|
|
7
|
+
authorizationURL: "https://osu.ppy.sh/oauth/authorize",
|
|
8
|
+
tokenURL: "https://osu.ppy.sh/oauth/token",
|
|
9
|
+
userURL: "https://osu.ppy.sh/api/v2/me",
|
|
10
|
+
scope: ["identify"],
|
|
11
|
+
tokenAuth: "client_secret_post",
|
|
12
|
+
mapUser: (profile) => profile,
|
|
13
|
+
}),
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Sign in with Osu; `user` is the `GET /api/v2/me` user. */
|
|
17
|
+
export function oauthOsu(options: OAuthPresetOptions): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
18
|
+
return presetHandler(osu, options)
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { presetHandler, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
3
|
+
|
|
4
|
+
export const paypal: OAuthPreset = {
|
|
5
|
+
name: "paypal",
|
|
6
|
+
record: () => ({
|
|
7
|
+
authorizationURL: "https://www.paypal.com/signin/authorize",
|
|
8
|
+
tokenURL: "https://api-m.paypal.com/v1/oauth2/token",
|
|
9
|
+
userURL: "https://api-m.paypal.com/v1/identity/openidconnect/userinfo?schema=openid",
|
|
10
|
+
scope: ["openid", "profile", "email"],
|
|
11
|
+
tokenAuth: "client_secret_basic",
|
|
12
|
+
mapUser: (profile) => profile,
|
|
13
|
+
}),
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Sign in with PayPal; `user` is the OpenID userinfo. */
|
|
17
|
+
export function oauthPayPal(options: OAuthPresetOptions): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
18
|
+
return presetHandler(paypal, options)
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { presetHandler, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
3
|
+
|
|
4
|
+
export const polar: OAuthPreset = {
|
|
5
|
+
name: "polar",
|
|
6
|
+
record: () => ({
|
|
7
|
+
authorizationURL: "https://polar.sh/oauth2/authorize",
|
|
8
|
+
tokenURL: "https://api.polar.sh/v1/oauth2/token",
|
|
9
|
+
userURL: "https://api.polar.sh/v1/oauth2/userinfo",
|
|
10
|
+
scope: ["openid", "email"],
|
|
11
|
+
tokenAuth: "client_secret_post",
|
|
12
|
+
mapUser: (profile) => profile,
|
|
13
|
+
}),
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Sign in with Polar; `user` is the OpenID userinfo. */
|
|
17
|
+
export function oauthPolar(options: OAuthPresetOptions): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
18
|
+
return presetHandler(polar, options)
|
|
19
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/// <reference path="../../../env.d.ts" />
|
|
2
|
+
import { oauth as configured } from "#hamur/auth/oauth"
|
|
3
|
+
import {
|
|
4
|
+
createError,
|
|
5
|
+
JWTError,
|
|
6
|
+
verifyJWT,
|
|
7
|
+
type HandlerContext,
|
|
8
|
+
type JWTAlgorithm,
|
|
9
|
+
type JWTPayload,
|
|
10
|
+
type Secret,
|
|
11
|
+
type HamurEvent,
|
|
12
|
+
} from "hamur/server"
|
|
13
|
+
import { isEnvRef, readSecret } from "hamur/server/internal"
|
|
14
|
+
import {
|
|
15
|
+
createOAuthHandler,
|
|
16
|
+
type OAuthError,
|
|
17
|
+
type OAuthHandlerOptions,
|
|
18
|
+
type OAuthPresetHooks,
|
|
19
|
+
type OAuthTokens,
|
|
20
|
+
} from "../handler.ts"
|
|
21
|
+
import { OAUTH_PROVIDERS, providerKeys } from "./catalog.ts"
|
|
22
|
+
|
|
23
|
+
/** The options every `oauth<Name>` takes; a provider adds its config keys. */
|
|
24
|
+
export interface OAuthPresetBaseOptions<User = Record<string, unknown>> {
|
|
25
|
+
onSuccess(event: HamurEvent, result: { user: User; tokens: OAuthTokens }): unknown
|
|
26
|
+
onError?(event: HamurEvent, error: OAuthError): unknown
|
|
27
|
+
/** Replaces the provider's default scopes. */
|
|
28
|
+
scope?: string[]
|
|
29
|
+
authorizationParams?: Record<string, string>
|
|
30
|
+
redirectURL?: string
|
|
31
|
+
/** Default `auth.oauth.<name>.clientId`. */
|
|
32
|
+
clientId?: Secret
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The options of a preset with a client secret. */
|
|
36
|
+
export interface OAuthPresetOptions<User = Record<string, unknown>> extends OAuthPresetBaseOptions<User> {
|
|
37
|
+
/** Default `auth.oauth.<name>.clientSecret`. */
|
|
38
|
+
clientSecret?: Secret
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A config key of the preset read at a request: its text, else the 500 that names where to set it. */
|
|
42
|
+
export type ReadKey = (event: HamurEvent, key: string) => string
|
|
43
|
+
|
|
44
|
+
/** What a provider adds to the engine, made from its config keys. */
|
|
45
|
+
export interface OAuthPresetRecord {
|
|
46
|
+
authorizationURL: string
|
|
47
|
+
tokenURL: string
|
|
48
|
+
userURL?: string
|
|
49
|
+
scope: string[]
|
|
50
|
+
tokenAuth?: OAuthHandlerOptions["tokenAuth"]
|
|
51
|
+
responseMode?: OAuthHandlerOptions["responseMode"]
|
|
52
|
+
pkce?: boolean
|
|
53
|
+
issuer?: string
|
|
54
|
+
authorizationParams?: Record<string, string>
|
|
55
|
+
/** A client secret the preset makes, in place of reading `clientSecret`. */
|
|
56
|
+
clientSecret?(context: { event: HamurEvent; clientId: string; read: ReadKey }): Promise<string>
|
|
57
|
+
profile?: OAuthPresetHooks["profile"]
|
|
58
|
+
clientIdParam?: string
|
|
59
|
+
tokenRequest?: OAuthPresetHooks["tokenRequest"]
|
|
60
|
+
/** A provider that joins scopes with another separator (Strava, TikTok: `,`) gets them as one `scope` parameter so. */
|
|
61
|
+
scopeSeparator?: string
|
|
62
|
+
/** Appends the client id to the default scopes at the start. */
|
|
63
|
+
clientIdScope?: boolean
|
|
64
|
+
mapUser(profile: any, tokens: OAuthTokens): unknown
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface OAuthPreset<Config = {}> {
|
|
68
|
+
name: string
|
|
69
|
+
record(config: Config): OAuthPresetRecord
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type Values = Record<string, unknown>
|
|
73
|
+
|
|
74
|
+
const CALL_KEYS = new Set(["onSuccess", "onError", "scope", "authorizationParams"])
|
|
75
|
+
|
|
76
|
+
/** The name of the export, `oauthGitHub` for `github`. */
|
|
77
|
+
export const exportName = (name: string): string => `oauth${OAUTH_PROVIDERS[name]!.label}`
|
|
78
|
+
|
|
79
|
+
/** The provider's config: `auth.oauth.<name>` under the options of the call; `""` is unset, and a key the preset does not take throws as the build does for `auth.oauth`. */
|
|
80
|
+
export function presetConfig(name: string, options: Values): Values {
|
|
81
|
+
const config: Values = { ...(configured as Record<string, Values | undefined>)[name] }
|
|
82
|
+
const keys = providerKeys(name)
|
|
83
|
+
for (const [key, value] of Object.entries(options)) {
|
|
84
|
+
if (CALL_KEYS.has(key)) continue
|
|
85
|
+
if (!keys.includes(key))
|
|
86
|
+
throw new TypeError(
|
|
87
|
+
`@hamur/auth: ${exportName(name)} has no ${JSON.stringify(key)} (it takes: ${keys.join(", ")})`,
|
|
88
|
+
)
|
|
89
|
+
if (value !== undefined && value !== "") config[key] = value
|
|
90
|
+
}
|
|
91
|
+
return config
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The user inside a provider's envelope; a profile without one is refused as a failed user request is. */
|
|
95
|
+
export function userOf(value: unknown): Record<string, unknown> {
|
|
96
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) return value as Record<string, unknown>
|
|
97
|
+
throw createError({ status: 401, message: "OAuth token request failed" })
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const CLAIMS: Record<string, string> = {
|
|
101
|
+
algorithm: "alg",
|
|
102
|
+
key: "signature",
|
|
103
|
+
signature: "signature",
|
|
104
|
+
expired: "exp",
|
|
105
|
+
not_before: "nbf",
|
|
106
|
+
issuer: "iss",
|
|
107
|
+
audience: "aud",
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The claims of an `id_token` verified against `jwksUri`; a failure is 401 `Invalid ID token: <claim>`, with the claim named. */
|
|
111
|
+
export async function idTokenClaims(
|
|
112
|
+
token: unknown,
|
|
113
|
+
jwksUri: string,
|
|
114
|
+
options: { issuer?: string; audience: string; algorithms?: JWTAlgorithm[]; clockTolerance?: number },
|
|
115
|
+
): Promise<JWTPayload> {
|
|
116
|
+
let claims: JWTPayload
|
|
117
|
+
try {
|
|
118
|
+
claims = await verifyJWT(
|
|
119
|
+
typeof token === "string" ? token : "",
|
|
120
|
+
{ jwksUri },
|
|
121
|
+
{
|
|
122
|
+
algorithms: options.algorithms ?? ["RS256"],
|
|
123
|
+
...(options.issuer === undefined ? {} : { issuer: options.issuer }),
|
|
124
|
+
audience: options.audience,
|
|
125
|
+
...(options.clockTolerance === undefined ? {} : { clockTolerance: options.clockTolerance }),
|
|
126
|
+
},
|
|
127
|
+
)
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (!(error instanceof JWTError)) throw error
|
|
130
|
+
throw createError({ status: 401, message: `Invalid ID token: ${CLAIMS[error.code] ?? error.code}` })
|
|
131
|
+
}
|
|
132
|
+
if (typeof claims.sub !== "string" || claims.sub === "")
|
|
133
|
+
throw createError({ status: 401, message: "Invalid ID token: sub" })
|
|
134
|
+
return claims
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** `https://<host>` for a host or an origin given with or without its scheme, without a trailing `/`. */
|
|
138
|
+
export function originOf(value: string): string {
|
|
139
|
+
return (/^https?:\/\//i.test(value) ? value : `https://${value}`).replace(/\/+$/, "")
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** A key the preset needs when it is defined (one that shapes its URLs). */
|
|
143
|
+
export function requireKey(name: string, config: object, key: string): string {
|
|
144
|
+
const value = (config as Values)[key]
|
|
145
|
+
if (typeof value !== "string" || value === "")
|
|
146
|
+
throw new TypeError(`@hamur/auth: ${exportName(name)} needs auth.oauth.${name}.${key}`)
|
|
147
|
+
return value
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function reader(name: string, config: Values): ReadKey {
|
|
151
|
+
return (_event, key) => {
|
|
152
|
+
const given = config[key]
|
|
153
|
+
const where = `auth.oauth.${name}.${key}`
|
|
154
|
+
if (isEnvRef(given)) return readSecret(given, `@hamur/auth: ${exportName(name)} ${where}`)
|
|
155
|
+
if (typeof given === "string" && given !== "") return given
|
|
156
|
+
throw new Error(`@hamur/auth: ${exportName(name)} needs ${where}`)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The raw handler body of a preset, its record over the OAuth engine. */
|
|
161
|
+
export function presetHandler<Config>(
|
|
162
|
+
preset: OAuthPreset<Config>,
|
|
163
|
+
options: OAuthPresetBaseOptions<any> & Config,
|
|
164
|
+
): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
165
|
+
const { name } = preset
|
|
166
|
+
const config = presetConfig(name, options as unknown as Values)
|
|
167
|
+
const record = preset.record(config as unknown as Config)
|
|
168
|
+
const read = reader(name, config)
|
|
169
|
+
const tokenAuth = record.tokenAuth ?? "client_secret_basic"
|
|
170
|
+
const scopes = options.scope ?? record.scope
|
|
171
|
+
return createOAuthHandler(
|
|
172
|
+
{
|
|
173
|
+
authorizationURL: record.authorizationURL,
|
|
174
|
+
tokenURL: record.tokenURL,
|
|
175
|
+
...(record.userURL === undefined ? {} : { userURL: record.userURL }),
|
|
176
|
+
clientId: "",
|
|
177
|
+
...(tokenAuth === "none" ? {} : { clientSecret: "" }),
|
|
178
|
+
scope: record.scopeSeparator === undefined ? scopes : [],
|
|
179
|
+
...(record.issuer === undefined ? {} : { issuer: record.issuer }),
|
|
180
|
+
tokenAuth,
|
|
181
|
+
...(record.responseMode === undefined ? {} : { responseMode: record.responseMode }),
|
|
182
|
+
...(record.pkce === undefined ? {} : { pkce: record.pkce }),
|
|
183
|
+
authorizationParams: {
|
|
184
|
+
...record.authorizationParams,
|
|
185
|
+
...(record.scopeSeparator !== undefined && scopes.length ? { scope: scopes.join(record.scopeSeparator) } : {}),
|
|
186
|
+
...options.authorizationParams,
|
|
187
|
+
},
|
|
188
|
+
...(typeof config.redirectURL === "string" ? { redirectURL: config.redirectURL } : {}),
|
|
189
|
+
mapUser: record.mapUser,
|
|
190
|
+
onSuccess: options.onSuccess,
|
|
191
|
+
...(options.onError ? { onError: options.onError } : {}),
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
provider: name,
|
|
195
|
+
clientId: (event) => read(event, "clientId"),
|
|
196
|
+
clientSecret: (event, clientId) =>
|
|
197
|
+
record.clientSecret ? record.clientSecret({ event, clientId, read }) : read(event, "clientSecret"),
|
|
198
|
+
...(record.profile ? { profile: record.profile } : {}),
|
|
199
|
+
...(record.clientIdScope && options.scope === undefined
|
|
200
|
+
? { scope: (clientId: string) => [...record.scope, clientId] }
|
|
201
|
+
: {}),
|
|
202
|
+
...(record.clientIdParam ? { clientIdParam: record.clientIdParam } : {}),
|
|
203
|
+
...(record.tokenRequest ? { tokenRequest: record.tokenRequest } : {}),
|
|
204
|
+
},
|
|
205
|
+
)
|
|
206
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { presetHandler, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
3
|
+
|
|
4
|
+
export const riotgames: OAuthPreset = {
|
|
5
|
+
name: "riotgames",
|
|
6
|
+
record: () => ({
|
|
7
|
+
authorizationURL: "https://auth.riotgames.com/authorize",
|
|
8
|
+
tokenURL: "https://auth.riotgames.com/token",
|
|
9
|
+
userURL: "https://americas.api.riotgames.com/riot/account/v1/accounts/me",
|
|
10
|
+
scope: ["openid"],
|
|
11
|
+
tokenAuth: "client_secret_basic",
|
|
12
|
+
mapUser: (profile) => profile,
|
|
13
|
+
}),
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Sign in with RiotGames; `user` is the Riot account (`puuid`, `gameName`, `tagLine`). */
|
|
17
|
+
export function oauthRiotGames(options: OAuthPresetOptions): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
18
|
+
return presetHandler(riotgames, options)
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { presetHandler, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
3
|
+
|
|
4
|
+
export const roblox: OAuthPreset = {
|
|
5
|
+
name: "roblox",
|
|
6
|
+
record: () => ({
|
|
7
|
+
authorizationURL: "https://apis.roblox.com/oauth/v1/authorize",
|
|
8
|
+
tokenURL: "https://apis.roblox.com/oauth/v1/token",
|
|
9
|
+
userURL: "https://apis.roblox.com/oauth/v1/userinfo",
|
|
10
|
+
scope: ["openid", "profile"],
|
|
11
|
+
tokenAuth: "client_secret_post",
|
|
12
|
+
mapUser: (profile) => profile,
|
|
13
|
+
}),
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Sign in with Roblox; `user` is the OpenID userinfo. */
|
|
17
|
+
export function oauthRoblox(options: OAuthPresetOptions): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
18
|
+
return presetHandler(roblox, options)
|
|
19
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HandlerContext } from "hamur/server"
|
|
2
|
+
import { originOf, presetHandler, type OAuthPreset, type OAuthPresetOptions } from "./preset.ts"
|
|
3
|
+
|
|
4
|
+
export interface SalesforceConfig {
|
|
5
|
+
/** `https://test.salesforce.com` for a sandbox, or the My Domain URL; default `https://login.salesforce.com`. */
|
|
6
|
+
baseURL?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const salesforce: OAuthPreset<SalesforceConfig> = {
|
|
10
|
+
name: "salesforce",
|
|
11
|
+
record: ({ baseURL = "https://login.salesforce.com" }) => {
|
|
12
|
+
const base = originOf(baseURL)
|
|
13
|
+
return {
|
|
14
|
+
authorizationURL: `${base}/services/oauth2/authorize`,
|
|
15
|
+
tokenURL: `${base}/services/oauth2/token`,
|
|
16
|
+
userURL: `${base}/services/oauth2/userinfo`,
|
|
17
|
+
scope: ["openid", "profile", "email"],
|
|
18
|
+
tokenAuth: "client_secret_post",
|
|
19
|
+
mapUser: (profile) => profile,
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Sign in with Salesforce; `user` is the OpenID userinfo. */
|
|
25
|
+
export function oauthSalesforce(
|
|
26
|
+
options: OAuthPresetOptions & SalesforceConfig,
|
|
27
|
+
): (input: unknown, ctx: HandlerContext) => Promise<unknown> {
|
|
28
|
+
return presetHandler(salesforce, options)
|
|
29
|
+
}
|