Authentication with Absinthe subscriptions

some context:
I’m trying to setup a grphql server with phoenix + absinthe to talk with a react native app.
On the app I’m using apollo and apollo-phoenix-websocket to push all the requests through websockets, now I’m trying to implement subscriptions with the new absinthe.
How do i manage authorization ? I was previously using a custom channel “gql:query” with an authorization header and I did the authentication in my channel like so

def join("gql:query", %{"authorization" => token}, socket) do
	case Phoenix.Token.verify(socket, "user salt", token, max_age: 86_400) do
		{:ok, user_id} ->
			socket = assign(socket, :user, Repo.get!(User, user_id))
			{:ok, %{message: "Joined"}, socket}
		{:error, _} ->
			:error
	end
end

Now I see absinthe expect something similar for GET/POST (http://absinthe-graphql.org/guides/context-and-authentication/)
but I don’t understand if I can implement something similar with the new Absinthe as it suggests to use Absinthe.Phoenix.Socket but I can’t touch the parameters of join/3

1 Like

checkout verily it’s a demo app I did for showcasing exactly what you are looking for.

And for execution context while using websockets, see this PR

3 Likes