manukall / phoenix_token_auth

Token authentication solution for Phoenix. Useful for APIs for e.g. single page apps.
MIT License
163 stars 39 forks source link

Working with ember simple auth #15

Closed alexjp closed 9 years ago

alexjp commented 9 years ago

Hi, Thanks for the plugin.

I managed to make it work with an existing ember app. The ember app is using simple auth with oauth2 bearer.

For it to work i had to make a few changes: In the sessions controller, something like this:

def create(conn, %{"email" => email, "password" => password}) do
    case Authenticator.authenticate(email, password) do
      {:ok, token} ->
        user_json = %{id: "1"}
        json conn, %{access_token: token, token_type: "bearer", user: user_json}

      {:error, errors} -> Util.send_error(conn, errors, 401)
    end
  end

In here seems that simple auth needs the user id in the token reply, as also access_token key, not only token.

Also, would it be possible to allow identification with username instead of email ?

SebastianSzturo commented 9 years ago

Great to hear that you made it work. :+1: I am just about to try to make it work myself. Which ember-simple-auth authenticator did you use?

alexjp commented 9 years ago

I used: https://github.com/simplabs/ember-simple-auth/tree/master/packages/ember-simple-auth-oauth2

Simple auth configuration seems pretty standard, as long as it receives the correct json from the server ( with access_token and user id ... if user_id is missing, i got alot of trouble ).

If anything i can help, let me know !

manukall commented 9 years ago

hey, great to hear that you got it to work with ember.

i think the easiest way to change the data returned after signing in for now would be to just create your own controller for that. you could just put the code you pasted above into that controller, add a route for it and just use that from your ember app.

identification via username would indeed be nice, but everything i can think of now would increase complexity a lot. if you can think of something nice, let me know.