Spotify OAuth provider

OAuth integration for Spotify. Refer to Spotify OAuth documentation for getting the required credentials. Provider id is spotify.

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

const spotifyAuth = spotify(auth, config);

spotify()#

const spotify: (
	auth: Auth,
	configs: {
		clientId: string;
		clientSecret: string;
		redirectUri: string;
		scope?: string[];
	}
) => SpotifyProvider;
Parameters#
nametypedescriptionoptional
authAuthLucia instance
config.clientIdstringSpotify OAuth app client id
config.clientSecretstringSpotify OAuth app client secret
config.redirectUristringone of the authorized redirect URIs
config.scopestring[]an array of scopes
Returns#
typedescription
SpotifyProviderSpotify provider

Interfaces#

SpotifyAuth#

See OAuth2ProviderAuth.

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

SpotifyTokens#

type SpotifyTokens = {
	accessToken: string;
	tokenType: string;
	scope: string;
	accessTokenExpiresIn: number;
	refreshToken: string;
};

SpotifyUser#

type SpotifyUser = {
	country?: string;
	display_name: string | null;
	email?: string;
	explicit_content: {
		filter_enabled?: boolean;
		filter_locked?: boolean;
	};
	external_urls: {
		spotify: string;
	};
	followers: {
		href: string | null;
		total: number;
	};
	href: string;
	id: string;
	images: [
		{
			url: string;
			height: number | null;
			width: number | null;
		}
	];
	product?: string;
	type: string;
	uri: string;
};

SpotifyUserAuth#

Extends ProviderUserAuth.

interface SpotifyUserAuth<_Auth extends Auth> extends ProviderUserAuth<_Auth> {
	appleUser: SpotifyUser;
	appleTokens: SpotifyTokens;
}
propertiestypedescription
appleUserSpotifyUserSpotify user
appleTokensSpotifyTokensAccess tokens etc
Generics#
nameextends
_AuthAuth