Functions for the Last.fm authentication flow.
Write operations need a session key, obtained by having the user authorize your API key. Session keys do not expire, so store them alongside the user.
The desktop flow is token/0 → url/1 → session/1. The web flow skips
token/0: send the user to https://www.last.fm/api/auth/?api_key=YOUR_KEY,
and Last.fm redirects to your registered callback with a token query
parameter to pass to session/1. Tokens are single-use and valid for 60
minutes.
Summary
Functions
Creates a session directly from a username and password (auth.getMobileSession).
Exchanges an authorized token for a session key (auth.getSession).
Fetches an unauthorized request token (auth.getToken).
Builds the URL at which a user authorizes a request token.
Functions
Creates a session directly from a username and password (auth.getMobileSession).
Only for applications where the user enters credentials into your own UI, and requires the mobile authentication permission on your API account.
{:ok, %{"session" => %{"key" => session_key}}} =
Lastex.Auth.mobile_session("username", "password")
Exchanges an authorized token for a session key (auth.getSession).
{:ok, %{"session" => %{"key" => session_key, "name" => username}}} =
Lastex.Auth.session(token)
Fetches an unauthorized request token (auth.getToken).
The user must authorize the token at url/1 before it can be exchanged for a
session key.
{:ok, %{"token" => token}} = Lastex.Auth.token()
Builds the URL at which a user authorizes a request token.
Lastex.Auth.url(token)
#=> "https://www.last.fm/api/auth/?api_key=YOUR_KEY&token=TOKEN"