Skip to content

AuthStructure

Defined in: src/structures/auth.ts:7

new AuthStructure(client: FMClient): AuthStructure;

Defined in: src/structures/auth.ts:10

FMClient

AuthStructure

getCallbackUrl(url: string): string | false;

Defined in: src/structures/auth.ts:76

Constructs Last.fm authentication site URL from the API key and URL. Last.fm will redirect to your callback URL, supplying an authentication token as a GET variable.

string

Custom callback URL.

string | false

URL to Last.fm app authentication site with callback URL, or false if the provided URL is an empty string.

const callbackUrl = fm.auth.getCallbackUrl("https://example.com/callback");
if (callbackUrl) {
console.log(`Auth URL with callback: ${callbackUrl}`);
}

getMobileSession(options: AuthGetMobileSessionOptions): Promise<SessionResponse>;

Defined in: src/structures/auth.ts:137

Fetches a valid session from Last.fm with the provided credentials.

AuthGetMobileSessionOptions

The options. See AuthGetMobileSessionOptions.

Promise<SessionResponse>

Session response.

  • Success: { success: true, session: LastFmSession }
  • Failure: { success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | number | string, errorMsg: string }
const res = await fm.auth.getMobileSession({
username: "USERNAME",
password: "PASSWORD",
});
if (res.success) {
console.log(`Session key: ${res.session.key}`);
}

getSession(token: string): Promise<SessionResponse>;

Defined in: src/structures/auth.ts:99

Fetches a valid session from Last.fm for specified token.

string

Same authentication token used in getUrl.

Promise<SessionResponse>

Session response.

  • Success: { success: true, session: LastFmSession }
  • Failure: { success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | number | string, errorMsg: string }
const res = await fm.auth.getSession("authorized_token");
if (res.success) {
console.log(`Session key: ${res.session.key}`);
}

getToken(): Promise<TokenResponse>;

Defined in: src/structures/auth.ts:29

This will return a token. It’s valid for 60 minutes from the moment it’s granted.

Promise<TokenResponse>

Token needed in getUrl and getSession to obtain session key for the user.

  • Success: { success: true, token: string }
  • Failure: { success: false, errorCode: ErrorCodes.NO_TOKEN | number | null, errorMsg: string }
const res = await fm.auth.getToken();
if (res.success) {
console.log(`Token: ${res.token}`);
}

getUrl(token: string): string | false;

Defined in: src/structures/auth.ts:54

Constructs Last.fm authentication site URL from the API key and token.

string

Authentication token from getToken.

string | false

URL to Last.fm app authentication site, or false if the provided token is an empty string.

const url = fm.auth.getUrl("your_auth_token");
if (url) {
console.log(`Auth URL: ${url}`);
}