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.

매개변수

str
default:"'https://api.x.com'"
str
default:"'https://x.com/i'"
str or None
default:"None"
str or None
default:"None"
str or None
default:"None"
Dict[str, Any] or None
default:"None"
str or List[str] or None
default:"None"

__init__

Initialize the OAuth2 PKCE authentication.

매개변수

str
default:"'https://api.x.com'"
The base URL for the X API token endpoint (defaults to https://api.x.com).
str
default:"'https://x.com/i'"
OAuth 2.0 인증을 위한 기본 URL입니다(기본값은 https://x.com/i).
str or None
default:"None"
The client ID for the X API.
str or None
default:"None"
X API의 client secret입니다.
str or None
default:"None"
OAuth 2.0 인증을 위한 redirect URI입니다.
Dict[str, Any] or None
default:"None"
An existing OAuth2 token dictionary (if available).
str or List[str] or None
default:"None"
OAuth 2.0 인증 스코프를 위한 공백으로 구분된 문자열 또는 문자열 목록입니다.

exchange_code

인증 코드를 토큰으로 교환합니다(TypeScript API와 일치).

매개변수

str
콜백에서 받은 인증 코드입니다.
str or None
default:"None"
선택적 code verifier입니다(제공되지 않으면 저장된 verifier를 사용).

반환값

Dictstr, Any

fetch_token

Fetch token using authorization response URL (legacy method, uses exchange_code internally).

매개변수

str
The full callback URL received after authorization

반환값

Dictstr, Any

get_authorization_url

OAuth 2.0 PKCE 흐름을 위한 인증 URL을 가져옵니다.

매개변수

str or None
default:"None"
보안을 위한 선택적 state 매개변수입니다.

반환값

str

get_code_challenge

Get the current code challenge (for PKCE). :returns: The current code challenge, or None if not set. :rtype: Optional[str]

반환값

str | None

get_code_verifier

Get the current code verifier (for PKCE). :returns: The current code verifier, or None if not set. :rtype: Optional[str]

반환값

str | None

is_token_expired

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

반환값

bool

refresh_token

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

반환값

Dictstr, Any

set_pkce_parameters

Manually set PKCE parameters.

매개변수

str
The code verifier to use.
str or None
default:"None"
Optional code challenge (will be generated if not provided).