=============== LIBRARY RULES =============== From library maintainers: - You can certainly check this another repo for skills https://github.com/0xABADBABE-ops/startgg-oauth2-skill ### Getting Started Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/examples/browser/README.md Install dependencies and start the development server. ```bash cd examples/browser npm install npm run dev ``` -------------------------------- ### Setup Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/examples/nextjs/README.md Navigate to the example directory, copy the environment file, install dependencies, and edit the file with your Start.gg client settings. ```bash cd examples/nextjs cp .env.example .env.local # Edit the file with your Start.gg client settings npm install ``` -------------------------------- ### Setup Commands Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/CONTRIBUTING.md Commands to install dependencies, build the project, and run tests. ```bash npm i npm run build npm test ``` -------------------------------- ### Setup Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/examples/node/README.md Commands to set up the Node.js example. ```bash cd examples/node cp .env.example .env # optional npm install ``` -------------------------------- ### Installing from GitHub Packages Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/AGENTS.md Example command to install the package from GitHub Packages. ```bash npm install @${repo_owner}/startgg-oauth2-full ``` -------------------------------- ### Install and Run Dev Server Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/examples/vite/README.md Commands to install dependencies and start the Vite development server. ```bash cd examples/vite npm install npm run dev ``` -------------------------------- ### Run Examples Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/CONTRIBUTING.md Commands to run browser and Node.js examples, including setting environment variables for the Node.js server example. ```bash npm run dev:browser npm run dev:node STARTGG_CLIENT_ID=your_id \ STARTGG_AUTH_URL=https://api.start.gg/oauth/authorize \ STARTGG_TOKEN_URL=https://api.start.gg/oauth/token \ npm run dev:node:server ``` -------------------------------- ### Setup Commands Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/examples/discordjs/README.md Commands to set up the Discord.js bot example, including copying the environment file, editing it, and installing dependencies. ```bash cd examples/discordjs cp .env.example .env # Edit .env with your Discord IDs and Start.gg client info npm install ``` -------------------------------- ### Example: Next.js app Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/README.md Instructions to run the Next.js app example. ```bash cd examples/nextjs && npm install && npm run dev ``` -------------------------------- ### Example: Frontend Vite demo Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/README.md Instructions to run the frontend Vite demo example. ```bash cd examples/vite && npm install && npm run dev ``` -------------------------------- ### Example: Node CLI/server Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/README.md Instructions to run the Node CLI/server example. ```bash cd examples/node && npm install && npm run dev ``` -------------------------------- ### Browser Quick Start: PKCE Flow Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/README.md Example of building the authorization URL for PKCE flow in a browser environment. ```typescript import { buildAuthorizeUrl, StartGGScope } from 'startgg-oauth2-full'; const cfg = { clientId: '', authEndpoint: 'https://api.start.gg/oauth/authorize', redirectUri: 'https://your.app/api/startgg/callback', }; const { url, codeVerifier } = await buildAuthorizeUrl(cfg, { scopes: [StartGGScope.USER_IDENTITY, StartGGScope.USER_EMAIL], state: crypto.randomUUID(), }); sessionStorage.setItem('pkce:verifier', codeVerifier); sessionStorage.setItem('oauth:state', ''); location.href = url; ``` -------------------------------- ### Example: Browser (Vite) Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/README.md Instructions to run the browser example using Vite. ```bash cd examples/browser && npm install && npm run dev ``` -------------------------------- ### Installation Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/README.md Install the library using npm. ```bash npm i startgg-oauth2-full # or copy src/auth/StartGGOAuth2.ts into your project ``` -------------------------------- ### Example: Discord.js bot Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/README.md Instructions to run the Discord.js bot example. ```bash cd examples/discordjs && npm install && npm run dev ``` -------------------------------- ### Callback Quick Start: Token Exchange and Bearer Token Creation Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/README.md Example of handling the callback, exchanging the code for a token, and creating a BearerToken object. ```typescript import { createStartGGAuth2Handler, BearerToken, StartGGScope } from 'startgg-oauth2-full'; const params = new URLSearchParams(location.search); const code = params.get('code')!; const state = params.get('state')!; if (state !== sessionStorage.getItem('oauth:state')) throw new Error('State mismatch'); const handler = createStartGGAuth2Handler({ clientId: '', redirectUri: 'https://your.app/api/startgg/callback', authEndpoint: 'https://api.start.gg/oauth/authorize', tokenEndpoint: 'https://api.start.gg/oauth/token', }); const res = await handler.exchangeToken(code, sessionStorage.getItem('pkce:verifier')!, [ StartGGScope.USER_IDENTITY, StartGGScope.USER_EMAIL, ]); const bearer = BearerToken.fromOAuthResponse(res); fetch('https://api.start.gg/your-endpoint', { headers: bearer.toAuthHeader() }); ``` -------------------------------- ### GitHub Packages Installation Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/README.md Install the library from GitHub Packages, requires setting npm auth token. ```bash npm set //npm.pkg.github.com/:_authToken= npm install @0xabadbabe-ops/startgg-oauth2-full ``` -------------------------------- ### Test Execution Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/README.md Example of running Jest tests for PKCE functionality. ```fish ┬─[playerone@fedora:~/d/startgg-oauth2-full]─[21:08:50]─[G:main =] ╰─>$ npm test -- pkce > startgg-oauth2-full@0.2.0 test > jest --runInBand pkce PASS __tests__/pkce.test.ts PKCE helpers ✓ generateCodeVerifier length bounds (4 ms) ✓ computeCodeChallengeS256 deterministic (3 ms) Test Suites: 1 passed, 1 total Tests: 2 passed, 2 total Snapshots: 0 total Time: 0.641 s, estimated 1 s Ran all test suites matching /pkce/i. ┬─[playerone@fedora:~/d/startgg-oauth2-full]─[21:10:09]─[G:main =] ╰─>$ [0] 0:fish* "~/d/startgg-oauth2-fu" 21:10 30-lis-25 ``` -------------------------------- ### Running the Bot Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/examples/discordjs/README.md Command to run the Discord.js bot example. ```bash npm run dev ``` -------------------------------- ### Commit Message Format Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/AGENTS.md Example of the recommended commit message format. ```bash fix(pkce): cap verifier length ``` -------------------------------- ### Node Catcher Environment Variables Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/STARTGG_OAUTH_SETUP.md Environment variables required for the Node.js catcher server and the command to run it. ```bash export STARTGG_CLIENT_ID=your_client_id export STARTGG_AUTH_URL=https://api.start.gg/oauth/authorize export STARTGG_TOKEN_URL=https://api.start.gg/oauth/token npm run dev:node:server ``` -------------------------------- ### Production Build Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/examples/nextjs/README.md Build the Next.js application for production and start the production server. ```bash npm run build npm start ``` -------------------------------- ### Build, Test, and Development Commands Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/AGENTS.md Commands for building, testing, and running interactive demos of the OAuth2 helpers. ```bash npm run build npm test npm run dev:node npm run dev:node:server npm run dev:browser ``` -------------------------------- ### Production Build Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/examples/browser/README.md Build static assets for production and preview them locally. ```bash npm run build npm run preview ``` -------------------------------- ### Build Script Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/README.md Command to build the project using TypeScript compiler. ```bash npm run build ``` -------------------------------- ### Test Script Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/README.md Command to run Jest tests. ```bash npm test ``` -------------------------------- ### Scopes Enum Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/README.md Defines the available scopes for start.gg OAuth2 authentication. ```typescript enum StartGGScope { USER_IDENTITY = 'user.identity', USER_EMAIL = 'user.email', TOURNAMENT_MANAGER = 'tournament.manager', TOURNAMENT_REPORTER = 'tournament.reporter', } ``` -------------------------------- ### OAuth2 Error Class Source: https://github.com/0xabadbabe-ops/startgg-oauth2-full/blob/main/README.md Defines the structure for OAuth2 errors, including optional code and details. ```typescript class OAuth2Error extends Error { code?: string; // e.g., TOKEN_EXCHANGE_FAILED details?: unknown; // parsed JSON or { raw: string } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.