Closed thbar closed 8 years ago
Thanks for the feedback. This is really useful because I don't know Devise that well myself, but I know that there will be a lot of developers out there who will come to Openmaize from Devise and Ruby. It's also interesting to see how you're using it - especially as I thought that roles were so central :) I'll work on adding something to the docs about this.
Great, thanks for considering this! Hit me up if you have any question, and I'll make sure to share more here if I have more questions.
Thanks for sharing this @thbar - I'm also migrating a Rails app to Phoenix using Openmaize, but in my case it's a complete rewrite so it was OK for me just to drop the role
column there, even though I don't use roles in my app.
I don't see roles as a central part of an authentication library, but maybe this is because I come from Devise, that doesn't implement roles (you manage them at a different level).
I've decided to remove the need for a user role, and so in the latest versions of Openmaize (1.0.0-beta.4) and OpenmaizeJWT (0.12), I've removed the need for the role to be set, so you can create and verify tokens without a user role being specified. I'm also going to make a few changes to the Authorize modules that are created by the mix generators - to make it more clear how you can use / customize them with or without user roles.
A couple of updates:
mix openmaize.gen.ectodb
, there is no need to add db_module: OpenmaizeEcto
to the call to plug. This means that the initial example you gave can now be written as plug Openmaize.Login, [unique_id: :email] when action in [:login_user]
.
Hi there! First, thanks for openmaize, which I'm starting to use to achieve authentication against an existing Rails/devise database (gradual rewrite of app from Rails to Phoenix).
It took me a bit of time to figure this out so I thought I'd share it here - maybe this is worth adding to the readme (e.g. "migrating from Rails & devise" section), since I suspect more people will do this in the upcoming months.
The first obvious steps to get this working were in the config:
and in my controller:
That was the easy part; the harder one was around the
role
column.The database
users
table hasn't got arole
column in devise (at least not by default). Initially I just tweaked the code inweb/controllers/authorize/ to fix pattern matching against
role(which didn't work), but
current_userwasn't set after that. I dig into openmaize-jwt and ended up seeing that because the
role` key was missing, I got an "incomplete token" error.Ultimately I used a virtual field with a default value for
role
, which seems to work fine:Hope this helps others :-)