Implementing login in Sinatra

3,196 views
Skip to first unread message

Cesare

unread,
May 4, 2011, 12:46:22 PM5/4/11
to sinatrarb
I am developing a webapp in Sinatra and now I am working on the
implementation of the login functionality. I have seen a few examples:

https://github.com/ratbeard/sinatra-warden
https://github.com/nanodeath/SinatraHamlSignin
https://github.com/maxjustus/sinatra-authentication

but some seem pretty outdated. I did not find a decent tutorial about
the matter. Any suggestion?

ps: I plan to deploy the app on heroku, probably with an ssl
certificate installed.

k.h...@finn.de

unread,
May 4, 2011, 1:13:48 PM5/4/11
to sina...@googlegroups.com
I usually do authenticatin on my own



-- Gesendet von meinem Palm Pre


--
You received this message because you are subscribed to the Google Groups "sinatrarb" group.
To post to this group, send email to sina...@googlegroups.com.
To unsubscribe from this group, send email to sinatrarb+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sinatrarb?hl=en.

Charlie Park

unread,
May 4, 2011, 6:46:59 PM5/4/11
to sina...@googlegroups.com
I can't speak to how outdated they are, but if an OAuth solution would work for you — where users can use their Twitter / Facebook credentials to log in on your site — I wrote a very simple Sinatra implementation of OmniAuth, here: https://github.com/charliepark/omniauth-for-sinatra.

All you need are your auth keys from Twitter or whomever, and you're good to go. You can always then request your user's e-mail address or other contact info, if you need to reach them directly later on.

Sylvain Desvé

unread,
May 5, 2011, 3:15:49 AM5/5/11
to sina...@googlegroups.com
I do on my own to, it's not that difficult.

Here is a tutorial :

It's Rails oriented but it's not very difficult to adapt for Sinatra.

Cesare

unread,
May 5, 2011, 5:07:01 AM5/5/11
to sinatrarb
Yes, it's easy but I am wondering, is it "safe"?
"is is safe?" = "can I sleep tight?"

-c.

On May 5, 9:15 am, Sylvain Desvé <sylvain.de...@gmail.com> wrote:
> I do on my own to, it's not that difficult.
>
> Here is a tutorial :http://railscasts.com/episodes/250-authentication-from-scratch
>
> <http://railscasts.com/episodes/250-authentication-from-scratch>It's Rails
> oriented but it's not very difficult to adapt for Sinatra.
>
> 2011/5/4 k.ha...@finn.de <k.ha...@finn.de>
>
>
>
> > I usually do authenticatin on my own
>
> > -- Gesendet von meinem Palm Pre
>
> > ------------------------------

Cesare

unread,
May 5, 2011, 5:07:45 AM5/5/11
to sinatrarb
I gave omniauth a thought/try but I'd prefer my own login system.
Thanks for the suggestion.

On May 5, 12:46 am, Charlie Park <char...@pearbudget.com> wrote:
> I can't speak to how outdated they are, but if an OAuth solution would work
> for you — where users can use their Twitter / Facebook credentials to log in
> on your site — I wrote a *very* simple Sinatra implementation of OmniAuth,

Jeremy Cowgar

unread,
May 5, 2011, 3:50:51 PM5/5/11
to sina...@googlegroups.com
Just take a peek at some of the existing auth systems. I also roll my
own as each system has different requirements and I have not been able
to find a one size fits all solution. It's not hard to make them and
not hard to make them safe. It's also not hard to make them unsafe
either, so just be sure you know what you are doing.

setcookie: current_user="jdoe" is NOT safe, LOL!

Jeremy

Cesare

unread,
May 7, 2011, 9:22:30 AM5/7/11
to sinatrarb
Ended up with rack, sessions and salted Passwords.
Probably will integrate omni auth in the next release.

Paolo Perego

unread,
May 9, 2011, 3:53:42 AM5/9/11
to sina...@googlegroups.com
On 5 May 2011 11:07, Cesare <cesare...@gmail.com> wrote:
> I gave omniauth a thought/try but I'd prefer my own login system.
> Thanks for the suggestion.
Hi Cesare, please note that re-inventing the wheel instead of using
well known and widely tested solutions for basic tasks (as auth) can
be risky from a security point of view.

Make sure to check your code with a penetration test or at least
against session fixation vulnerability.

Paolo
--
"... static analysis is fun, again!"

OWASP Orizon project leader, http://github.com/thesp0nge/owasp-orizon
OWASP Esapi Ruby project leader, https://github.com/thesp0nge/owasp-esapi-ruby

Jeremy Cowgar

unread,
May 9, 2011, 7:48:00 AM5/9/11
to sina...@googlegroups.com
Implementing an existing solution can be a security risk as well.
Something as important as security should be understood indepth and
internally.

Jeremy

On Mon, May 9, 2011 at 3:53 AM, Paolo Perego <thes...@gmail.com> wrote:
> Hi Cesare, please note that re-inventing the wheel instead of using
> well known and widely tested solutions for basic tasks (as auth) can
> be risky from a security point of view.
>
> Make sure to check your code with a penetration test or at least
> against session fixation vulnerability.
>
> Paolo
> --
> "... static analysis is fun, again!"
>
> OWASP Orizon project leader, http://github.com/thesp0nge/owasp-orizon
> OWASP Esapi Ruby project leader, https://github.com/thesp0nge/owasp-esapi-ruby
>

rjjm

unread,
May 11, 2011, 5:34:23 AM5/11/11
to sinatrarb
Hi Cesare,

I'd have to agree with the consensus. There is no easy answer to
authentication in the first instance, it's one of those learning
curves that I resisted for too long.

The best solution I found was to take an existing solution (like
https://github.com/maxjustus/sinatra-authentication) and alter it to
my needs.

At the same time take a look at the authentication tutorials mentioned
on railscasts and this one I found useful:
http://ididitmyway.heroku.com/past/2011/2/22/really_simple_authentication_in_sinatra/

I also found the detailed explanation in Agile Dev with Rails quite
helpful: http://pragprog.com/titles/rails2/agile-web-development-with-rails

Once you have implemented one of the 'out-of-the-box' solutions from
github you should be able to apply the lessons from the tutorials. At
least, that's how it worked for me.

HTH,
Robin



On May 4, 5:46 pm, Cesare <cesareroc...@gmail.com> wrote:
> I am developing a webapp in Sinatra and now I am working on the
> implementation of the login functionality. I have seen a few examples:
>
> https://github.com/ratbeard/sinatra-wardenhttps://github.com/nanodeath/SinatraHamlSigninhttps://github.com/maxjustus/sinatra-authentication

djangst

unread,
May 11, 2011, 11:02:43 AM5/11/11
to sinatrarb
Reply all
Reply to author
Forward
0 new messages