Openid connect

From G1Joshi/Agent-Skills · View interactive version

Openid connect is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert OpenID Connect (OIDC) assistance covering ID tokens, UserInfo endpoints, discovery documents, and claims. Use when implementing single sign-on (SSO), verifying ID tokens, or configuring OIDC providers.

How to use this skill

Skill file

OpenID Connect (OIDC)

OIDC extends OAuth 2.0 to provide Identity. While OAuth handles "Access" (Authorization), OIDC handles "Who are you?" (Authentication).

When to Use

Quick Start

// Request
GET /authorize?
  response_type=code&
  scope=openid profile email&  <-- 'openid' scope triggers OIDC
  client_id=...&
  redirect_uri=...

// Token Response
{
  "access_token": "SlAV32hkKG...", // For API access
  "id_token": "eyJ0eXKiOiJK...",   // JWT containing User Profile
  "expires_in": 3600
}

Core Concepts

The OIDC Layer on OAuth 2.0

OIDC adds an identity layer on top of OAuth 2.0 by introducing the cryptographic ID Token and UserInfo endpoint:

[ OAuth 2.0 (Authorization) ] ──+ OpenID Scope ──→ [ OpenID Connect (Authentication) ]
                                                     ├── ID Token (JWT with user claims)
                                                     ├── Discovery Endpoint (/.well-known/openid-configuration)
                                                     └── UserInfo Endpoint (/userinfo)

The OIDC Discovery Document (`/.well-known/openid-configuration`)

Allows clients to discover authorization, token, JWKS, and userinfo endpoints dynamically:

{
  "issuer": "https://accounts.google.com",
  "authorization_endpoint": "https://accounts.google.com/o/oauth2/v2/auth",
  "token_endpoint": "https://oauth2.googleapis.com/token",
  "userinfo_endpoint": "https://openidconnect.googleapis.com/v1/userinfo",
  "jwks_uri": "https://www.googleapis.com/oauth2/v3/certs",
  "response_types_supported": ["code", "token", "id_token"]
}

The ID Token & Core Standard Claims

A signed JWT containing identity assertion claims:

{
  "iss": "https://accounts.google.com",
  "sub": "109823481230912",
  "aud": "my-client-app-id",
  "exp": 1727420400,
  "iat": 1727416800,
  "email": "user@example.com",
  "email_verified": true,
  "name": "Alex Mercer"
}

Common Patterns

Authorization Code Flow with PKCE

Problem: Public clients (SPAs, Mobile Apps) cannot securely store client secrets.

Solution: Generate dynamic code verifier and code challenge (Proof Key for Code Exchange).

import crypto from "crypto";

// 1. Generate Code Verifier & Challenge
function generatePkceCodes() {
  const verifier = crypto.randomBytes(32).toString("base64url");
  const challenge = crypto
    .createHash("sha256")
    .update(verifier)
    .digest("base64url");
  return { verifier, challenge };
}

// 2. Redirect to Auth URL with Challenge
const { verifier, challenge } = generatePkceCodes();
const authUrl =
  `https://auth.example.com/oauth/authorize?response_type=code` +
  `&client_id=my-spa&redirect_uri=https://app.com/callback` +
  `&code_challenge=${challenge}&code_challenge_method=S256&scope=openid profile email`;

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :------------------ | :---------------------------- | :---------------------------------------- |

| id_token missing | Scope openid not requested. | Add openid to scopes. |

| Signature Invalid | Wrong Public Key. | Refresh JWKS from the discovery endpoint. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.