@@ -1042,43 +1042,48 @@ This example shows how to use OAuth 2.0 with Proof Key for Code Exchange (PKCE).
10421042**Example** (using a web server for callback):
10431043
10441044```python
1045- from xdk.auth import OAuth2PKCE
1045+ from xdk.oauth2_auth import OAuth2PKCEAuth
10461046from urllib.parse import urlparse
10471047import webbrowser
10481048
10491049# Step 1: Create PKCE instance
1050- auth = OAuth2PKCE (
1051- client_id="your_client_id ",
1052- redirect_uri="http://localhost:8080/callback ",
1053- scopes=[ "tweet.read", " users.read", " offline.access"] # Adjust scopes as needed
1050+ auth = OAuth2PKCEAuth (
1051+ client_id="YOUR_CLIENT_ID ",
1052+ redirect_uri="YOUR_CALLBACK_URL ",
1053+ scope= "tweet.read users.read offline.access"
10541054)
10551055
10561056# Step 2: Get authorization URL
1057- auth_url = auth.get_authorization_url()
1057+ auth_url, state = auth.get_authorization_url()
10581058print(f"Visit this URL to authorize: {auth_url}")
10591059webbrowser.open(auth_url)
10601060
10611061# Step 3: Handle callback (in a real app, use a web framework like Flask)
10621062# Assume callback_url = "http://localhost:8080/callback?code=AUTH_CODE_HERE"
10631063callback_url = input("Paste the full callback URL here: ")
1064- parsed = urlparse(callback_url)
1065- code = parsed.query.split("=")[1]
10661064
10671065# Step 4: Exchange code for tokens
1068- tokens = auth.fetch_token(authorization_code=code )
1066+ tokens = auth.fetch_token(authorization_response=callback_url )
10691067access_token = tokens["access_token"]
10701068refresh_token = tokens["refresh_token"] # Store for renewal
10711069
10721070# Step 5: Create client
1073- client = Client(oauth2_access_token=access_token)
1071+ # Option 1: Use bearer_token (OAuth2 access tokens work as bearer tokens)
1072+ client = Client(bearer_token=access_token)
1073+
1074+ # Option 2: Pass the full token dict for automatic refresh support
1075+ # client = Client(token=tokens)
10741076```
10751077
10761078**Token Refresh** (automatic in SDK for long-lived sessions):
10771079
10781080```python
10791081# If access token expires, refresh using stored refresh_token
1080- tokens = auth.refresh_token(refresh_token=refresh_token)
1081- client = Client(oauth2_access_token=tokens["access_token"])
1082+ # The refresh_token method uses the stored token from the OAuth2PKCEAuth instance
1083+ tokens = auth.refresh_token()
1084+ # Use the refreshed token
1085+ client = Client(bearer_token=tokens["access_token"])
1086+ # Or pass the full token dict: client = Client(token=tokens)
10821087```
10831088
10841089### 3. OAuth 1.0a User Context
0 commit comments