Twitter OAuth provider

OAuth integration for Twitter OAuth 2.0 with PKCE. The access token can only be used for Twitter API v2. Provider id is twitter.

import { twitter } from "@lucia-auth/oauth/providers";
import { auth } from "./lucia.js";

const twitterAuth = twitter(auth, config);

twitter()#

const twitter: (
	auth: Auth,
	config: {
		clientId: string;
		clientSecret: string;
		redirectUri: string;
		scope?: string[];
	}
) => TwitterProvider;
Parameter#
nametypedescriptionoptional
authAuthLucia instance
config.clientIdstringclient id
config.clientSecretstringclient id
config.redirectUristringredirect URI
config.scopestring[]an array of scopes
Returns#
typedescription
TwitterProviderTwitter provider

Interfaces#

TwitterAuth#

See OAuth2ProviderAuthWithPKCE.

// implements OAuth2ProviderAuthWithPKCE<TwitterAuth<_Auth>>
interface TwitterAuth<_Auth extends Auth> {
	getAuthorizationUrl: () => Promise<
		readonly [url: URL, codeVerifier: string, state: string]
	>;
	validateCallback: (code: string) => Promise<TwitterUserAuth<_Auth>>;
}
Generics#
nameextendsdefault
_AuthAuthAuth

TwitterTokens#

type TwitterTokens = {
	accessToken: string;
	refreshToken: string | null;
};

TwitterUser#

type TwitterUser = {
	id: string;
	name: string;
	username: string;
};

TwitterUserAuth#

Extends ProviderUserAuth.

interface TwitterUserAuth<_Auth extends Auth> extends ProviderUserAuth<_Auth> {
	twitterUser: TwitterUser;
	twitterTokens: TwitterTokens;
}
propertiestypedescription
twitterUserTwitterUserTwitter user
twitterTokensTwitterTokensAccess tokens etc
Generics#
nameextends
_AuthAuth