Sample of Grape + Warden

1,240 views
Skip to first unread message

William Afendy

unread,
Mar 15, 2013, 5:01:37 AM3/15/13
to ruby-...@googlegroups.com
I've read this article (http://code.dblock.org/grape-api-authentication-w-devise) by dblockdotorg, but I'm still having problem implementing any Authentication into Grape. Just to be clear that I'm very new to Ruby, so it seems like the article is written for Ruby programmers who are already familiar with Rack and Rails framework. 

I would like to build an API server that can only be accessed by authenticated users. After doing some research, I came down to 2 options to build such API app in Ruby, either using Sinatra or Grape. I always hit a brick wall when I am trying to implement the Authentication part with either of these gems. 

This is the setup I'm working on now (Rack => Grape => Devise/Warden), the reason I chose Grape because of many articles talk about it and agree that it is the best choice to build such API app. However I am unable to find a complete example how these 3 gems work together, all the examples I found only talking about code snippets, and I'm having a lot of problem putting together these snippets into a working API app. 

Am I in the right direction here? Is there a better option?

Thanks,


William

Daniel Doubrovkine

unread,
Mar 15, 2013, 1:30:39 PM3/15/13
to ruby-...@googlegroups.com
I think you're on the right track, Rack + Grape works well with Warden.

Put up on Github a very simple Grape API with an attempt of protecting it with Warden. Write tests that fail and I'll help you figure out what the issues are.


--
You received this message because you are subscribed to the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

dB. | Moscow - Geneva - Seattle - New York
dblock.org - @dblockdotorg

Adam Williams

unread,
Mar 17, 2013, 2:51:20 PM3/17/13
to ruby-...@googlegroups.com
William,

I have been working to remove Devise on the app I'm working on, as we have a very sophisticated mechanism for defining 'authenticated'. However, we are still using Warden and Grape, and Devise is not all that difficult to comprehend once you realize it is managing Warden - it wires Warden into Rails and defines Warden::Strategies from/for your Device user models (through mechanisms like database_authenticatable, token_authenticatable). You would need to use rails_warden if you didn't use Devise.

The key to understanding the interaction of Rack, Warden, and Grape is understanding Warden and how it is accessed in the Rack Grape::Endpoints, assuming you've configured Warden according to Devise or rails_warden instructions. Neither of those tools, however, provide everything you need for accessing those Warden things from a Grape::API.

Check out this gist and see if it helps: https://gist.github.com/aiwilliams/5174567

@aiwilliams


William Afendy

unread,
Mar 18, 2013, 1:08:04 AM3/18/13
to ruby-...@googlegroups.com
Daniel,

This is my first attempt writing a simple app using the example from Grape, combined with the Setup documentation on Warden. But I'm getting "not opened for reading" error when accessing http://localhost:9292/warden

As suggested, I created a simple setup on github here is the url https://github.com/wafendy/grape_warden

Sorry that I'm completely clueless with Rack and Warden Setup.


William






--
You received this message because you are subscribed to a topic in the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ruby-grape/E2SfcrCa4NU/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to ruby-grape+...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
William Afendy

William Afendy

unread,
Mar 18, 2013, 3:50:58 AM3/18/13
to ruby-...@googlegroups.com
Daniel,

I made a little progress after upgrading to Grape 0.4.0. I updated the repository on github.

William
--
William Afendy

Daniel Doubrovkine

unread,
Mar 23, 2013, 3:03:51 PM3/23/13
to ruby-...@googlegroups.com
Your code is actually working now. I made some improvements in https://github.com/wafendy/grape_warden/pull/1.

I think you should clean this up, add a README with some explanations, maybe do a bit of refactoring. This will be a good example to add to the wiki for those trying to implement warden from scratch.

Hope it helps.

cheers
dB.

Thimios Dimopulos

unread,
Apr 9, 2015, 6:25:03 AM4/9/15
to ruby-...@googlegroups.com
that example is currently offline. Would have been great to take a look at it. Does someone have a pointer to another example of integrating warden in grape when using grape without rails?

Thanks

Daniel Doubrovkine

unread,
Apr 9, 2015, 7:16:16 AM4/9/15
to ruby-...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages