跳到主要内容
知仓学习社ZHICANG

authentication-patterns

Provides auth patterns for API keys, OAuth, and token management. Use when implementing or reviewing service authentication and credential handling.

读凭据严重 5 · 高危 0athola/claude-night-market

它会碰到什么

扫了多少7 个文本文件,38 KB
它会碰到什么读凭据
命中总数11 处
命中统计严重 5 · 高 0 · 中 0 · 低 0
逐条看命中(5 条严重或高危)
  • 严重 modules/auth-methods.md:16cred-paths
    # Or in .env file
  • 严重 modules/auth-methods.md:17cred-paths
    echo "GEMINI_API_KEY=your-key-here" >> ~/.env
  • 严重 modules/auth-methods.md:65cred-paths
    # ~/.config/{service}/credentials.json
  • 严重 modules/interactive-auth.md:50cred-paths
    export GOOGLE_APPLICATION_CREDENTIALS="path/to/credentials.json"
  • 严重 README.md:407cred-paths
    - AWS: `~/.aws/credentials`

这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。

技能内容

Table of Contents

  • [Overview](#overview)
  • [When to Use](#when-to-use)
  • [Authentication Methods](#authentication-methods)
  • [Quick Start](#quick-start)
  • [Verify Authentication](#verify-authentication)
  • [Smoke Test](#smoke-test)
  • [Standard Flow](#standard-flow)
  • [Step 1: Check Environment](#step-1:-check-environment)
  • [Step 2: Verify with Service](#step-2:-verify-with-service)
  • [Step 3: Handle Failures](#step-3:-handle-failures)
  • [Integration Pattern](#integration-pattern)
  • [Detailed Resources](#detailed-resources)
  • [Exit Criteria](#exit-criteria)

Authentication Patterns

Overview

Common authentication patterns for integrating with external services. Provides consistent approaches to credential management, verification, and error handling.

When To Use

  • Integrating with external APIs
  • Need credential verification
  • Managing multiple auth methods
  • Handling auth failures gracefully

When NOT To Use

  • Project doesn't use the leyline infrastructure patterns
  • Simple scripts without service architecture needs

Authentication Methods

| Method | Best For | Environment Variable |

|--------|----------|---------------------|

| API Key | Simple integrations | {SERVICE}_API_KEY |

| OAuth | User-authenticated | Browser-based flow |

| Token | Session-based | {SERVICE}_TOKEN |

| None | Public APIs | N/A |

Quick Start

Verify Authentication

from leyline.auth import verify_auth, AuthMethod

# API Key verification
status = verify_auth(
    service="gemini", method=AuthMethod.API_KEY, env_var="GEMINI_API_KEY"
)

if not status.authenticated:
    print(f"Auth failed: {status.message}")
    print(f"Action: {status.suggested_action}")

Verification: Run the command with --help flag to verify availability.

Smoke Test

def verify_with_smoke_test(service: str) -> bool:
    """Verify auth with simple request."""
    result = execute_simple_request(service, "ping")
    return result.success

Verification: Run pytest -v to verify tests pass.

Standard Flow

Step 1: Check Environment

def check_credentials(service: str, env_var: str) -> bool:
    value = os.getenv(env_var)
    if not value:
        print(f"Missing {env_var}")
        return False
    return True

Verification: Run the command with --help flag to verify availability.

Step 2: Verify with Service

def verify_with_service(service: str) -> AuthStatus:
    result = subprocess.run([service, "auth", "status"], capture_output=True)
    return AuthStatus(
        authenticated=(result.returncode == 0), message=result.stdout.decode()
    )

Verification: Run the command with --help flag to verify availability.

Step 3: Handle Failures

def handle_auth_failure(service: str, method: AuthMethod) -> str:
    actions = {
        AuthMethod.API_KEY: f"Set {service.upper()}_API_KEY environment variable",
        AuthMethod.OAUTH: f"Run '{service} auth login' for browser auth",
        AuthMethod.TOKEN: f"Refresh token with '{service} token refresh'",
    }
    return actions[method]

Verification: Run the command with --help flag to verify availability.

Integration Pattern

# In your skill's frontmatter
dependencies: [leyline:authentication-patterns]

Verification: Run the command with --help flag to verify availability.

Interactive Authentication (Shell)

For workflows requiring interactive authentication with token caching and session management:

# Source the interactive auth script
source plugins/leyline/scripts/interactive_auth.sh

# Ensure authentication before proceeding
ensure_auth github || exit 1
ensure_auth gitlab || exit 1
ensure_auth aws || exit 1

# Continue with authenticated operations
gh pr view 123
glab issue list
aws s3 ls

Features:

  • ✅ Interactive OAuth flows for GitHub, GitLab, AWS, and more
  • ✅ Token caching (5-minute TTL)
  • ✅ Session persistence (24-hour TTL)
  • ✅ CI/CD compatible (auto-detects non-interactive environments)
  • ✅ Multi-service support

See modules/interactive-auth.md for complete documentation.

Detailed Resources

  • Auth Methods: See modules/auth-methods.md for method details
  • Verification: See modules/verification-patterns.md for testing patterns
  • Interactive: See modules/interactive-auth.md for shell-based auth flows

Exit Criteria

  • Credentials verified or clear failure message
  • Suggested action for auth failures
  • Smoke test confirms working auth

想直接用这个技能?

本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。