add-external-oauth

Implements external OAuth2/OIDC login with PKCE and Supabase user provisioning in Next.js.

Updated May 27, 2026
One-click install
npx skills add https://github.com/Rkaaaa404/cyberhack-SYDT --skill add-external-oauth-rkaaaa404
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: add-external-oauth
Source: https://github.com/Rkaaaa404/cyberhack-SYDT/tree/main/.agents/skills/add-external-oauth
Command: npx skills add https://github.com/Rkaaaa404/cyberhack-SYDT --skill add-external-oauth-rkaaaa404

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires jose, @supabase/ssr, and includes references (resource) components.

What problem does it solve? Self-hosted Supabase deployments do not expose identity provider configuration, so built-in OAuth cannot be used. This Skill implements a full OAuth2/OIDC flow where Next.js acts as the OAuth client, handling token exchange, claim extraction, JIT user provisioning, and session establishment. ## Core Features & Use Cases - OAuth Proxy Flow with PKCE: Generates PKCE verifiers, encrypts state with AES-256-GCM, and handles the authorization code exchange against any OIDC provider. - Multi-Provider Support: Ships configurations for Azure AD, Google, Okta, Auth0, and generic OIDC providers, with multi-source claim extraction (access_token, id_token, userinfo) and email claim normalization across 8 claim name variants. - Supabase JIT Provisioning: Finds or creates users via the Admin API, generates sessions through the magic link + OTP workaround, and sets cookies correctly via supabase.auth.setSession(). - Use Case: Add SSO login to a Buildpad DaaS application backed by self-hosted Supabase, where employees authenticate through the company Azure AD tenant and are provisioned automatically on first login. ## Quick Start Add external OAuth login to my Next.js app using the add-external-oauth skill with Azure AD as the identity provider.

Frequently Asked Questions about add-external-oauth

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add OAuth SSO login to a Next.js app with self-hosted Supabase?▼

Implement Next.js as the OAuth client: create API routes for the authorization redirect and callback, exchange the code with PKCE, then provision users via the Supabase Admin API. Self-hosted Supabase does not expose IDP configuration, so the built-in OAuth flow cannot be used.

How to implement PKCE in a Next.js OAuth flow?▼

Generate a 32-byte random code_verifier encoded as base64url, then create the code_challenge as its SHA-256 hash. Send the challenge to the authorize endpoint and the verifier during token exchange, storing the verifier in an AES-256-GCM encrypted state cookie.

Why does OAuth login loop back to the login page after success?▼

Manually setting sb-access-token cookies does not match the format Supabase SSR middleware expects. Use createServerClient from @supabase/ssr and call supabase.auth.setSession() with the access and refresh tokens so cookies are written in the correct format.

Why is the email claim missing from the ID token?▼

Some providers return email in the access_token or userinfo endpoint instead of the id_token, and claim names vary (preferred_username, upn, mail, login). Decode all token sources and check multiple claim name variants when normalizing user data.

Does Supabase Admin API have a getUserByEmail method?▼

No, the Supabase Admin API does not provide getUserByEmail. You must paginate through auth.admin.listUsers() and match the email address case-insensitively to find an existing user before creating a new one.

Which OAuth providers does this approach support?▼

It supports Azure AD, Google, Okta, Auth0, and any generic OIDC-compliant provider configured through environment variables. Each provider supplies authorization, token, JWKS, and issuer URLs, with optional userinfo endpoints.