[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6CXC5JW5NDERFC3T96364GD":3,"skill-same:01M6CXC5JW5NDERFC3T96364GD":92},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":23,"linkOnly":24,"markdownContent":25,"markdownBody":26,"frontMatter":27,"refName":30,"commitSha":31,"skillDirectory":5,"forksCount":32,"repositoryHtmlUrl":33,"repositoryHomepageUrl":6,"ownerHtmlUrl":34,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":35,"install":36,"resources":49},"01M6CXC5JW5NDERFC3T96364GD","oauth",null,"OAuth 2.0 and OpenID Connect implementation","ffsshhttiikk\u002Fopencode-agents-skills","ffsshhttiikk","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F226346827?v=4","01M6CWD9RR3Y7VRQX3MXYC8FYH","01M6CWD9WVPYAZW0J82G1VKGHY",3,"MIT","https:\u002F\u002Fgithub.com\u002Fffsshhttiikk\u002Fopencode-agents-skills\u002Fblob\u002Fmain\u002Foauth\u002FSKILL.md",[],[18,19,20,21,22],"OAuth","security","connect","opencode","implementation","2026-11-10 10:12:30",false,"---\nname: oauth\ndescription: OAuth 2.0 and OpenID Connect implementation\nlicense: MIT\ncompatibility: opencode\nmetadata:\n  audience: developers\n  category: security\n---\n## What I do\n- Implement OAuth 2.0 flows\n- Handle OpenID Connect authentication\n- Manage tokens securely\n- Implement authorization grants\n- Handle refresh tokens\n- Validate tokens\n- Implement PKCE for mobile\u002FSPA\n- Secure OAuth implementations\n\n## When to use me\nWhen implementing OAuth authentication or authorization.\n\n## OAuth 2.0 Flows\n```\nOAuth 2.0 Grant Types:\n\n1. Authorization Code (Web Apps)\n   Client → Auth Server → User Login → Auth Code → \n   Client → Token Exchange → Access Token\n\n2. Authorization Code + PKCE (Mobile\u002FSPA)\n   Same as above, but with code_verifier\n\n3. Client Credentials (M2M)\n   Client → Token Exchange → Access Token\n\n4. Device Code (IoT, Smart TVs)\n   Device Code Flow → User authorization on second device\n\n5. Refresh Token\n   Client → Token Refresh → New Access Token\n```\n\n## OAuth Implementation\n```python\nfrom dataclasses import dataclass\nfrom typing import Optional\nfrom datetime import datetime, timedelta\nimport secrets\nimport hashlib\n\n\n@dataclass\nclass OAuthConfig:\n    \"\"\"OAuth configuration.\"\"\"\n    client_id: str\n    client_secret: str\n    authorization_endpoint: str\n    token_endpoint: str\n    redirect_uri: str\n    scopes: list[str]\n    access_token_ttl: int = 3600  # 1 hour\n    refresh_token_ttl: int = 2592000  # 30 days\n\n\nclass OAuthClient:\n    \"\"\"OAuth 2.0 client implementation.\"\"\"\n    \n    def __init__(self, config: OAuthConfig):\n        self.config = config\n        self.code_store = {}  # In production, use Redis\n        self.token_store = {}\n    \n    def generate_authorization_code(self, state: str, redirect_uri: str):\n        \"\"\"Generate authorization code for auth code flow.\"\"\"\n        code = secrets.token_urlsafe(32)\n        \n        self.code_store[code] = {\n            'state': state,\n            'redirect_uri': redirect_uri,\n            'scopes': self.config.scopes,\n            'created_at': datetime.utcnow(),\n            'expires_in': 600,  # 10 minutes\n        }\n        \n        return code\n    \n    def validate_authorization_code(\n        self,\n        code: str,\n        redirect_uri: str\n    ) -> Optional[dict]:\n        \"\"\"Validate and consume authorization code.\"\"\"\n        if code not in self.code_store:\n            return None\n        \n        code_data = self.code_store[code]\n        \n        # Check expiration\n        elapsed = (datetime.utcnow() - code_data['created_at']).total_seconds()\n        if elapsed > code_data['expires_in']:\n            del self.code_store[code]\n            return None\n        \n        # Validate redirect URI\n        if code_data['redirect_uri'] != redirect_uri:\n            return None\n        \n        # Consume code\n        del self.code_store[code]\n        \n        return code_data\n    \n    def exchange_code_for_tokens(\n        self,\n        code: str,\n        redirect_uri: str,\n        client_id: str = None,\n        client_secret: str = None,\n        code_verifier: str = None\n    ) -> dict:\n        \"\"\"Exchange authorization code for tokens.\"\"\"\n        # Validate client\n        if client_id != self.config.client_id:\n            raise OAuthError(\"invalid_client\", \"Invalid client ID\")\n        \n        # Validate client secret (if required)\n        if client_secret and not self._validate_client_secret(client_secret):\n            raise OAuthError(\"invalid_client\", \"Invalid client secret\")\n        \n        # Validate code\n        code_data = self.validate_authorization_code(code, redirect_uri)\n        if not code_data:\n            raise OAuthError(\"invalid_grant\", \"Invalid or expired code\")\n        \n        # Validate PKCE if provided\n        if code_verifier and not self._validate_pkce(code, code_verifier):\n            raise OAuthError(\"invalid_grant\", \"PKCE validation failed\")\n        \n        # Generate tokens\n        access_token = self._generate_access_token()\n        refresh_token = self._generate_refresh_token()\n        \n        # Store tokens\n        self.token_store[access_token] = {\n            'scopes': code_data['scopes'],\n            'created_at': datetime.utcnow(),\n            'expires_in': self.config.access_token_ttl,\n        }\n        \n        return {\n            'access_token': access_token,\n            'token_type': 'Bearer',\n            'expires_in': self.config.access_token_ttl,\n            'refresh_token': refresh_token,\n            'scope': ' '.join(code_data['scopes']),\n        }\n    \n    def refresh_access_token(\n        self,\n        refresh_token: str,\n        scopes: list[str] = None\n    ) -> dict:\n        \"\"\"Refresh access token using refresh token.\"\"\"\n        if refresh_token not in self.token_store:\n            raise OAuthError(\"invalid_grant\", \"Invalid refresh token\")\n        \n        token_data = self.token_store[refresh_token]\n        \n        # Check expiration\n        elapsed = (datetime.utcnow() - token_data['created_at']).total_seconds()\n        if elapsed > self.config.refresh_token_ttl:\n            del self.token_store[refresh_token]\n            raise OAuthError(\"invalid_grant\", \"Refresh token expired\")\n        \n        # Validate scopes (can't request more than original)\n        requested_scopes = scopes or token_data['scopes']\n        for scope in requested_scopes:\n            if scope not in token_data['scopes']:\n                raise OAuthError(\"invalid_scope\", \"Requested scope not allowed\")\n        \n        # Generate new tokens\n        access_token = self._generate_access_token()\n        new_refresh_token = self._generate_refresh_token()\n        \n        # Invalidate old refresh token\n        del self.token_store[refresh_token]\n        \n        # Store new tokens\n        self.token_store[access_token] = {\n            'scopes': requested_scopes,\n            'created_at': datetime.utcnow(),\n            'expires_in': self.config.access_token_ttl,\n        }\n        \n        return {\n            'access_token': access_token,\n            'token_type': 'Bearer',\n            'expires_in': self.config.access_token_ttl,\n            'refresh_token': new_refresh_token,\n            'scope': ' '.join(requested_scopes),\n        }\n    \n    def validate_access_token(self, token: str) -> Optional[dict]:\n        \"\"\"Validate access token and return claims.\"\"\"\n        if token not in self.token_store:\n            return None\n        \n        token_data = self.token_store[token]\n        \n        elapsed = (datetime.utcnow() - token_data['created_at']).total_seconds()\n        if elapsed > token_data['expires_in']:\n            del self.token_store[token]\n            return None\n        \n        return token_data\n    \n    def _generate_access_token(self) -> str:\n        \"\"\"Generate secure access token.\"\"\"\n        return secrets.token_urlsafe(32)\n    \n    def _generate_refresh_token(self) -> str:\n        \"\"\"Generate secure refresh token.\"\"\"\n        return secrets.token_urlsafe(32)\n    \n    def _validate_client_secret(self, secret: str) -> bool:\n        \"\"\"Validate client secret.\"\"\"\n        return secrets.compare_digest(secret, self.config.client_secret)\n    \n    def _validate_pkce(self, code_challenge: str, code_verifier: str) -> bool:\n        \"\"\"Validate PKCE code verifier against challenge.\"\"\"\n        # In production, store code_challenge with code\n        return True\n\n\nclass OAuthError(Exception):\n    \"\"\"OAuth error.\"\"\"\n    \n    def __init__(self, error: str, error_description: str):\n        self.error = error\n        self.error_description = error_description\n        super().__init__(f\"{error}: {error_description}\")\n```\n\n## PKCE Implementation\n```python\nimport base64\nimport hashlib\nimport secrets\n\n\nclass PKCE:\n    \"\"\"PKCE helper for OAuth 2.0.\"\"\"\n    \n    @staticmethod\n    def generate_code_verifier(length: int = 43) -> str:\n        \"\"\"\n        Generate cryptographically secure code verifier.\n        \n        Must be 43-128 characters, using [A-Z], [a-z], [0-9], \"-\", \".\", \"_\", \"~\"\n        \"\"\"\n        alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~'\n        return ''.join(secrets.choice(alphabet) for _ in range(length))\n    \n    @staticmethod\n    def generate_code_challenge(code_verifier: str) -> str:\n        \"\"\"\n        Generate code challenge from code verifier.\n        \n        Uses S256 method: BASE64URL(SHA256(code_verifier))\n        \"\"\"\n        sha256_hash = hashlib.sha256(code_verifier.encode('ascii')).digest()\n        return base64.urlsafe_b64encode(sha256_hash).decode('ascii').rstrip('=')\n    \n    @staticmethod\n    def generate_pair() -> tuple[str, str]:\n        \"\"\"Generate code verifier and challenge pair.\"\"\"\n        code_verifier = PKCE.generate_code_verifier()\n        code_challenge = PKCE.generate_code_challenge(code_verifier)\n        return code_verifier, code_challenge\n    \n    @staticmethod\n    def validate_code_verifier(code_verifier: str, code_challenge: str) -> bool:\n        \"\"\"Verify code verifier matches challenge.\"\"\"\n        expected_challenge = PKCE.generate_code_challenge(code_verifier)\n        return secrets.compare_digest(expected_challenge, code_challenge)\n\n\n# Usage for authorization code flow with PKCE\ndef authorization_code_flow_with_pkce():\n    # Client generates code verifier and challenge\n    code_verifier, code_challenge = PKCE.generate_pair()\n    \n    # Store code_verifier securely (session, not localStorage)\n    store_code_verifier(code_verifier)\n    \n    # Redirect user to authorization endpoint\n    auth_url = (\n        f\"{auth_server}\u002Fauthorize?\"\n        f\"response_type=code&\"\n        f\"client_id={client_id}&\"\n        f\"redirect_uri={redirect_uri}&\"\n        f\"scope={scopes}&\"\n        f\"state={generate_state()}&\"\n        f\"code_challenge={code_challenge}&\"\n        f\"code_challenge_method=S256\"\n    )\n    \n    # After user authorizes, receive code\n    # Exchange code for tokens with code_verifier\n    tokens = client.exchange_code_for_tokens(\n        code=authorization_code,\n        redirect_uri=redirect_uri,\n        code_verifier=code_verifier\n    )\n```\n\n## Token Validation\n```python\nfrom jwt import jwt, JWTError\nfrom jwt.algorithms import RSAAlgorithm\n\n\nclass TokenValidator:\n    \"\"\"Validate OAuth and JWT tokens.\"\"\"\n    \n    def __init__(self, jwks_uri: str):\n        self.jwks_uri = jwks_uri\n        self.jwks_cache = {}\n    \n    def validate_token(self, token: str, audience: str) -> dict:\n        \"\"\"Validate JWT token.\"\"\"\n        try:\n            # Get signing key\n            unverified_header = jwt.get_unverified_header(token)\n            kid = unverified_header.get('kid')\n            \n            key = self._get_signing_key(kid)\n            \n            # Decode and validate\n            claims = jwt.decode(\n                token,\n                key,\n                algorithms=['RS256'],\n                audience=audience,\n                options={\n                    'verify_exp': True,\n                    'verify_aud': True,\n                    'verify_iat': True,\n                }\n            )\n            \n            return claims\n        \n        except jwt.ExpiredSignatureError:\n            raise TokenValidationError(\"Token has expired\")\n        except jwt.InvalidAudienceError:\n            raise TokenValidationError(\"Invalid audience\")\n        except JWTError as e:\n            raise TokenValidationError(f\"Token validation failed: {e}\")\n    \n    def _get_signing_key(self, kid: str) -> str:\n        \"\"\"Get signing key from JWKS.\"\"\"\n        if kid in self.jwks_cache:\n            return self.jwks_cache[kid]\n        \n        # Fetch JWKS\n        jwks = requests.get(self.jwks_uri).json()\n        \n        for key_data in jwks.get('keys', []):\n            if key_data.get('kid') == kid:\n                key = RSAAlgorithm.from_jwk(key_data)\n                self.jwks_cache[kid] = key\n                return key\n        \n        raise TokenValidationError(f\"Key not found: {kid}\")\n```\n\n## Best Practices\n```\n1. Use PKCE for all flows\n   Required for mobile and SPA\n   Recommended for all\n\n2. Use short-lived access tokens\n   Combine with refresh tokens\n\n3. Validate everything\n   Client ID, redirect URI, scopes, audience\n\n4. Secure token storage\n   Access tokens: memory or secure cookie\n   Refresh tokens: server-side storage\n\n5. Use state parameter\n   Prevent CSRF attacks\n\n6. Implement token binding\n   Bind tokens to client\n\n7. Log and monitor\n   Track token usage\n\n8. Rotate keys regularly\n   Use JWKS for key rotation\n\n9. Don't leak tokens in URLs\n   Use POST body, not query params\n\n10. Implement token revocation\n    Support token revocation endpoint\n```\n","## What I do\n- Implement OAuth 2.0 flows\n- Handle OpenID Connect authentication\n- Manage tokens securely\n- Implement authorization grants\n- Handle refresh tokens\n- Validate tokens\n- Implement PKCE for mobile\u002FSPA\n- Secure OAuth implementations\n\n## When to use me\nWhen implementing OAuth authentication or authorization.\n\n## OAuth 2.0 Flows\n```\nOAuth 2.0 Grant Types:\n\n1. Authorization Code (Web Apps)\n   Client → Auth Server → User Login → Auth Code → \n   Client → Token Exchange → Access Token\n\n2. Authorization Code + PKCE (Mobile\u002FSPA)\n   Same as above, but with code_verifier\n\n3. Client Credentials (M2M)\n   Client → Token Exchange → Access Token\n\n4. Device Code (IoT, Smart TVs)\n   Device Code Flow → User authorization on second device\n\n5. Refresh Token\n   Client → Token Refresh → New Access Token\n```\n\n## OAuth Implementation\n```python\nfrom dataclasses import dataclass\nfrom typing import Optional\nfrom datetime import datetime, timedelta\nimport secrets\nimport hashlib\n\n\n@dataclass\nclass OAuthConfig:\n    \"\"\"OAuth configuration.\"\"\"\n    client_id: str\n    client_secret: str\n    authorization_endpoint: str\n    token_endpoint: str\n    redirect_uri: str\n    scopes: list[str]\n    access_token_ttl: int = 3600  # 1 hour\n    refresh_token_ttl: int = 2592000  # 30 days\n\n\nclass OAuthClient:\n    \"\"\"OAuth 2.0 client implementation.\"\"\"\n    \n    def __init__(self, config: OAuthConfig):\n        self.config = config\n        self.code_store = {}  # In production, use Redis\n        self.token_store = {}\n    \n    def generate_authorization_code(self, state: str, redirect_uri: str):\n        \"\"\"Generate authorization code for auth code flow.\"\"\"\n        code = secrets.token_urlsafe(32)\n        \n        self.code_store[code] = {\n            'state': state,\n            'redirect_uri': redirect_uri,\n            'scopes': self.config.scopes,\n            'created_at': datetime.utcnow(),\n            'expires_in': 600,  # 10 minutes\n        }\n        \n        return code\n    \n    def validate_authorization_code(\n        self,\n        code: str,\n        redirect_uri: str\n    ) -> Optional[dict]:\n        \"\"\"Validate and consume authorization code.\"\"\"\n        if code not in self.code_store:\n            return None\n        \n        code_data = self.code_store[code]\n        \n        # Check expiration\n        elapsed = (datetime.utcnow() - code_data['created_at']).total_seconds()\n        if elapsed > code_data['expires_in']:\n            del self.code_store[code]\n            return None\n        \n        # Validate redirect URI\n        if code_data['redirect_uri'] != redirect_uri:\n            return None\n        \n        # Consume code\n        del self.code_store[code]\n        \n        return code_data\n    \n    def exchange_code_for_tokens(\n        self,\n        code: str,\n        redirect_uri: str,\n        client_id: str = None,\n        client_secret: str = None,\n        code_verifier: str = None\n    ) -> dict:\n        \"\"\"Exchange authorization code for tokens.\"\"\"\n        # Validate client\n        if client_id != self.config.client_id:\n            raise OAuthError(\"invalid_client\", \"Invalid client ID\")\n        \n        # Validate client secret (if required)\n        if client_secret and not self._validate_client_secret(client_secret):\n            raise OAuthError(\"invalid_client\", \"Invalid client secret\")\n        \n        # Validate code\n        code_data = self.validate_authorization_code(code, redirect_uri)\n        if not code_data:\n            raise OAuthError(\"invalid_grant\", \"Invalid or expired code\")\n        \n        # Validate PKCE if provided\n        if code_verifier and not self._validate_pkce(code, code_verifier):\n            raise OAuthError(\"invalid_grant\", \"PKCE validation failed\")\n        \n        # Generate tokens\n        access_token = self._generate_access_token()\n        refresh_token = self._generate_refresh_token()\n        \n        # Store tokens\n        self.token_store[access_token] = {\n            'scopes': code_data['scopes'],\n            'created_at': datetime.utcnow(),\n            'expires_in': self.config.access_token_ttl,\n        }\n        \n        return {\n            'access_token': access_token,\n            'token_type': 'Bearer',\n            'expires_in': self.config.access_token_ttl,\n            'refresh_token': refresh_token,\n            'scope': ' '.join(code_data['scopes']),\n        }\n    \n    def refresh_access_token(\n        self,\n        refresh_token: str,\n        scopes: list[str] = None\n    ) -> dict:\n        \"\"\"Refresh access token using refresh token.\"\"\"\n        if refresh_token not in self.token_store:\n            raise OAuthError(\"invalid_grant\", \"Invalid refresh token\")\n        \n        token_data = self.token_store[refresh_token]\n        \n        # Check expiration\n        elapsed = (datetime.utcnow() - token_data['created_at']).total_seconds()\n        if elapsed > self.config.refresh_token_ttl:\n            del self.token_store[refresh_token]\n            raise OAuthError(\"invalid_grant\", \"Refresh token expired\")\n        \n        # Validate scopes (can't request more than original)\n        requested_scopes = scopes or token_data['scopes']\n        for scope in requested_scopes:\n            if scope not in token_data['scopes']:\n                raise OAuthError(\"invalid_scope\", \"Requested scope not allowed\")\n        \n        # Generate new tokens\n        access_token = self._generate_access_token()\n        new_refresh_token = self._generate_refresh_token()\n        \n        # Invalidate old refresh token\n        del self.token_store[refresh_token]\n        \n        # Store new tokens\n        self.token_store[access_token] = {\n            'scopes': requested_scopes,\n            'created_at': datetime.utcnow(),\n            'expires_in': self.config.access_token_ttl,\n        }\n        \n        return {\n            'access_token': access_token,\n            'token_type': 'Bearer',\n            'expires_in': self.config.access_token_ttl,\n            'refresh_token': new_refresh_token,\n            'scope': ' '.join(requested_scopes),\n        }\n    \n    def validate_access_token(self, token: str) -> Optional[dict]:\n        \"\"\"Validate access token and return claims.\"\"\"\n        if token not in self.token_store:\n            return None\n        \n        token_data = self.token_store[token]\n        \n        elapsed = (datetime.utcnow() - token_data['created_at']).total_seconds()\n        if elapsed > token_data['expires_in']:\n            del self.token_store[token]\n            return None\n        \n        return token_data\n    \n    def _generate_access_token(self) -> str:\n        \"\"\"Generate secure access token.\"\"\"\n        return secrets.token_urlsafe(32)\n    \n    def _generate_refresh_token(self) -> str:\n        \"\"\"Generate secure refresh token.\"\"\"\n        return secrets.token_urlsafe(32)\n    \n    def _validate_client_secret(self, secret: str) -> bool:\n        \"\"\"Validate client secret.\"\"\"\n        return secrets.compare_digest(secret, self.config.client_secret)\n    \n    def _validate_pkce(self, code_challenge: str, code_verifier: str) -> bool:\n        \"\"\"Validate PKCE code verifier against challenge.\"\"\"\n        # In production, store code_challenge with code\n        return True\n\n\nclass OAuthError(Exception):\n    \"\"\"OAuth error.\"\"\"\n    \n    def __init__(self, error: str, error_description: str):\n        self.error = error\n        self.error_description = error_description\n        super().__init__(f\"{error}: {error_description}\")\n```\n\n## PKCE Implementation\n```python\nimport base64\nimport hashlib\nimport secrets\n\n\nclass PKCE:\n    \"\"\"PKCE helper for OAuth 2.0.\"\"\"\n    \n    @staticmethod\n    def generate_code_verifier(length: int = 43) -> str:\n        \"\"\"\n        Generate cryptographically secure code verifier.\n        \n        Must be 43-128 characters, using [A-Z], [a-z], [0-9], \"-\", \".\", \"_\", \"~\"\n        \"\"\"\n        alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~'\n        return ''.join(secrets.choice(alphabet) for _ in range(length))\n    \n    @staticmethod\n    def generate_code_challenge(code_verifier: str) -> str:\n        \"\"\"\n        Generate code challenge from code verifier.\n        \n        Uses S256 method: BASE64URL(SHA256(code_verifier))\n        \"\"\"\n        sha256_hash = hashlib.sha256(code_verifier.encode('ascii')).digest()\n        return base64.urlsafe_b64encode(sha256_hash).decode('ascii').rstrip('=')\n    \n    @staticmethod\n    def generate_pair() -> tuple[str, str]:\n        \"\"\"Generate code verifier and challenge pair.\"\"\"\n        code_verifier = PKCE.generate_code_verifier()\n        code_challenge = PKCE.generate_code_challenge(code_verifier)\n        return code_verifier, code_challenge\n    \n    @staticmethod\n    def validate_code_verifier(code_verifier: str, code_challenge: str) -> bool:\n        \"\"\"Verify code verifier matches challenge.\"\"\"\n        expected_challenge = PKCE.generate_code_challenge(code_verifier)\n        return secrets.compare_digest(expected_challenge, code_challenge)\n\n\n# Usage for authorization code flow with PKCE\ndef authorization_code_flow_with_pkce():\n    # Client generates code verifier and challenge\n    code_verifier, code_challenge = PKCE.generate_pair()\n    \n    # Store code_verifier securely (session, not localStorage)\n    store_code_verifier(code_verifier)\n    \n    # Redirect user to authorization endpoint\n    auth_url = (\n        f\"{auth_server}\u002Fauthorize?\"\n        f\"response_type=code&\"\n        f\"client_id={client_id}&\"\n        f\"redirect_uri={redirect_uri}&\"\n        f\"scope={scopes}&\"\n        f\"state={generate_state()}&\"\n        f\"code_challenge={code_challenge}&\"\n        f\"code_challenge_method=S256\"\n    )\n    \n    # After user authorizes, receive code\n    # Exchange code for tokens with code_verifier\n    tokens = client.exchange_code_for_tokens(\n        code=authorization_code,\n        redirect_uri=redirect_uri,\n        code_verifier=code_verifier\n    )\n```\n\n## Token Validation\n```python\nfrom jwt import jwt, JWTError\nfrom jwt.algorithms import RSAAlgorithm\n\n\nclass TokenValidator:\n    \"\"\"Validate OAuth and JWT tokens.\"\"\"\n    \n    def __init__(self, jwks_uri: str):\n        self.jwks_uri = jwks_uri\n        self.jwks_cache = {}\n    \n    def validate_token(self, token: str, audience: str) -> dict:\n        \"\"\"Validate JWT token.\"\"\"\n        try:\n            # Get signing key\n            unverified_header = jwt.get_unverified_header(token)\n            kid = unverified_header.get('kid')\n            \n            key = self._get_signing_key(kid)\n            \n            # Decode and validate\n            claims = jwt.decode(\n                token,\n                key,\n                algorithms=['RS256'],\n                audience=audience,\n                options={\n                    'verify_exp': True,\n                    'verify_aud': True,\n                    'verify_iat': True,\n                }\n            )\n            \n            return claims\n        \n        except jwt.ExpiredSignatureError:\n            raise TokenValidationError(\"Token has expired\")\n        except jwt.InvalidAudienceError:\n            raise TokenValidationError(\"Invalid audience\")\n        except JWTError as e:\n            raise TokenValidationError(f\"Token validation failed: {e}\")\n    \n    def _get_signing_key(self, kid: str) -> str:\n        \"\"\"Get signing key from JWKS.\"\"\"\n        if kid in self.jwks_cache:\n            return self.jwks_cache[kid]\n        \n        # Fetch JWKS\n        jwks = requests.get(self.jwks_uri).json()\n        \n        for key_data in jwks.get('keys', []):\n            if key_data.get('kid') == kid:\n                key = RSAAlgorithm.from_jwk(key_data)\n                self.jwks_cache[kid] = key\n                return key\n        \n        raise TokenValidationError(f\"Key not found: {kid}\")\n```\n\n## Best Practices\n```\n1. Use PKCE for all flows\n   Required for mobile and SPA\n   Recommended for all\n\n2. Use short-lived access tokens\n   Combine with refresh tokens\n\n3. Validate everything\n   Client ID, redirect URI, scopes, audience\n\n4. Secure token storage\n   Access tokens: memory or secure cookie\n   Refresh tokens: server-side storage\n\n5. Use state parameter\n   Prevent CSRF attacks\n\n6. Implement token binding\n   Bind tokens to client\n\n7. Log and monitor\n   Track token usage\n\n8. Rotate keys regularly\n   Use JWKS for key rotation\n\n9. Don't leak tokens in URLs\n   Use POST body, not query params\n\n10. Implement token revocation\n    Support token revocation endpoint\n```\n",{"name":5,"license":14,"metadata":28,"description":7,"compatibility":21},{"audience":29,"category":19},"developers","main","5f7a3e453c98261f93d19a6a7de44ad8f7b72d41",2,"https:\u002F\u002Fgithub.com\u002Fffsshhttiikk\u002Fopencode-agents-skills","https:\u002F\u002Fgithub.com\u002Fffsshhttiikk","2026-03-01 06:55:40",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add ffsshhttiikk\u002Fopencode-agents-skills --skill oauth",{"tool":42,"command":43},"bunx","bunx skills add ffsshhttiikk\u002Fopencode-agents-skills --skill oauth",{"tool":45,"command":46},"pnpm","pnpm dlx skills add ffsshhttiikk\u002Fopencode-agents-skills --skill oauth","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fffsshhttiikk\u002Fopencode-agents-skills\u002Fblob\u002Fmain\u002Foauth\u002FSKILL.md",true,[50,56,60,64,68,72,76,80,84,88],{"path":51,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":54,"sourceHtmlUrl":55},"anomaly-diagnosis.md","REFERENCE","参考文档",14029,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Findranilbanerjee\u002Fdigital-marketing-pro\u002Fskills\u002Fanalytics-insights\u002Fanomaly-diagnosis.md",{"path":57,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":58,"sourceHtmlUrl":59},"clv-analysis.md",16081,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Findranilbanerjee\u002Fdigital-marketing-pro\u002Fskills\u002Fanalytics-insights\u002Fclv-analysis.md",{"path":61,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":62,"sourceHtmlUrl":63},"competitive-intelligence.md",13815,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Findranilbanerjee\u002Fdigital-marketing-pro\u002Fskills\u002Fanalytics-insights\u002Fcompetitive-intelligence.md",{"path":65,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":66,"sourceHtmlUrl":67},"dark-social-tracking.md",13688,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Findranilbanerjee\u002Fdigital-marketing-pro\u002Fskills\u002Fanalytics-insights\u002Fdark-social-tracking.md",{"path":69,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":70,"sourceHtmlUrl":71},"dashboard-design.md",21403,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Findranilbanerjee\u002Fdigital-marketing-pro\u002Fskills\u002Fanalytics-insights\u002Fdashboard-design.md",{"path":73,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":74,"sourceHtmlUrl":75},"incrementality-testing.md",14555,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Findranilbanerjee\u002Fdigital-marketing-pro\u002Fskills\u002Fanalytics-insights\u002Fincrementality-testing.md",{"path":77,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":78,"sourceHtmlUrl":79},"kpi-frameworks.md",11974,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Findranilbanerjee\u002Fdigital-marketing-pro\u002Fskills\u002Fanalytics-insights\u002Fkpi-frameworks.md",{"path":81,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":82,"sourceHtmlUrl":83},"mmm-framework.md",18058,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Findranilbanerjee\u002Fdigital-marketing-pro\u002Fskills\u002Fanalytics-insights\u002Fmmm-framework.md",{"path":85,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":86,"sourceHtmlUrl":87},"privacy-first-measurement.md",19610,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Findranilbanerjee\u002Fdigital-marketing-pro\u002Fskills\u002Fanalytics-insights\u002Fprivacy-first-measurement.md",{"path":89,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":90,"sourceHtmlUrl":91},"reporting-templates.md",11265,"https:\u002F\u002Fgithub.com\u002Fhashgraph-online\u002Fawesome-codex-plugins\u002Fblob\u002Fmain\u002Fplugins\u002Findranilbanerjee\u002Fdigital-marketing-pro\u002Fskills\u002Fanalytics-insights\u002Freporting-templates.md",[93,104,114,123,133,142],{"skillNo":94,"name":95,"nameZh":6,"description":96,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":97,"categories":98,"keywords":99,"publishedAt":23},"01M6CXT9TXDF79BWJTMQAPB49G","xamarin","Xamarin cross-platform development","https:\u002F\u002Fgithub.com\u002Fffsshhttiikk\u002Fopencode-agents-skills\u002Fblob\u002Fmain\u002Fxamarin\u002FSKILL.md",[],[95,100,101,102,21,103],"platform","cross-platform","mobile","development",{"skillNo":105,"name":106,"nameZh":6,"description":107,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":108,"categories":109,"keywords":110,"publishedAt":23},"01M6CXT8AD04MFYDA32VW3FKAG","wrangling","Data wrangling fundamentals","https:\u002F\u002Fgithub.com\u002Fffsshhttiikk\u002Fopencode-agents-skills\u002Fblob\u002Fmain\u002Fwrangling\u002FSKILL.md",[],[106,111,21,112,113],"data wrangling","science","data",{"skillNo":115,"name":116,"nameZh":6,"description":117,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":118,"categories":119,"keywords":120,"publishedAt":23},"01M6CXT717GCN7SRRNPBDP4508","windows","Windows operating system administration and scripting","https:\u002F\u002Fgithub.com\u002Fffsshhttiikk\u002Fopencode-agents-skills\u002Fblob\u002Fmain\u002Fwindows\u002FSKILL.md",[],[116,121,21,122],"system","scripting",{"skillNo":124,"name":125,"nameZh":6,"description":126,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":127,"categories":128,"keywords":129,"publishedAt":23},"01M6CXT54K794NMEM3XAPZZDKT","wide-column","Wide-column data model","https:\u002F\u002Fgithub.com\u002Fffsshhttiikk\u002Fopencode-agents-skills\u002Fblob\u002Fmain\u002Fwide-column\u002FSKILL.md",[],[130,131,21,132,113],"wide column","databases","model",{"skillNo":134,"name":135,"nameZh":6,"description":136,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":137,"categories":138,"keywords":139,"publishedAt":23},"01M6CXT28FMT2P4V9GZE67WA8E","wide-column-stores","Wide-column database stores","https:\u002F\u002Fgithub.com\u002Fffsshhttiikk\u002Fopencode-agents-skills\u002Fblob\u002Fmain\u002Fwide-column-stores\u002FSKILL.md",[],[140,131,21,141],"wide column stores","database",{"skillNo":143,"name":144,"nameZh":6,"description":145,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":146,"categories":147,"keywords":148,"publishedAt":23},"01M6CXT0D0M0Q4T2N7C2RX7DSN","websockets","WebSocket implementation and best practices","https:\u002F\u002Fgithub.com\u002Fffsshhttiikk\u002Fopencode-agents-skills\u002Fblob\u002Fmain\u002Fwebsockets\u002FSKILL.md",[],[144,149,150,151,21,152,22],"websocket","real-time","time","best practices"]