AuthStructure
Defined in: src/structures/auth.ts:7
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AuthStructure(client: FMClient): AuthStructure;Defined in: src/structures/auth.ts:10
Parameters
Section titled “Parameters”client
Section titled “client”Returns
Section titled “Returns”AuthStructure
Methods
Section titled “Methods”getCallbackUrl()
Section titled “getCallbackUrl()”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.
Parameters
Section titled “Parameters”string
Custom callback URL.
Returns
Section titled “Returns”string | false
URL to Last.fm app authentication site with callback URL, or false if the provided URL is an empty string.
Example
Section titled “Example”const callbackUrl = fm.auth.getCallbackUrl("https://example.com/callback");
if (callbackUrl) { console.log(`Auth URL with callback: ${callbackUrl}`);}getMobileSession()
Section titled “getMobileSession()”getMobileSession(options: AuthGetMobileSessionOptions): Promise<SessionResponse>;Defined in: src/structures/auth.ts:137
Fetches a valid session from Last.fm with the provided credentials.
Parameters
Section titled “Parameters”options
Section titled “options”The options. See AuthGetMobileSessionOptions.
Returns
Section titled “Returns”Promise<SessionResponse>
Session response.
- Success:
{ success: true, session: LastFmSession } - Failure:
{ success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | number | string, errorMsg: string }
Example
Section titled “Example”const res = await fm.auth.getMobileSession({ username: "USERNAME", password: "PASSWORD",});
if (res.success) { console.log(`Session key: ${res.session.key}`);}getSession()
Section titled “getSession()”getSession(token: string): Promise<SessionResponse>;Defined in: src/structures/auth.ts:99
Fetches a valid session from Last.fm for specified token.
Parameters
Section titled “Parameters”string
Same authentication token used in getUrl.
Returns
Section titled “Returns”Promise<SessionResponse>
Session response.
- Success:
{ success: true, session: LastFmSession } - Failure:
{ success: false, errorCode: ErrorCodes.MISSING_REQUIREMENTS | number | string, errorMsg: string }
Example
Section titled “Example”const res = await fm.auth.getSession("authorized_token");
if (res.success) { console.log(`Session key: ${res.session.key}`);}getToken()
Section titled “getToken()”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.
Returns
Section titled “Returns”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 }
Example
Section titled “Example”const res = await fm.auth.getToken();
if (res.success) { console.log(`Token: ${res.token}`);}getUrl()
Section titled “getUrl()”getUrl(token: string): string | false;Defined in: src/structures/auth.ts:54
Constructs Last.fm authentication site URL from the API key and token.
Parameters
Section titled “Parameters”string
Authentication token from getToken.
Returns
Section titled “Returns”string | false
URL to Last.fm app authentication site, or false if the provided token is an empty string.
Example
Section titled “Example”const url = fm.auth.getUrl("your_auth_token");
if (url) { console.log(`Auth URL: ${url}`);}