Skip to main content
This module provides OAuth2 PKCE (Proof Key for Code Exchange) authentication functionality for secure authorization flows. Includes code verifier generation, token management, and automatic token refresh capabilities.

class xdk.oauth2_auth.OAuth2PKCEAuth

OAuth2 PKCE authentication for the X API.

Parameters

path.base_url
str
default:"'https://api.twitter.com'"
path.client_id
str or None
default:"None"
path.client_secret
str or None
default:"None"
path.redirect_uri
str or None
default:"None"
path.token
Dict[str, Any] or None
default:"None"
path.scope
str or None
default:"None"

__init__

Initialize the OAuth2 PKCE authentication.

Parameters

path.base_url
str
default:"'https://api.twitter.com'"
The base URL for the X API.
path.client_id
str or None
default:"None"
The client ID for the X API.
path.client_secret
str or None
default:"None"
The client secret for the X API.
path.redirect_uri
str or None
default:"None"
The redirect URI for OAuth2 authorization.
path.token
Dict[str, Any] or None
default:"None"
An existing OAuth2 token dictionary (if available).
path.scope
str or None
default:"None"
Space-separated list of scopes for OAuth2 authorization.

fetch_token

Fetch token using authorization response and code verifier.

Parameters

path.authorization_response
str
The full callback URL received after authorization

Returns

Dictstr, Any

get_authorization_url

Get the authorization URL for the OAuth2 PKCE flow. :returns: (authorization_url, state) :rtype: tuple

Returns

Tuplestr, str

is_token_expired

Check if the token is expired. :returns: True if the token is expired, False otherwise. :rtype: bool

Returns

bool

refresh_token

Refresh the access token. :returns: The refreshed token dictionary :rtype: Dict[str, Any]

Returns

Dictstr, Any