Redirect to Last.fm and receive a token (unused)

This commit is contained in:
Claudio Ortolina
2025-05-05 19:19:12 +01:00
parent 9e458b07df
commit 7c547f2d80
6 changed files with 27 additions and 0 deletions
+4
View File
@@ -24,6 +24,10 @@ if api_key = System.get_env("LAST_FM_API_KEY") do
config :music_library, LastFm, api_key: api_key
end
if shared_secret = System.get_env("LAST_FM_SHARED_SECRET") do
config :music_library, LastFm, shared_secret: shared_secret
end
if user = System.get_env("LAST_FM_USER") do
config :music_library, LastFm, user: user
end
+5
View File
@@ -41,5 +41,10 @@ defmodule LastFm do
end
end
def auth_url do
last_fm_config = last_fm_config()
"https://www.last.fm/api/auth/?api_key=" <> last_fm_config.api_key
end
defp last_fm_config, do: LastFm.Config.resolve(:music_library)
end
+6
View File
@@ -1,6 +1,7 @@
defmodule LastFm.Config do
@type t :: %__MODULE__{
api_key: String.t(),
shared_secret: String.t(),
user: String.t(),
auto_refresh: boolean(),
refresh_interval: pos_integer(),
@@ -10,6 +11,7 @@ defmodule LastFm.Config do
@enforce_keys [:api_key, :user]
defstruct api_key: "",
shared_secret: "",
user: "",
auto_refresh: true,
refresh_interval: 60_000,
@@ -21,6 +23,10 @@ defmodule LastFm.Config do
type: :string,
required: true
],
shared_secret: [
type: :string,
required: true
],
user: [
type: :string,
required: true
@@ -0,0 +1,7 @@
defmodule MusicLibraryWeb.LastFmController do
use MusicLibraryWeb, :controller
def callback(conn, %{"token" => _token}) do
conn |> redirect(to: ~p"/")
end
end
@@ -35,5 +35,8 @@
</button>
</div>
</.form>
<a href={LastFm.auth_url()} class="flex items-center justify-center">
Connect to Last.fm
</a>
</div>
</div>
+2
View File
@@ -29,6 +29,8 @@ defmodule MusicLibraryWeb.Router do
get "/login", SessionController, :new
post "/sessions/create", SessionController, :create
get "/auth/last_fm/callback", LastFmController, :callback
scope "/" do
pipe_through :logged_in