CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-requests-oauthlib

OAuthlib authentication support for Requests.

Pending
Overview
Eval results
Files

compliance-fixes.mddocs/

Provider Compliance Fixes

Pre-built compliance fixes for popular OAuth providers that implement non-standard OAuth behaviors. These fixes enable seamless integration with services that deviate from the OAuth 2.0 specification.

Capabilities

Facebook Compliance Fix

Handles Facebook's non-standard OAuth 2.0 implementation that returns tokens as URL-encoded form data with incorrect content-type headers instead of JSON.

def facebook_compliance_fix(session: OAuth2Session) -> OAuth2Session:
    """
    Apply Facebook-specific OAuth compliance fixes.

    Fixes:
    - Handles text/plain content-type for token responses
    - Converts 'expires' field to standard 'expires_in' field
    - Adds missing 'token_type': 'Bearer' to token response
    - Converts response to proper JSON format

    Args:
        session (OAuth2Session): OAuth session to modify

    Returns:
        OAuth2Session: Modified session with Facebook compliance fixes
    """

Usage Example:

from requests_oauthlib import OAuth2Session
from requests_oauthlib.compliance_fixes import facebook_compliance_fix

# Create session and apply Facebook fixes
oauth = OAuth2Session('client_id', redirect_uri='https://example.com/callback')
oauth = facebook_compliance_fix(oauth)

# Now works with Facebook's non-standard responses
auth_url, state = oauth.authorization_url('https://www.facebook.com/dialog/oauth')
token = oauth.fetch_token(
    'https://graph.facebook.com/oauth/access_token',
    authorization_response=callback_url,
    client_secret='client_secret'
)

Slack Compliance Fix

Handles Slack's non-standard parameter name for access tokens in API requests.

def slack_compliance_fix(session: OAuth2Session) -> OAuth2Session:
    """
    Apply Slack-specific OAuth compliance fixes.

    Fixes:
    - Uses 'token' parameter instead of standard Authorization header
    - Automatically adds token to request data or URL parameters
    - Preserves existing token parameter if already present

    Args:
        session (OAuth2Session): OAuth session to modify

    Returns:
        OAuth2Session: Modified session with Slack compliance fixes
    """

Usage Example:

from requests_oauthlib import OAuth2Session
from requests_oauthlib.compliance_fixes import slack_compliance_fix

# Create session and apply Slack fixes
oauth = OAuth2Session('client_id', redirect_uri='https://example.com/callback')
oauth = slack_compliance_fix(oauth)

# Token automatically added as 'token' parameter
auth_url, state = oauth.authorization_url('https://slack.com/oauth/authorize')
token = oauth.fetch_token(
    'https://slack.com/api/oauth.access',
    authorization_response=callback_url,
    client_secret='client_secret'
)

# API calls automatically include token parameter
response = oauth.post('https://slack.com/api/chat.postMessage', data={
    'channel': '#general',
    'text': 'Hello from OAuth!'
})

Instagram Compliance Fix

Handles Instagram's token response format variations.

def instagram_compliance_fix(session: OAuth2Session) -> OAuth2Session:
    """
    Apply Instagram-specific OAuth compliance fixes.

    Args:
        session (OAuth2Session): OAuth session to modify

    Returns:
        OAuth2Session: Modified session with Instagram compliance fixes
    """

Mailchimp Compliance Fix

Handles Mailchimp's OAuth implementation specifics.

def mailchimp_compliance_fix(session: OAuth2Session) -> OAuth2Session:
    """
    Apply Mailchimp-specific OAuth compliance fixes.

    Args:
        session (OAuth2Session): OAuth session to modify

    Returns:
        OAuth2Session: Modified session with Mailchimp compliance fixes
    """

Fitbit Compliance Fix

Handles Fitbit's OAuth implementation requirements.

def fitbit_compliance_fix(session: OAuth2Session) -> OAuth2Session:
    """
    Apply Fitbit-specific OAuth compliance fixes.

    Args:
        session (OAuth2Session): OAuth session to modify

    Returns:
        OAuth2Session: Modified session with Fitbit compliance fixes
    """

Weibo Compliance Fix

Handles Weibo's OAuth implementation variations.

def weibo_compliance_fix(session: OAuth2Session) -> OAuth2Session:
    """
    Apply Weibo-specific OAuth compliance fixes.

    Args:
        session (OAuth2Session): OAuth session to modify

    Returns:
        OAuth2Session: Modified session with Weibo compliance fixes
    """

PlentyMarkets Compliance Fix

Handles PlentyMarkets OAuth implementation specifics.

def plentymarkets_compliance_fix(session: OAuth2Session) -> OAuth2Session:
    """
    Apply PlentyMarkets-specific OAuth compliance fixes.

    Args:
        session (OAuth2Session): OAuth session to modify

    Returns:
        OAuth2Session: Modified session with PlentyMarkets compliance fixes
    """

eBay Compliance Fix

Handles eBay's OAuth implementation requirements.

def ebay_compliance_fix(session: OAuth2Session) -> OAuth2Session:
    """
    Apply eBay-specific OAuth compliance fixes.

    Args:
        session (OAuth2Session): OAuth session to modify

    Returns:
        OAuth2Session: Modified session with eBay compliance fixes
    """

How Compliance Fixes Work

Compliance fixes modify OAuth2Session behavior by registering custom hooks that intercept and modify requests and responses. They typically:

  1. Register compliance hooks using session.register_compliance_hook()
  2. Modify request parameters before sending to provider
  3. Transform response data to match OAuth 2.0 specification
  4. Handle provider-specific quirks like custom parameter names or response formats

Common OAuth Provider Issues

Non-Standard Token Responses

  • Issue: Providers return tokens in unexpected formats or with incorrect content-type headers
  • Solution: Parse and normalize token responses to standard JSON format

Custom Parameter Names

  • Issue: Providers expect tokens in non-standard parameter names or locations
  • Solution: Intercept requests and add tokens using provider-specific parameter names

Missing Token Information

  • Issue: Providers omit required fields like token_type or use non-standard field names
  • Solution: Add missing fields or rename fields to match OAuth 2.0 specification

Content-Type Issues

  • Issue: Providers return JSON data with incorrect content-type headers
  • Solution: Override content-type detection and force JSON parsing

Creating Custom Compliance Fixes

You can create custom compliance fixes for other providers:

def custom_provider_compliance_fix(session):
    def fix_token_response(response):
        # Modify response as needed
        if 'custom_token_field' in response.text:
            # Transform response to standard format
            pass
        return response
    
    def fix_protected_request(url, headers, data):
        # Modify request parameters as needed
        if session.access_token:
            # Add token in provider-specific way
            pass
        return url, headers, data
    
    # Register hooks
    session.register_compliance_hook('access_token_response', fix_token_response)
    session.register_compliance_hook('protected_request', fix_protected_request)
    
    return session

Available Hook Types

Compliance fixes can register hooks for different points in the OAuth flow:

  • access_token_response: Modify token endpoint responses before parsing
  • refresh_token_response: Modify refresh token responses before parsing
  • protected_request: Modify authenticated API requests before sending
  • access_token_request: Modify token fetch requests before sending
  • refresh_token_request: Modify token refresh requests before sending

Best Practices

  1. Apply fixes early: Apply compliance fixes immediately after creating the OAuth2Session
  2. Test thoroughly: Provider APIs can change, so test compliance fixes regularly
  3. Document provider-specific behavior: Keep notes on what each fix addresses
  4. Monitor provider updates: Watch for changes in provider OAuth implementations
  5. Combine fixes carefully: Some providers may need multiple fixes or custom combinations

Install with Tessl CLI

npx tessl i tessl/pypi-requests-oauthlib

docs

compliance-fixes.md

index.md

oauth1.md

oauth2.md

tile.json