{"_id":"o-auth-lib","_rev":"3-4876cea145b35e1e60f4ce09b4bb9c50","name":"o-auth-lib","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"o-auth-lib","version":"1.0.0","keywords":["oauth","react","typescript","authentication","pkce"],"author":{"name":"dataxis-labs"},"license":"ISC","_id":"o-auth-lib@1.0.0","maintainers":[{"name":"udit-singh","email":"udit6706@gmail.com"}],"homepage":"https://github.com/Dataxis-UditSingh/o-auth-lib#readme","bugs":{"url":"https://github.com/Dataxis-UditSingh/o-auth-lib/issues"},"dist":{"shasum":"bf16c008944e1200362bc53204d0d938b9b68fa0","tarball":"https://registry.npmjs.org/o-auth-lib/-/o-auth-lib-1.0.0.tgz","fileCount":30,"integrity":"sha512-Vxy7KJg5eD6tilqKLwzcBLRSs2P9JPicDGMGFaKPgKFB1YuDThg9lxGYcLWeT/aovwwWOGNSUAmx/UPv1q0wjg==","signatures":[{"sig":"MEQCID2N1tRBn5rPrRJxwBwQh38blZERrBFZdyucNITJGP1zAiBAfEY4Wn/M9519H8pu1D5Wt/wldh9utJvCzlmS2qkWow==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":43477},"main":"dist/index.js","type":"commonjs","types":"dist/index.d.ts","gitHead":"ab8c468966e3289e6a9fd96ff765574110443db5","scripts":{"test":"vitest run","build":"tsc","prepare":"npm run build"},"_npmUser":{"name":"udit-singh","email":"udit6706@gmail.com"},"repository":{"url":"git+https://github.com/Dataxis-UditSingh/o-auth-lib.git","type":"git"},"_npmVersion":"11.12.1","description":"A TypeScript-friendly authentication library for OAuth and custom login flows with PKCE support.","directories":{},"_nodeVersion":"24.15.0","_hasShrinkwrap":false,"devDependencies":{"jsdom":"^29.1.1","vitest":"^4.1.7","typescript":"^5.0.0","@types/node":"^20.0.0","@types/react":"^18.0.0"},"peerDependencies":{"react":"^17 || ^18"},"_npmOperationalInternal":{"tmp":"tmp/o-auth-lib_1.0.0_1780296793971_0.5964477234248937","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"o-auth-lib","version":"1.0.1","keywords":["oauth","react","typescript","authentication","pkce"],"author":{"name":"dataxis-labs"},"license":"ISC","_id":"o-auth-lib@1.0.1","maintainers":[{"name":"udit-singh","email":"udit6706@gmail.com"}],"homepage":"https://github.com/Dataxis-UditSingh/o-auth-lib#readme","bugs":{"url":"https://github.com/Dataxis-UditSingh/o-auth-lib/issues"},"dist":{"shasum":"7f4b437462c87f0cbf21aee7c117b2616dfdd019","tarball":"https://registry.npmjs.org/o-auth-lib/-/o-auth-lib-1.0.1.tgz","fileCount":30,"integrity":"sha512-JFq1CPAQKsP5MQQ4BP2tykKfs42b6bR+4BqLJUPuuZ3K4zd/dFGzBEOIulMFFrgZD/FXz9gzbC/mAgjuCR+zxg==","signatures":[{"sig":"MEQCIG0B5qP1KzJV/I02gBhKZdwVI54kKi/NQBjb+GB44OcyAiBXnMyHD6FgctZf0czS1HXqIHaeHwQrcVjbLzYcsEyFpQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":43484},"main":"dist/index.js","type":"commonjs","types":"dist/index.d.ts","gitHead":"f0dbbe296757c4826c5f1e83a318488d824c3b6b","scripts":{"test":"vitest run","build":"tsc","prepare":"npm run build"},"_npmUser":{"name":"udit-singh","email":"udit6706@gmail.com"},"repository":{"url":"git+https://github.com/Dataxis-UditSingh/o-auth-lib.git","type":"git"},"_npmVersion":"11.12.1","description":"A TypeScript-friendly authentication library for OAuth and custom login flows with PKCE support.","directories":{},"_nodeVersion":"24.15.0","_hasShrinkwrap":false,"devDependencies":{"jsdom":"^29.1.1","vitest":"^4.1.7","typescript":"^5.0.0","@types/node":"^20.0.0","@types/react":"^18.0.0"},"peerDependencies":{"react":"^17 || ^18 || ^19"},"_npmOperationalInternal":{"tmp":"tmp/o-auth-lib_1.0.1_1780298191002_0.6421609310681218","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"o-auth-lib","version":"1.1.0","description":"A TypeScript-friendly authentication library for OAuth and custom login flows with PKCE support.","main":"dist/index.js","module":"dist/index.js","exports":{".":{"import":"./dist/index.js","require":"./dist/index.js"}},"types":"dist/index.d.ts","scripts":{"build":"tsc","prepare":"npm run build","test":"vitest run"},"keywords":["oauth","react","typescript","authentication","pkce"],"author":{"name":"dataxis-labs"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/Dataxis-UditSingh/o-auth-lib.git"},"bugs":{"url":"https://github.com/Dataxis-UditSingh/o-auth-lib/issues"},"homepage":"https://github.com/Dataxis-UditSingh/o-auth-lib#readme","type":"commonjs","peerDependencies":{"react":"^17 || ^18 || ^19"},"devDependencies":{"@types/node":"^20.0.0","@types/react":"^18.0.0","jsdom":"^29.1.1","typescript":"^5.0.0","vitest":"^4.1.7"},"gitHead":"e00a3406e2ef97771173f9ebcff7271052b085c4","_id":"o-auth-lib@1.1.0","_nodeVersion":"26.0.0","_npmVersion":"11.12.1","dist":{"integrity":"sha512-yZFjlSYhPyUeNVmvF2B/Tpp3CYE1pJNfvR9p2P8Xfo0ifHpq0wy7vwZj0JJsHbJHce6OYA7cswiBfHqn5xZkuw==","shasum":"1403b6c05e8f319eaab3c6caac52c85187630024","tarball":"https://registry.npmjs.org/o-auth-lib/-/o-auth-lib-1.1.0.tgz","fileCount":34,"unpackedSize":55545,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBHrbVFcI8yBj+5e9kf5BvwBRQOPVV7bKQ4JFQiKFmp/AiEAvT3EiZHHYa/lldJ57NNF19zi4bIJjwVe6LJ91qH1VMM="}]},"_npmUser":{"name":"udit-singh","email":"udit6706@gmail.com"},"directories":{},"maintainers":[{"name":"udit-singh","email":"udit6706@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/o-auth-lib_1.1.0_1781157913191_0.5266784986458393"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-01T06:53:13.793Z","modified":"2026-06-11T06:05:13.463Z","1.0.0":"2026-06-01T06:53:14.108Z","1.0.1":"2026-06-01T07:16:31.149Z","1.1.0":"2026-06-11T06:05:13.341Z"},"bugs":{"url":"https://github.com/Dataxis-UditSingh/o-auth-lib/issues"},"author":{"name":"dataxis-labs"},"license":"ISC","homepage":"https://github.com/Dataxis-UditSingh/o-auth-lib#readme","keywords":["oauth","react","typescript","authentication","pkce"],"repository":{"type":"git","url":"git+https://github.com/Dataxis-UditSingh/o-auth-lib.git"},"description":"A TypeScript-friendly authentication library for OAuth and custom login flows with PKCE support.","maintainers":[{"name":"udit-singh","email":"udit6706@gmail.com"}],"readme":"# o-auth-lib\n\n[![npm version](https://img.shields.io/npm/v/o-auth-lib.svg)](https://www.npmjs.com/package/o-auth-lib)\n[![License: ISC](https://img.shields.io/badge/License-ISC-yellow.svg)](https://opensource.org/licenses/ISC)\n\nA TypeScript authentication library for OAuth and normal login flows. The package is designed so consuming apps provide credentials and configuration at runtime, keeping the library reusable and secure.\n\n## Installation\n\n```bash\nnpm install o-auth-lib react\n```\n\n```bash\nyarn add o-auth-lib react\n```\n\n```bash\npnpm add o-auth-lib react\n```\n\n> **Requires:** `react@17` or `react@18`\n\n## Browser Support\n\n- Modern browsers with support for:\n  - `crypto.getRandomValues()` (for PKCE)\n  - `crypto.subtle.digest()` (for SHA-256)\n  - `fetch` API\n  - `URLSearchParams`\n\nTargets **ES2019** and above.\n\n## Usage\n\n### OAuth login\n\n`useAuth()` is the recommended hook for browser-based OAuth login flows.\n\n```ts\nimport { useAuth } from \"o-auth-lib\";\n\nconst oauthConfig = {\n  authType: \"oauth\" as const,\n  provider: \"google\" as const,\n  clientId: import.meta.env.VITE_GOOGLE_CLIENT_ID,\n  redirectUri: import.meta.env.VITE_APP_REDIRECT_URI,\n  scopes: [\"openid\", \"profile\", \"email\"],\n  usePKCE: true,\n};\n\nfunction LoginButton() {\n  const { execute, loading, error, result } = useAuth(oauthConfig);\n\n  return (\n    <button onClick={() => execute()} disabled={loading}>\n      {loading ? \"Signing in...\" : \"Sign in with Google\"}\n      {error && <div>{error}</div>}\n      {result && <div>Authenticated</div>}\n    </button>\n  );\n}\n```\n\n> `usePKCE` is enabled by default for OAuth code flows, so browser apps do not need to use `clientSecret` in the frontend.\n\n### Generic authentication helper\n\nFor normal login flows, use `authenticate()` with a configurable auth endpoint.\n\n```ts\nimport { authenticate } from \"o-auth-lib\";\n\nconst normalConfig = {\n  authType: \"normal\" as const,\n  provider: \"normal\",\n  serviceName: \"my-service\",\n  authUrl: \"https://api.example.com/auth/login\",\n  email: \"user@example.com\",\n  password: \"secret-password\",\n  contentType: \"application/json\",\n};\n\nasync function login() {\n  const result = await authenticate(normalConfig);\n  console.log(result.accessToken, result.data);\n}\n```\n\n### Custom provider example\n\n```ts\nimport { authenticate } from \"o-auth-lib\";\n\nconst customOAuthConfig = {\n  authType: \"oauth\" as const,\n  provider: {\n    authorizeUrl: \"https://custom.example.com/oauth/authorize\",\n    tokenUrl: \"https://custom.example.com/oauth/token\",\n    responseType: \"code\",\n    scopeSeparator: \" \",\n  },\n  clientId: import.meta.env.VITE_CUSTOM_CLIENT_ID,\n  redirectUri: import.meta.env.VITE_APP_REDIRECT_URI,\n  scopes: [\"read\", \"write\"],\n};\n\nconst result = await authenticate(customOAuthConfig);\n```\n\n## Supported provider presets\n\n- `google`\n- `github`\n- `apple`\n- custom provider objects using `provider: { authorizeUrl, tokenUrl, ... }`\n\n## API Reference\n\n### `useAuth(config: AuthConfig): UseAuthResult`\n\nReact hook for authentication flows.\n\n**Parameters:**\n- `config` – OAuth or normal auth configuration\n- `authType` – `\"oauth\"` or `\"normal\"`\n- `provider` – Provider name or custom preset\n\n**Returns:**\n- `execute()` – Function to trigger authentication\n- `loading` – Boolean indicating if auth is in progress\n- `error` – Error message if authentication failed\n- `result` – `AuthResult` containing access token and response data\n\n### `authenticate(config: AuthConfig): Promise<AuthResult>`\n\nGeneric async function for OAuth or normal authentication.\n\n**Returns:**\n- `authType` – Type of authentication used\n- `provider` – Provider name\n- `accessToken` – Access/bearer token if available\n- `refreshToken` – Refresh token if available\n- `data` – Raw response from OAuth provider or auth endpoint\n\n### PKCE Support\n\nPKCE is enabled by default for OAuth authorization code flows. To disable:\n\n```ts\nconst config = {\n  authType: \"oauth\" as const,\n  provider: \"google\",\n  clientId: \"...\",\n  redirectUri: \"...\",\n  usePKCE: false, // Disable PKCE\n};\n```\n\n## Important notes\n\n- Do not store real credentials inside the published package.\n- Pass `clientId` and other credentials from consuming apps, for example via environment variables.\n- `clientSecret` should not be used in browser-only OAuth flows unless the application is a confidential client and the token exchange is performed on a trusted backend.\n- The package publishes only `dist/` via `package.json` `files`, so local `.env` files are not included in the npm package.\n- State validation is automatic and prevents CSRF attacks in OAuth flows.\n","readmeFilename":"README.md"}