This message was deleted.
# general
m
This message was deleted.
n
Hi Martin - I've just seen your GitHub issue and now found your message; I've been pushing Ory a lot with elixir and have it integrated and working with Phoenix Framework. I hope to find some time in the near future to break this out and create an independent example in https://github.com/ory/examples/
Time flies; I've opened a draft PR where you can see basic login/registration flows. Planning to implement more flows and cleanup the form rendering components in future. 🙂 https://github.com/ory/examples/pull/74
d
@numerous-dawn-55367 - this is awesome. I have been kicking around integrating into a Phoenix app. Any particular reason you didn't implement in LiveView?
n
Not particularly, it could be quite easily moved to LiveView with flow data on the socket I imagine
d
Yeah, I think the gen-auth makes use of an on_mount hook.
This is awesome though
t
Nice @numerous-dawn-55367! I'll take a look at your PR and see if I can figure out what I'm doing wrong. Stuck on getting the session data, maybe you can spot where I'm messing up? 🙂
Copy code
defp check_session(%Plug.Conn{} = conn) do
    connection = Ory.Connection.new([{"token", "Bearer MY_TOKEN"}])

    [cookies] = Plug.Conn.get_req_header(conn, "cookie")

    case Ory.Api.Frontend.to_session(connection, [{"Cookie", cookies}]) do
      {:ok, %Ory.Model.Session{} = session} ->
        {:ok, session}

      {:ok, %Ory.Model.ErrorGeneric{} = err} ->
        {:error, err}

      {:error, %Tesla.Env{} = err} ->
        {:error, err}

      {:error, err} ->
        {:error, err}
    end
  end
Keep getting the error
Copy code
** (FunctionClauseError) no function clause matching in Tesla.put_header/3
when I call it like you do in your example:
Copy code
case Ory.Api.Frontend.to_session(connection, Cookie: cookies) do
n
Are you using the latest client version? The generated tesla client was broken previously; and also I’ve found generally a better success of passing the cookies to Ory when stringifying them in a
key=value;
manor https://github.com/tobbbles/examples/blob/a18a92fda34d66c121042a2f9a910b1aa373c04e/elixir-ory-network/lib/example_web/helpers.ex#L6
t
Yeah, I just tried using the client from git master (where you merged the PR to update the OpenAPI Generator), works now! Awesome job 🙂
Working on a GraphQL API so I'm really excited about trying to use Kratos for identity management and maybe getting Keto to work as a permission middleware in Absinthe.
@numerous-dawn-55367 Have you had any luck using an access token with Ory.Connection?
n
I've not - I'm guessing you're trying to hit the admin endpoints and trying to supply an auth token that way?
t
Yeah. Trying to use Ory.Api.Permissions, but I can't for the life of me get it working with the token. Ory.Connection.New("TOKEN") doesn't work as far as I can tell.
n
I (unfortunately) wouldn't be surprised if there's a fair bit of broken functionality in the generated client that has never been discovered yet; Are you able to debug the tesla request to just double check if the header is being attached to the client requests with
config :tesla, Tesla.Middleware.Logger, debug: true
in the config?
t
I can see that the header is attached, but it fails either way. I think you're right in that there's a lot of broken functionality. Getting this error:
Copy code
** (FunctionClauseError) no function clause matching in anonymous fn/1 in Tesla.Adapter.Httpc.request/2
        (tesla 1.7.0) lib/tesla/adapter/httpc.ex:55: anonymous fn("authorization") in Tesla.Adapter.Httpc.request/2
From this call:
Copy code
Ory.Api.Relationship.list_relationship_namespaces(
        Ory.Connection.new("Bearer MY_TOKEN")
      )
n
I'd suggest for now avoiding the
Ory.Connection
model and try to make a Tesla client yourself with the correct BearerAuth middleware attached and pass that to your admin operation functions; You'll see an example client implementation here; https://hexdocs.pm/tesla/Tesla.Middleware.BearerAuth.html And how you can plug the base url stuff etc at https://hexdocs.pm/tesla/readme.html If that works well, then I think this is the recommended way of creating authenticated clients for admin operations with the SDK, until overhauling the upstream generated elixir client
I just did some local checking and the it definitely seems like a bad way the generated clients use tokens; using the following
Copy code
client = Tesla.client([
  {Tesla.Middleware.BearerAuth, token: "MY_TOKEN"},
  Tesla.Middleware.EncodeJson,
  {Tesla.Middleware.BaseUrl, "<https://my-project.projects.oryapis.com>"}
])
supplied as a client it works happily
t
Custom client worked perfectly! Really appreciate the help, saved me hours of pain and frustration here 🙂
n
Happy to help! I think Ory is a great pairing for the Elixir eco-system; and we just have to work out the issues. 🙂
👍 1