Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
371
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
4
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Omniauth GemAll, Every and Authentication Everywhere Omni + auth By Sumit Munot
  • 2. How to Use Omniauth to Authenticate Our Users?We Needs to Sign Up For Various Applications andSites Separately.Why?We have already sign up on many, using differentusernames, that going back to one of them andtrying to remember our credentials is sometimesimpossible.
  • 3. Now a days, most of the sites offering alternativeway to sign up,By allowing us to use other sites accounts.Like• Google Account• Twitter• GitHub• FacebookIt feels like a long and arduous task.But fear not, Omniauth is here to help.
  • 4. Omniauth allows us to easilyintegrate more than sixty authentication providers!
  • 5. Preparing ApplicationCreate Rails applicationrails new application_nameIn GEMFILE addgem omniauthThen,Bundle install
  • 6. Creating a ProviderHow add a provider to Omniauth?We need to sign up as a developer onproviders site.Then just we will have to make two settings inour application regardingUsername and Password.
  • 7. If you want to use Facebook authenticationhead over to Create newdevelopers.facebook.com/apps app hereandclick on “Create New App”
  • 8. Getting our App id/ API key and App Secret from settings
  • 9. Add Provider To The App Create a new file under config/initializers called omniauth.rb.Rails.application.config.middleware.use OmniAuth::Builder doprovider :facebook, YOUR_APP_ID, YOUR_APP_SECRETend Create the Controller Session $> rails generate controller sessions new create failure
  • 10. Set path in routes.rbget /login, :to => sessions#new, :as => :loginmatch /auth/:provider/callback, :to => sessions#creatematch /auth/failure, :to => sessions#failureIn Controller app/controllers/sessions_controller.rb just adddef Createauth_hash = request.env[omniauth.auth]render :text => auth_hash.inspectend
  • 11. Now make sure everything is working.Point the browser tolocalhost:3000/auth/facebook/Then,we’ll be redirected to Facebook so we can authorize our app.We will Authorize it, and we will be redirected back to our appand see a hash with some information.In between will be our name, our Facebook user id, and our email, among other things.If error occurred then,
  • 12. Change Some Setting in Facebook/apps for siteredirection Blank App Domains Change site URL
  • 13. Thanks