Created
October 10, 2008 22:35
-
-
Save bradly/16171 to your computer and use it in GitHub Desktop.
Merb Stack Authentication Setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Merb Stack Authentication Setup | |
# create your app | |
$ merb-gen app authentication_app | |
$ cd authentication_app | |
# migrate the default user model | |
$ rake db:auto_migrate | |
# create a user | |
$ merb -i | |
>> u = User.new | |
>> u.login = 'joe' | |
>> u.password = u.password_confirmation = 'password' | |
>> u.save | |
>> exit | |
# create a resource to protect | |
$ merb-gen resource secret | |
# require authentication on resource | |
# secrets.rb | |
class Secrets < Application | |
before :ensure_authenticated | |
... | |
end | |
# add route for resource | |
# router.rb | |
Merb::Router.prepare do | |
resources :secrets | |
... | |
end | |
# start your app | |
$ merb | |
# test access to your resource before authentication is denied | |
http://localhost:4000/secrets | |
#login | |
http://localhost:4000/login | |
# test access to your resource before authentication is granted | |
http://localhost:4000/secrets | |
# test basic authentication | |
$ curl username:password@localhost:4000/secrets | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment