import {
Client,
OAuth2,
generateCodeVerifier,
generateCodeChallenge,
type OAuth2Config,
type ClientConfig,
type OAuth2Token
} from '@xdevplatform/xdk';
(async (): Promise<void> => {
const oauth2Config: OAuth2Config = {
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
redirectUri: 'https://example.com',
scope: ['tweet.read', 'users.read', 'offline.access'],
};
const oauth2: OAuth2 = new OAuth2(oauth2Config);
const state: string = 'example-state';
const codeVerifier: string = generateCodeVerifier();
const codeChallenge: string = await generateCodeChallenge(codeVerifier);
oauth2.setPkceParameters(codeVerifier, codeChallenge);
const authUrl: string = await oauth2.getAuthorizationUrl(state);
// उपयोगकर्ता authUrl पर जाकर ऐप को अधिकृत करता है
// अधिकृत करने के बाद, उपयोगकर्ता code पैरामीटर के साथ वापस रीडायरेक्ट हो जाता है
// callback URL से code निकालें (उदाहरण के लिए, query params से)
const authCode: string = 'code-from-callback-url'; // इसे OAuth callback से मिले वास्तविक code से बदलें
const tokens: OAuth2Token = await oauth2.exchangeCode(authCode, codeVerifier);
const config: ClientConfig = {
accessToken: tokens.access_token,
};
const client: Client = new Client(config);
});