Authentication¶
The Griddy SDK requires authentication to access NFL data. This guide explains how to obtain and use authentication tokens.
Overview¶
The NFL API uses OAuth-based authentication. You need an access token to make API requests. There are two ways to authenticate:
- Token-based: Provide a pre-obtained access token (both SDKs)
- Browser-based: Automated login using Playwright (Python SDK only)
Token-Based Authentication¶
Obtaining a Token¶
To obtain an access token:
- Log in to NFL.com in your browser
- Open browser developer tools (F12)
- Go to the Network tab
- Look for API requests to
api.nfl.com - Find the
Authorizationheader containingBearer <token> - Copy the token (without the "Bearer " prefix)
Using the Token¶
Token Format¶
The nfl_auth dictionary can include:
| Field | Type | Required | Description |
|---|---|---|---|
accessToken |
string | Yes | The OAuth access token |
refreshToken |
string | No | Token for refreshing access |
expiresIn |
number | No | Token expiration in seconds |
Browser-Based Authentication (Python Only)¶
The Python SDK can automatically obtain tokens using Playwright browser automation.
Setup¶
First, install Playwright and browsers:
Usage¶
from griddy.nfl import GriddyNFL
# Authenticate with email and password
nfl = GriddyNFL(
login_email="your_email@example.com",
login_password="your_password",
headless_login=True # Run browser in headless mode
)
# The SDK automatically handles authentication
games = nfl.games.get_games(season=2024, season_type="REG", week=1)
Options¶
| Parameter | Type | Default | Description |
|---|---|---|---|
login_email |
str | None | NFL.com account email |
login_password |
str | None | NFL.com account password |
headless_login |
bool | False | Run browser without GUI |
Important
Browser-based authentication is not available in the TypeScript SDK. You must provide a pre-obtained access token.
Storing Credentials¶
Environment Variables¶
Store your token in an environment variable:
Configuration File¶
For development, you can store credentials in a local file:
import json
from griddy.nfl import GriddyNFL
# Load from file
with open("credentials.json") as f:
auth = json.load(f)
nfl = GriddyNFL(nfl_auth=auth)
Security Warning
Never commit credentials to version control. Add credentials.json to your .gitignore file.
Token Expiration¶
NFL access tokens expire periodically. When your token expires:
- API calls will return authentication errors
- You'll need to obtain a new token
Handling Expiration¶
Context Manager (Python)¶
Use the context manager for automatic resource cleanup:
from griddy.nfl import GriddyNFL
with GriddyNFL(nfl_auth={"accessToken": "your_token"}) as nfl:
games = nfl.games.get_games(season=2024, season_type="REG", week=1)
# Resources are automatically cleaned up
Cleanup (TypeScript)¶
Always close the client when done: