Redirect to Last.fm and receive a token (unused)
This commit is contained in:
@@ -24,6 +24,10 @@ if api_key = System.get_env("LAST_FM_API_KEY") do
|
|||||||
config :music_library, LastFm, api_key: api_key
|
config :music_library, LastFm, api_key: api_key
|
||||||
end
|
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
|
if user = System.get_env("LAST_FM_USER") do
|
||||||
config :music_library, LastFm, user: user
|
config :music_library, LastFm, user: user
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -41,5 +41,10 @@ defmodule LastFm do
|
|||||||
end
|
end
|
||||||
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)
|
defp last_fm_config, do: LastFm.Config.resolve(:music_library)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
defmodule LastFm.Config do
|
defmodule LastFm.Config do
|
||||||
@type t :: %__MODULE__{
|
@type t :: %__MODULE__{
|
||||||
api_key: String.t(),
|
api_key: String.t(),
|
||||||
|
shared_secret: String.t(),
|
||||||
user: String.t(),
|
user: String.t(),
|
||||||
auto_refresh: boolean(),
|
auto_refresh: boolean(),
|
||||||
refresh_interval: pos_integer(),
|
refresh_interval: pos_integer(),
|
||||||
@@ -10,6 +11,7 @@ defmodule LastFm.Config do
|
|||||||
|
|
||||||
@enforce_keys [:api_key, :user]
|
@enforce_keys [:api_key, :user]
|
||||||
defstruct api_key: "",
|
defstruct api_key: "",
|
||||||
|
shared_secret: "",
|
||||||
user: "",
|
user: "",
|
||||||
auto_refresh: true,
|
auto_refresh: true,
|
||||||
refresh_interval: 60_000,
|
refresh_interval: 60_000,
|
||||||
@@ -21,6 +23,10 @@ defmodule LastFm.Config do
|
|||||||
type: :string,
|
type: :string,
|
||||||
required: true
|
required: true
|
||||||
],
|
],
|
||||||
|
shared_secret: [
|
||||||
|
type: :string,
|
||||||
|
required: true
|
||||||
|
],
|
||||||
user: [
|
user: [
|
||||||
type: :string,
|
type: :string,
|
||||||
required: true
|
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>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</.form>
|
</.form>
|
||||||
|
<a href={LastFm.auth_url()} class="flex items-center justify-center">
|
||||||
|
Connect to Last.fm
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ defmodule MusicLibraryWeb.Router do
|
|||||||
get "/login", SessionController, :new
|
get "/login", SessionController, :new
|
||||||
post "/sessions/create", SessionController, :create
|
post "/sessions/create", SessionController, :create
|
||||||
|
|
||||||
|
get "/auth/last_fm/callback", LastFmController, :callback
|
||||||
|
|
||||||
scope "/" do
|
scope "/" do
|
||||||
pipe_through :logged_in
|
pipe_through :logged_in
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user