際際滷

際際滷Share a Scribd company logo
Rails 3 and OAuth




BarCamp Tampa, September 26, 2010
Who am I?

Hello, Im Bryce.
I snuck up here from Miami.
I make web applications with Ruby on
Rails.
I tweet as @bonzoesc
Quick Disclaimer

This used to be two
presentations but I
 combined them.
    Thanks for your cooperation!
What is Rails?
Ruby on Rails速 is an open-source web
framework thats optimized for
programmer happiness and sustainable
productivity. It lets you write beautiful
code by favoring convention over
con guration.
                   - http://rubyonrails.org/
What is Rails?

 Rails is a way to build
web applications quickly
and be able to maintain
  them in the future.
What is Rails?
Twitter      Scribd
Hulu         Less Accounting
Basecamp     Shopify
Groupon      Get Satisfaction
Lighthouse   Urban Dictionary
Github       Kongregate
What is Rails?



Four main parts
What is Rails?

ActiveRecord
turns database into
Ruby objects
What is Rails?

ActionController
turns web requests
into Ruby method
calls
What is Rails?

ActionView
turns Ruby code into
web responses
What is Rails?

Railties
turns the parts into
Rails
History
So What?


Rails 3 feels like Rails
in the right places.
So What?


Rails 3 is as exible as
Merb.
The Speci cs
ActiveRecord
 Database interactions
ActiveRecord Classic
@published = Post.鍖nd(
  :all,
  :where=>{:published=>true},
  :order=>'created_at desc'
)

@unpublished = Post.鍖nd(
  :all,
  :where=>:published=>false},
  :order=>'created_at desc'
)
ActiveRecord Arel


@ordered = Post.order('created_at asc')
@published = @ordered.where(:published=>true)
@unpublished = @ordered.where(:published=>false)
ActiveRecord Arel

Compositional
Chainable
Less code
Lazy
ActiveModel

   Put the ActiveRecord
features you love on plain,
   non-database objects
ActiveModel

Validations
Serialization (JSON, XML)
Callbacks (before_save)
Translations
ActionController
    Handling requests
Responder

   Exposed to the
developer for the rst
       time
Responder

Allows precise yet
reusable control of
how responses are
    generated
Responder

class EpisodesController < ApplicationController
油油respond_to :html, :xml, :json

油油def index
油油油油@episodes = Episode.all
油油油油respond_with @episodes
油油end
end
CSRF Protection

Cross-Site Request Forgery is
    an attack allowing an
 attacker to impersonate a
            user.
CSRF Protection


1. User clicks link in a friends tweet
   to http://evilsite.us/
CSRF Protection


2. User clicks play on a video on
   http://evilsite.us/
CSRF Protection


3. User ends up tweeting link to
   http://evilsite.us/
CSRF Protection

Note that Twitter isnt
 vulnerable to this.
CSRF Protection

   Note that Twitter isnt
    vulnerable to this.
They use Rails built-in CSRF
        protection.
CSRF Protection

Enabled by default
Transparent
Use the built-in form builders
ActionView
 Producing responses
XSS Protection

Cross Site Scripting is a class
of attack allowing an attacker
 to execute code on a users
        web browser.
XSS Protection


1. User watches video on YouTube
XSS Protection

2. Malicious code in the comments
   cause the user to post malicious
   code in videos theyre previously
   watched.
XSS Protection
Rails 3 has protection for this
   built in and enabled by
            default.
Think hard before using raw
      output in views.
A side note

Curious about CSRF and XSS attacks?
  Hack Miami had presentations about these
  vulnerabilities on Saturday, September 18.
    Hop in your DeLorean to learn more!

     http://hackmiami.org/
Unobtrusive
     JavaScript

   Rails 1 & 2 injected
 JavaScript into pages to
make AJAX features work.
Unobtrusive
     JavaScript

Rails 3 annotates the HTML
  with special properties.
Unobtrusive
      JavaScript

    There are drivers for
Prototype, jQuery, and more.
No more scripts/*


The scripts directory used to
 contain tools for generating
and running your application.
No more scripts/*


Rails 3 does this with the rails tool.
Big Changes
ActiveRecord: Arel, ActiveModel
ActionController: CSRF protection,
ActionController::Responder
ActionView: XSS Protection, Unobtrusive
JavaScript
Railties: No more scripts/*
Authorization
 with OAuth
Authentication

Authentication is
proving who you
      are.
Authentication

Drivers license
Passport
Fingerprint on     le
Authorization

 Authorization is
letting something
 happen on your
      behalf.
Authorization

Signature on a contract
Key in your cars ignition
Verbal permission
Authentication
      and
 Authorization
Two security primitives that
  taste great together!
On the Web
The Old Stupid Way
The Old Stupid Way

 You want TripIt to read your address
  book.
 You dont want TripIt to read all your
  email.
Another Bad Idea
Another Bad Idea

 How do you revoke access?
 How do you revoke access to only one
  client?
 How do you ensure clients only do
  certain things?
OAuth
OAuth
An open protocol to allow
secure API authorization in a
simple and standard method
from desktop and web
applications.
                 - http://oauth.net/
OAuth

OAuth lets you limit
 and control client
applications working
  on your behalf.
OAuth
Facebook     Yahoo
Twitter      Net ix
Github       Picomoney
Google       37signals
An OAuth Session

1.You nd a useful website
that reads your friends
tweets about movies, and
adds them to your Net ix
queue.
An OAuth Session

2.You click the Connect with
Net ix button, and are
redirected to:
https://api-user.net ix.com/
An OAuth Session

3.You enter your Net ix
account information, and are
returned to the client
website.
An OAuth Session

4.You click the Connect with
Twitter button, and are
redirected to:
https://api.twitter.com/
An OAuth Session

5.You enter your Twitter
account information, and are
returned to the client
website.
An OAuth Session

The client application
gets tokens for each
service.
An OAuth Session
If you decide (at any time) to quit using the
service, you can visit Twitter and Net ix and
revoke its authorization.
An OAuth Session
The Guts

1. The consumer (client) asks the
   provider (server) for a new blank
   request token, and sends the user
   to the provider with that request
   token.
The Guts

2. The user authenticates with the
   provider, and accepts (or denies)
   the authorization the consumer
   wants.
The Guts


3. The user is redirected back to the
   consumer with a request token
   bound to that user.
The Guts


4. The consumer gives the request
   token to the server in exchange for
   an access token.
The Guts


5. The consumer can use the access
   token as authorization.
OAuth 2

OAuth 1.0a and 2
are different and
  incompatible.
OAuth 1 or 2?

 If youre making a
    consumer, the
provider made that
   choice for you.
OAuth 1 or 2?


If youre making a
provider, OAuth 2.
Getting Started
I Didnt Finish My Demo
Photo Credits
http://www. ickr.com/photos/lazytom/320269269/
http://www. ickr.com/photos/andrewmbutler/428388719/
http://www. ickr.com/photos/emdurso/2686817699/
http://www. ickr.com/photos/beleaveme/1871344753/
http://www. ickr.com/photos/beleaveme/4676893419/
http://www. ickr.com/photos/scottobear/186001665/
(pretty smug about Tri-Rail photos in a Rails 3 presentation)
Photo Credits

http://www. ickr.com/photos/95453014@N00/451238739/
http://www. ickr.com/photos/mattkieffer/4671197999/
http://www. ickr.com/photos/italintheheart/4018162624/
http://www. ickr.com/photos/spbutterworth/2756176408/
http://www. ickr.com/photos/gesteves/3336482837/
Look at Stuff

http://db.tt/wDfs5nd - slides (keynote & pdf)
http://bit.ly/r3oauth - half- nished source
http://twitter.com/bonzoesc
Questions
Thanks!
What Im Using


 Ruby 1.8.7
 Rails 3
 twitter gem
Follow along!

The hexits at the bottom of
the slide are a git commit
number.
http://bit.ly/r3oauth
Build the Skeleton


> rails new oauthdemo




       fbdb7051
Add Gems

Gem le:
  gem油'oauth'

> bundle install

    96919add
Start the Server


    > rails s
Rails 3 and OAuth for Barcamp Tampa
Add a Users table
> rails g model user 
 screen_name:string 
 twitter_token:string 
 twitter_secret:string


           3473158b
Stub Controller
> rails g controller 
 authorization 
 new 
 show


           767512e2
Stub Controller
con g/routes.rb:
Oauthdemo::Application.routes.draw do
油油resource :authorization

app/controllers/authorization_controller.rb:
class AuthorizationController < ApplicationController
  
油油def create
油油end

油油def destroy
油油end

                         2dd53ba0
OAuth Con guration
con g/initializers/twitter.rb:

TWITTER_OAUTH_TOKENS = {
油油:key=>'DCtwdGNS38Sr9JN',
油油:secret=>'gJ6RN7Nblq9t'
}


                       bb1dd05b
Ad

Recommended

Introduction to rg\injection
Introduction to rg\injection
Bastian Hofmann
How to create OpenSocial Apps in 45 minutes
How to create OpenSocial Apps in 45 minutes
Bastian Hofmann
Intro to developing for @twitterapi
Intro to developing for @twitterapi
Raffi Krikorian
Intro to developing for @twitterapi (updated)
Intro to developing for @twitterapi (updated)
Raffi Krikorian
What's happening here?
What's happening here?
Raffi Krikorian
Beware the potholes
Beware the potholes
Yan Cui
Akka Presentation Schule@synyx
Akka Presentation Schule@synyx
Florian Hopf
Nishimura finding vulnerabilities-in-firefox-for-i-os-(nishimunea)
Nishimura finding vulnerabilities-in-firefox-for-i-os-(nishimunea)
PacSecJP
O auth
O auth
faisalqau
OAuth
OAuth
Aslam Jarwar
MainFinalOAuth
MainFinalOAuth
Mohan Kumar Tadikimalla
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
Jim Jeffers
Spring4 security oauth2
Spring4 security oauth2
Sang Shin
Maintest3
Maintest3
Mohan Kumar Tadikimalla
OAuth and OEmbed
OAuth and OEmbed
leahculver
Maintest2
Maintest2
Mohan Kumar Tadikimalla
Startup Institute NY (Summer 2016) - Authentication, Validation, and Basic Te...
Startup Institute NY (Summer 2016) - Authentication, Validation, and Basic Te...
Matthew Gerrior
Startup Institute NY - Authentication, Validation, and Basic Testing
Startup Institute NY - Authentication, Validation, and Basic Testing
Matthew Gerrior
Top X OAuth 2 Hacks
Top X OAuth 2 Hacks
Antonio Sanso
Spring4 security oauth2
Spring4 security oauth2
axykim00
Ruby on Rails Penetration Testing
Ruby on Rails Penetration Testing
3S Labs
OAuth 2
OAuth 2
ChrisWood262
Maintest 100713212237-phpapp02-100714080303-phpapp02
Maintest 100713212237-phpapp02-100714080303-phpapp02
Mohan Kumar Tadikimalla
OAuth
OAuth
Mohan Kumar Tadikimalla
Maintest 100713212237-phpapp02-100714080303-phpapp02
Maintest 100713212237-phpapp02-100714080303-phpapp02
Mohan Kumar Tadikimalla
OAuth
OAuth
Tom Elrod
OAuth for your API - The Big Picture
OAuth for your API - The Big Picture
Apigee | Google Cloud
Oauth Behind The Scenes
Oauth Behind The Scenes
Thang Tran Duc
Mastering AI Workflows with FME by Mark Doring
Mastering AI Workflows with FME by Mark Doring
Safe Software
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu

More Related Content

Similar to Rails 3 and OAuth for Barcamp Tampa (20)

O auth
O auth
faisalqau
OAuth
OAuth
Aslam Jarwar
MainFinalOAuth
MainFinalOAuth
Mohan Kumar Tadikimalla
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
Jim Jeffers
Spring4 security oauth2
Spring4 security oauth2
Sang Shin
Maintest3
Maintest3
Mohan Kumar Tadikimalla
OAuth and OEmbed
OAuth and OEmbed
leahculver
Maintest2
Maintest2
Mohan Kumar Tadikimalla
Startup Institute NY (Summer 2016) - Authentication, Validation, and Basic Te...
Startup Institute NY (Summer 2016) - Authentication, Validation, and Basic Te...
Matthew Gerrior
Startup Institute NY - Authentication, Validation, and Basic Testing
Startup Institute NY - Authentication, Validation, and Basic Testing
Matthew Gerrior
Top X OAuth 2 Hacks
Top X OAuth 2 Hacks
Antonio Sanso
Spring4 security oauth2
Spring4 security oauth2
axykim00
Ruby on Rails Penetration Testing
Ruby on Rails Penetration Testing
3S Labs
OAuth 2
OAuth 2
ChrisWood262
Maintest 100713212237-phpapp02-100714080303-phpapp02
Maintest 100713212237-phpapp02-100714080303-phpapp02
Mohan Kumar Tadikimalla
OAuth
OAuth
Mohan Kumar Tadikimalla
Maintest 100713212237-phpapp02-100714080303-phpapp02
Maintest 100713212237-phpapp02-100714080303-phpapp02
Mohan Kumar Tadikimalla
OAuth
OAuth
Tom Elrod
OAuth for your API - The Big Picture
OAuth for your API - The Big Picture
Apigee | Google Cloud
Oauth Behind The Scenes
Oauth Behind The Scenes
Thang Tran Duc
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
Jim Jeffers
Spring4 security oauth2
Spring4 security oauth2
Sang Shin
OAuth and OEmbed
OAuth and OEmbed
leahculver
Startup Institute NY (Summer 2016) - Authentication, Validation, and Basic Te...
Startup Institute NY (Summer 2016) - Authentication, Validation, and Basic Te...
Matthew Gerrior
Startup Institute NY - Authentication, Validation, and Basic Testing
Startup Institute NY - Authentication, Validation, and Basic Testing
Matthew Gerrior
Top X OAuth 2 Hacks
Top X OAuth 2 Hacks
Antonio Sanso
Spring4 security oauth2
Spring4 security oauth2
axykim00
Ruby on Rails Penetration Testing
Ruby on Rails Penetration Testing
3S Labs
Maintest 100713212237-phpapp02-100714080303-phpapp02
Maintest 100713212237-phpapp02-100714080303-phpapp02
Mohan Kumar Tadikimalla
Maintest 100713212237-phpapp02-100714080303-phpapp02
Maintest 100713212237-phpapp02-100714080303-phpapp02
Mohan Kumar Tadikimalla
OAuth for your API - The Big Picture
OAuth for your API - The Big Picture
Apigee | Google Cloud
Oauth Behind The Scenes
Oauth Behind The Scenes
Thang Tran Duc

Recently uploaded (20)

Mastering AI Workflows with FME by Mark Doring
Mastering AI Workflows with FME by Mark Doring
Safe Software
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
Mastering AI Workflows with FME by Mark Doring
Mastering AI Workflows with FME by Mark Doring
Safe Software
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
Ad

Rails 3 and OAuth for Barcamp Tampa

Editor's Notes

  • #13: Merb started as a smaller, simpler Rails. Merb didn&amp;#x2019;t force you to use some of the libraries that Rails 1 &amp; 2 did. In December 2008, the Rails and Merb teams announced they were merging and collaborating on Rails 3.
  • #16: ActiveRecord: Arel, ActiveModel ActionController: CSRF protection, ActionController::Responder ActionView: XSS Protection, Unobtrusive JavaScript Railties: No more scripts/*
  • #25: Easily add XML or JSON support to a resource. Add pagination support for HTML views.
  • #27: For example, visiting http://malicious.site/ could post a message as you on Twitter.
  • #33: Unless you go through the work to disable this, you won&amp;#x2019;t have to worry
  • #40: On a page with 100 AJAX buttons, this could double the size of the page load.
  • #41: The client downloads a driver once per site, instead of on every page load.
  • #43: The most &amp;#x201C;gotcha&amp;#x201D; of the rails changes. When upgrading Rails, these scripts would have to be added to or replaced.
  • #44: When new versions are released, you won&amp;#x2019;t have to update any scripts.