Store Last.fm API key with encrypted secret
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
defmodule MusicLibraryWeb.LastFmController do
|
||||
use MusicLibraryWeb, :controller
|
||||
|
||||
def callback(conn, %{"token" => token}) do
|
||||
case LastFm.get_session(token) do
|
||||
{:ok, session} ->
|
||||
conn
|
||||
|> put_session(:last_fm_user, session.name)
|
||||
|> put_session(:last_fm_key, session.key)
|
||||
|> put_flash(:info, "Successfully authenticated with Last.fm.")
|
||||
|> redirect(to: ~p"/")
|
||||
alias MusicLibrary.Secrets
|
||||
|
||||
def callback(conn, %{"token" => token}) do
|
||||
with {:ok, session} <- LastFm.get_session(token),
|
||||
{:ok, _secret} <- Secrets.store("last_fm_key", session.key) do
|
||||
conn
|
||||
|> put_flash(:info, gettext("Successfully connected your Last.fm account"))
|
||||
|> redirect(to: ~p"/")
|
||||
else
|
||||
{:error, reason} ->
|
||||
conn
|
||||
|> put_flash(:error, "Failed to authenticate with Last.fm: #{reason}")
|
||||
|> put_flash(:error, "Failed to connect your Last.fm account: #{reason}")
|
||||
|> redirect(to: ~p"/")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user