From 208410dd8c76e010ccac8f75699499b6aa6be97e Mon Sep 17 00:00:00 2001 From: CYP3R Date: Thu, 15 Aug 2024 15:35:11 -0400 Subject: [PATCH] feat(providers): Add Roblox provider (#11515) * Add Roblox provider * Update roblox.ts --------- Co-authored-by: Falco Winkler <8613031+falcowinkler@users.noreply.github.com> --- .github/ISSUE_TEMPLATE/2_bug_provider.yml | 1 + docs/public/img/providers/roblox.svg | 1 + packages/core/src/providers/roblox.ts | 94 +++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 docs/public/img/providers/roblox.svg create mode 100644 packages/core/src/providers/roblox.ts diff --git a/.github/ISSUE_TEMPLATE/2_bug_provider.yml b/.github/ISSUE_TEMPLATE/2_bug_provider.yml index 38bd1e6763..b1974faeeb 100644 --- a/.github/ISSUE_TEMPLATE/2_bug_provider.yml +++ b/.github/ISSUE_TEMPLATE/2_bug_provider.yml @@ -73,6 +73,7 @@ body: - "Patreon" - "Pipedrive" - "Reddit" + - "Roblox" - "Salesforce" - "SimpleLogin" - "Slack" diff --git a/docs/public/img/providers/roblox.svg b/docs/public/img/providers/roblox.svg new file mode 100644 index 0000000000..18b59b7e88 --- /dev/null +++ b/docs/public/img/providers/roblox.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/core/src/providers/roblox.ts b/packages/core/src/providers/roblox.ts new file mode 100644 index 0000000000..e20579af70 --- /dev/null +++ b/packages/core/src/providers/roblox.ts @@ -0,0 +1,94 @@ +/** + *
+ * Built-in Roblox integration. + * + * + * + *
+ * + * @module providers/roblox + */ +import type { OIDCUserConfig, OIDCConfig } from "./index.js" + +/** + * Corresponds to the user structure documented here: + * https://create.roblox.com/docs/cloud/reference/oauth2 (Example User with Profile Scope) + */ +export interface RobloxProfile extends Record { + /* Roblox user id */ + sub: string + + /* Roblox display name */ + name: string + + /* Roblox display name */ + nickname: string + + /* Roblox username */ + preferred_username: string + + /* Creation time of the Roblox account as a Unix timestamp. */ + created_at: number + + /* Roblox account profile URL */ + profile: string + + /* Roblox avatar headshot image. Can be null if the avatar headshot image hasn't yet been generated or has been moderated */ + picture: string | null +} + +/** + * Add Roblox login to your page. + * + * ### Setup + * + * #### Callback URL + * ``` + * https://example.com/api/auth/callback/roblox + * ``` + * + * #### Configuration + *```ts + * import { Auth } from "@auth/core" + * import Roblox from "@auth/providers/roblox" + * + * const request = new Request(origin) + * const response = await Auth(request, { + * providers: [ + * Roblox({ + * clientId: AUTH_ROBLOX_ID, + * clientSecret: AUTH_ROBLOX_SECRET, + * }), + * ], + * }) + * ``` + * + * ### Resources + * + * - [Roblox OAuth documentation](https://create.roblox.com/docs/cloud/open-cloud/oauth2-overview) + * - [Roblox OAuth apps](https://create.roblox.com/dashboard/credentials?activeTab=OAuthTab) + * + * :::info **Disclaimer** + * + * If you think you found a bug in the default configuration, you can [open an issue](https://authjs.dev/new/provider-issue). + * + * Auth.js strictly adheres to the specification and it cannot take responsibility for any deviation from + * the spec by the provider. You can open an issue, but if the problem is non-compliance with the spec, + * we might not pursue a resolution. You can ask for more help in [Discussions](https://authjs.dev/new/github-discussions). + * + * ::: + */ +export default function Roblox( + options: OIDCUserConfig +): OIDCConfig { + return { + id: "roblox", + name: "Roblox", + type: "oidc", + authorization: { params: { scope: "openid profile" } }, + issuer: "https://apis.roblox.com/oauth/", + checks: ["pkce", "state"], + style: { bg: "#5865F2", text: "#fff" }, + options, + } +}