agentsclimarketplace

Oauth ai services

Skill pinkpixel-dev/skills-collection-2/SKILLS/oauth-ai-services

Part 2 of the AI and agent skills collection, with 650+ skill folders focused on reusable workflows, security playbooks, cloud implementation guides, scripts, references, and assets for builders and operators.

Install
npx -y skills add pinkpixel-dev/skills-collection-2 --skill oauth-ai-services

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Complete reference for implementing OAuth 2.0 login flows with major AI service providers: OpenAI/ChatGPT, Anthropic Claude/Claude Code, Google Gemini, and GitHub Copilot. USE THIS SKILL whenever working on authentication, login, OAuth, tokens, or API access for any of these AI services — even if the user just says "how do I log in to X API", "I need to auth with Claude/OpenAI/Gemini/Copilot", "implement OAuth for AI service", "refresh tokens", "PKCE flow", "authorization code grant", "device code flow", or anything relating to integrating user authentication into an app that uses these AI APIs. Also trigger when comparing auth patterns across AI providers, troubleshooting 401/403 errors on AI APIs, or building MCP servers/clients that need user-scoped AI tokens.

SKILL.md

5.2 KB, ~1.1k tokens by cl100k_base, as published. Nobody here has run it

OAuth for AI Services

Four major AI providers, four different auth strategies. This skill covers endpoints, grant types, scopes, token formats, code examples, and security best practices for each.

Quick Provider Summary

ProviderAuth EndpointToken EndpointToken FormatDevice Flow
OpenAIhttps://auth.openai.com/oauth/authorizehttps://auth.openai.com/oauth/tokenJWT
Anthropichttps://claude.ai/oauth/authorizehttps://platform.claude.com/v1/oauth/tokenOpaque string
Google Geminihttps://accounts.google.com/o/oauth2/v2/authhttps://oauth2.googleapis.com/tokenOpaque (+ JWT id_token)
GitHub Copilothttps://github.com/login/oauth/authorizehttps://github.com/login/oauth/access_tokenOpaque (gho_ prefix)

All four support Authorization Code + PKCE and Refresh Tokens. All tokens expire ~1 hour.


Critical Gotchas (Read First!)

  • OpenAI: Token endpoint expects JSON body, NOT form-encoded. Must include model.request scope or you'll get 401 on API calls.
  • Anthropic: Token endpoint at platform.claude.com (not claude.ai). Uses custom scopes, no OIDC (openid not used).
  • Google: Token endpoint expects form-encoded body (opposite of OpenAI). Must add access_type=offline for refresh tokens. App needs verification for production.
  • GitHub Copilot: No special scopes needed. Token is a standard GitHub OAuth token (gho_ prefix) that Copilot SDK accepts directly.

Per-Provider Details

See references/ for deep-dive implementation details, full code examples, and flow diagrams.

  • references/openai.md — OpenAI/ChatGPT/Codex OAuth
  • references/anthropic.md — Anthropic Claude / Claude Code OAuth
  • references/google-gemini.md — Google Gemini / generative-language OAuth
  • references/github-copilot.md — GitHub Copilot OAuth
  • references/security-and-checklist.md — Security best practices, integration checklist, comparison table

Universal Auth Code + PKCE Flow

All four providers follow this same general pattern:

1. Generate code_verifier (random 43-128 char string)
2. code_challenge = BASE64URL(SHA256(code_verifier))
3. Redirect user to provider's authorize URL with:
   ?response_type=code
   &client_id=YOUR_CLIENT_ID
   &redirect_uri=YOUR_CALLBACK
   &scope=REQUIRED_SCOPES
   &code_challenge=<challenge>
   &code_challenge_method=S256
   &state=RANDOM_CSRF_TOKEN
4. User logs in + consents
5. Provider redirects to YOUR_CALLBACK?code=AUTH_CODE&state=...
6. Verify state matches
7. POST to provider's token endpoint with grant_type=authorization_code + code + code_verifier
8. Receive access_token + refresh_token
9. Use access_token as "Authorization: Bearer <token>" on API calls
10. When token expires (~1hr), POST to token endpoint with grant_type=refresh_token

Scope Cheat Sheet

OpenAI:    openid profile email offline_access model.request
Anthropic: user:profile user:inference user:sessions:claude_code user:mcp_servers
Google:    https://www.googleapis.com/auth/generative-language openid email profile
Copilot:   (none required beyond default user scopes)

TypeScript PKCE Helper (Works Everywhere)

import { createHash, randomBytes } from 'crypto';

export function generatePKCE() {
  const verifier = randomBytes(32).toString('base64url');
  const challenge = createHash('sha256').update(verifier).digest('base64url');
  return { verifier, challenge };
}

export function buildAuthUrl(
  baseUrl: string,
  params: {
    clientId: string;
    redirectUri: string;
    scope: string;
    challenge: string;
    state: string;
    extra?: Record<string, string>;
  }
): string {
  const url = new URL(baseUrl);
  url.searchParams.set('response_type', 'code');
  url.searchParams.set('client_id', params.clientId);
  url.searchParams.set('redirect_uri', params.redirectUri);
  url.searchParams.set('scope', params.scope);
  url.searchParams.set('code_challenge', params.challenge);
  url.searchParams.set('code_challenge_method', 'S256');
  url.searchParams.set('state', params.state);
  if (params.extra) {
    for (const [k, v] of Object.entries(params.extra)) {
      url.searchParams.set(k, v);
    }
  }
  return url.toString();
}

For detailed per-provider examples, token refresh flows, device code flows, and SDK usage → read the relevant references/ file.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.