Skip to content

Instantly share code, notes, and snippets.

@bradly
Created October 10, 2008 22:35
Show Gist options
  • Save bradly/16171 to your computer and use it in GitHub Desktop.
Save bradly/16171 to your computer and use it in GitHub Desktop.
Merb Stack Authentication Setup
# 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