{"id":42619928,"url":"https://github.com/scalekit-inc/scalekit-nextjs-auth-example","last_synced_at":"2026-01-29T04:18:39.037Z","repository":{"id":333810617,"uuid":"1132519957","full_name":"scalekit-inc/scalekit-nextjs-auth-example","owner":"scalekit-inc","description":"Production-ready Next.js authentication example with Scalekit OIDC integration. Includes SSO, SAML, session management, protected routes, and TypeScript support for enterprise authentication.","archived":false,"fork":false,"pushed_at":"2026-01-21T05:43:07.000Z","size":77,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-21T17:26:48.517Z","etag":null,"topics":["authentication","enterprise-auth","full-stack-auth","nextjs","nextjs-auth","oauth","oidc","saml","scalekit","scim","session-management","sso","typescript"],"latest_commit_sha":null,"homepage":"https://docs.scalekit.com/authenticate/fsa/quickstart/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scalekit-inc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-12T04:31:20.000Z","updated_at":"2026-01-21T05:43:11.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/scalekit-inc/scalekit-nextjs-auth-example","commit_stats":null,"previous_names":["scalekit-inc/scalekit-nextjs-auth-example"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/scalekit-inc/scalekit-nextjs-auth-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalekit-inc%2Fscalekit-nextjs-auth-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalekit-inc%2Fscalekit-nextjs-auth-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalekit-inc%2Fscalekit-nextjs-auth-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalekit-inc%2Fscalekit-nextjs-auth-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scalekit-inc","download_url":"https://codeload.github.com/scalekit-inc/scalekit-nextjs-auth-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scalekit-inc%2Fscalekit-nextjs-auth-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28862142,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T22:56:21.783Z","status":"online","status_checked_at":"2026-01-29T02:00:06.714Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","enterprise-auth","full-stack-auth","nextjs","nextjs-auth","oauth","oidc","saml","scalekit","scim","session-management","sso","typescript"],"created_at":"2026-01-29T04:18:38.298Z","updated_at":"2026-01-29T04:18:39.023Z","avatar_url":"https://github.com/scalekit-inc.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Next.js Scalekit Authentication Example\n\nA simple Next.js app that shows how to add secure sign-in with Scalekit (OIDC). You can use it as a starting point or as a reference to integrate enterprise-grade authentication.\n\nWhat this example includes:\n\n- The app signs users in with Scalekit using the OpenID Connect (OIDC) authorization flow.\n- The `/dashboard` page is protected and redirects unauthenticated users to the login flow.\n- The configuration shows how to register an OAuth 2.0 client and wire login, callback, and logout endpoints.\n- The pages use Bootstrap classes so pages render well on desktop and mobile.\n- After login, the dashboard displays selected ID token claims to demonstrate how to access user information.\n\n### Prerequisites\n\n- Node.js 18.0 or later is installed.\n- npm or yarn is installed.\n- You have a Scalekit account with an OIDC application. [Sign up](https://app.scalekit.com/)\n\n## 🛠️ Quick start\n\n### Configure Scalekit\n\nPick one method below.\n\n_Method A_ — .env.local file (recommended for local dev):\n\nCreate or update `.env.local` in the project root:\n\n```env\n# Replace placeholders with your values\nSCALEKIT_ENV_URL=https://your-env.scalekit.io\nSCALEKIT_CLIENT_ID=YOUR_CLIENT_ID\nSCALEKIT_CLIENT_SECRET=YOUR_CLIENT_SECRET\nSCALEKIT_REDIRECT_URI=http://localhost:3000/auth/callback\n\n# Optional server config\nNEXT_PUBLIC_APP_URL=http://localhost:3000\n```\n\n_Method B_ — environment variables:\n\n```bash\nexport SCALEKIT_ENV_URL=https://your-env.scalekit.io\nexport SCALEKIT_CLIENT_ID=YOUR_CLIENT_ID\nexport SCALEKIT_CLIENT_SECRET=YOUR_CLIENT_SECRET\nexport SCALEKIT_REDIRECT_URI=http://localhost:3000/auth/callback\nexport NEXT_PUBLIC_APP_URL=http://localhost:3000\n```\n\nImportant:\n\n- Never commit secrets to source control.\n- Ensure the redirect URI exactly matches what is configured in Scalekit.\n\n### Build and run\n\n```bash\n# Install dependencies\nnpm install\n# or\nyarn install\n# or\npnpm install\n\n# Run the development server\nnpm run dev\n# or\nyarn dev\n# or\npnpm dev\n```\n\nThe application will start at `http://localhost:3000`\n\n### Setup Scalekit\n\nTo find your required values:\n\n1.  Visit [Scalekit Dashboard](https://app.scalekit.com) and proceed to _Settings_\n\n2.  Copy the API credentials\n\n    - **Environment URL** (e.g., `https://your-env.scalekit.dev`)\n    - **Client ID**\n    - **Client Secret**\n\n3.  Authentication \u003e Redirect URLs \u003e Allowed redirect URIs:\n    - Add `http://localhost:3000/auth/callback` (no trailing slash)\n    - Optionally add `http://localhost:3000` as a post-logout redirect\n\n### Application routes\n\n| Route                            | Description                 | Auth required |\n| -------------------------------- | --------------------------- | ------------- |\n| `/`                              | Home page with login option | No            |\n| `/login`                         | Custom login page           | No            |\n| `/auth/callback`                 | OIDC callback (API route)   | No            |\n| `/dashboard`                     | Protected dashboard         | Yes           |\n| `/sessions`                      | Session management          | Yes           |\n| `/sessions/validate-token`       | Validate token (API)        | Yes           |\n| `/sessions/refresh-token`        | Refresh token (API)         | Yes           |\n| `/organization/settings`          | Protected settings page     | Yes (permission) |\n| `/logout`                        | Logout and end session      | Yes           |\n\n### 🚦 Try the app\n\n1. Start the app (see Quick start)\n2. Visit `http://localhost:3000`\n3. Click Sign in with Scalekit\n4. Authenticate with your provider\n5. Open the dashboard and then try logout\n\nStuck? [Contact us](https://docs.scalekit.com/support/contact-us/).\n\n#### Code structure\n\n```\nnextjs-scalekit-example/\n├── app/                          # Next.js App Router pages\n│   ├── api/                      # API routes\n│   │   └── auth/                 # Authentication API routes\n│   │       ├── login/            # Login initiation\n│   │       ├── callback/          # OAuth callback handler\n│   │       ├── logout/           # Logout handler\n│   │       ├── refresh/          # Token refresh\n│   │       └── validate/         # Token validation\n│   ├── dashboard/                # Dashboard page\n│   ├── sessions/                 # Session management page\n│   ├── organization/             # Organization settings\n│   ├── login/                    # Login page\n│   ├── error/                     # Error page\n│   └── permission-denied/        # Permission denied page\n├── components/                    # React components\n│   ├── LoginButton.tsx\n│   ├── LogoutButton.tsx\n│   └── SessionActions.tsx\n├── lib/                          # Utility libraries\n│   ├── scalekit.ts               # Scalekit client initialization\n│   ├── cookies.ts                # Session cookie management\n│   └── auth.ts                   # Authentication utilities\n├── package.json                  # Dependencies\n├── tsconfig.json                 # TypeScript configuration\n├── next.config.js                # Next.js configuration\n└── README.md                     # This file\n```\n\n#### Dependencies\n\n- Next.js 14+ (App Router)\n- **@scalekit-sdk/node** (Official Scalekit Node SDK)\n- React 18+\n- TypeScript\n- date-fns (for date formatting)\n- js-cookie (for cookie management)\n\nSee `package.json` for exact versions.\n\n#### Scalekit SDK Methods Used\n\nThis application uses the official Scalekit Node SDK (`@scalekit-sdk/node`) for all authentication operations:\n\n- `ScalekitClient.getAuthorizationUrl()` - Generate OAuth authorization URL\n- `ScalekitClient.authenticateWithCode()` - Exchange code for tokens\n- `ScalekitClient.validateToken()` - Validate tokens and extract permissions\n- `ScalekitClient.refreshAccessToken()` - Refresh expired tokens\n- `ScalekitClient.getLogoutUrl()` - Generate logout URL\n\n#### Key Features\n\n- **Server-Side Authentication**: Uses Next.js API routes for secure token handling\n- **Cookie-Based Sessions**: Secure HTTP-only cookies for session storage\n- **Automatic Token Refresh**: Middleware can be added to refresh tokens automatically\n- **Permission-Based Access Control**: Route protection based on token permissions\n- **TypeScript Support**: Full type safety throughout the application\n\n\n\n#### Support\n\n- Read the Scalekit docs: [Documentation](https://docs.scalekit.com).\n- Read the Next.js docs: [Documentation](https://nextjs.org/docs).\n\n#### License 📄\n\nThis project is for demonstration and learning. Refer to dependency licenses for production use.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscalekit-inc%2Fscalekit-nextjs-auth-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscalekit-inc%2Fscalekit-nextjs-auth-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscalekit-inc%2Fscalekit-nextjs-auth-example/lists"}