Add basic web finger support
This commit is contained in:
parent
541e329dc4
commit
f3995911d7
|
@ -0,0 +1,33 @@
|
||||||
|
defmodule ClacksWeb.WebFingerController do
|
||||||
|
use ClacksWeb, :controller
|
||||||
|
alias Clacks.Actor
|
||||||
|
|
||||||
|
@acct_regex ~r/(?:acct:)?([a-z0-9_]+)(?:@.+)?/i
|
||||||
|
|
||||||
|
def get(conn, %{"resource" => resource}) do
|
||||||
|
with [_, nickname] <- Regex.run(@acct_regex, resource),
|
||||||
|
%Actor{local: true} = actor <- Actor.get_by_nickanme(nickname) do
|
||||||
|
url = Application.get_env(:clacks, ClacksWeb.Endpoint)[:url]
|
||||||
|
host = url[:host]
|
||||||
|
port = url[:port]
|
||||||
|
maybe_port = if port == URI.default_port(url[:scheme]), do: "", else: ":#{port}"
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> json(%{
|
||||||
|
"subject" => "acct:#{actor.nickname}@#{host}#{maybe_port}",
|
||||||
|
"links" => [
|
||||||
|
%{
|
||||||
|
"rel" => "self",
|
||||||
|
"type" => "application/activity+json",
|
||||||
|
"href" => actor.ap_id
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
else
|
||||||
|
_ ->
|
||||||
|
conn
|
||||||
|
|> put_status(404)
|
||||||
|
|> json(%{error: "No such resource"})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -22,6 +22,8 @@ defmodule ClacksWeb.Router do
|
||||||
|
|
||||||
get "/objects/:id", ObjectsController, :get
|
get "/objects/:id", ObjectsController, :get
|
||||||
get "/users/:nickname", ActorController, :get
|
get "/users/:nickname", ActorController, :get
|
||||||
|
|
||||||
|
get "/.well-known/webfinger", WebFingerController, :get
|
||||||
end
|
end
|
||||||
|
|
||||||
# Other scopes may use custom stacks.
|
# Other scopes may use custom stacks.
|
||||||
|
|
Loading…
Reference in New Issue