Giter Site home page Giter Site logo

crowdint_auth's Introduction

CrowdintAuth

Build Status

Adds the required configuration to use Devise with our Crowd Interactive Google Apps account for authentication.

Installation

Gemfile

gem 'crowdint_auth'

Run

bundle install

Usage

Migration

Devise model needs the following extra fields:

class AddColumnsToUsers < ActiveRecord::Migration
  def change
    add_column :users, :provider, :string
    add_column :users, :uid, :string
  end
end

Devise

The devise model should include the :omniauthable option, for example:

devise :database_authenticatable, :token_authenticatable, :trackable, :omniauthable

Routes

If your user class is User

Set up the devise routes:

devise_scope :user do
  get 'google_apps_sign_in', :to => "crowdint_auth/omniauth_callbacks#google_apps_sign_in"
end

devise_for :users, controllers: { omniauth_callbacks: 'crowdint_auth/omniauth_callbacks' }

The first match will determine the url for the login. That is, your sign in link will probably look something like:

= link_to 'Sign In', google_apps_sign_in_path

If your user class is named differently

Create your own omniauth callbacks controller that inherits from CrowdintAuth::OmniauthCallbacksController:

class Users::OmniauthCallbacksController < CrowdintAuth::OmniauthCallbacksController
  def user_class
    OtherClass
  end
end

And set it up on routes:

devise_scope :user do
  get 'google_apps_sign_in', :to => "users/omniauth_callbacks#google_apps_sign_in"
end

devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }

About the Author

Crowd Interactive is a leading Ruby and Rails consultancy firm based in Mexico currently doing business with startups in the United States. We specialize in building and growing your existing development team, by adding engineers onsite or offsite. We pick our clients carefully, as we only work with companies we believe in. Find out more about us on our website.

crowdint_auth's People

Watchers

 avatar  avatar  avatar

crowdint_auth's Issues

Error when redirecting back from Google authorization

This is the workflow:

  1. Click on login button
  2. Authenticate to your crowdint's Google account
  3. When redirecting to deployator-config.herokuapp.com, an error appears.

If you decide to not authorize the app, you also have an error when redirecting. Also, if you already authorized the app and access the site, you will get an error.

All these errors are NotMethodError exceptions. Seems like Rails is trying to call some methods on a string instead of an object. Someway, a string got in a place where an OpenID::Consumer::DiscoveredServices object should be. I was unable to find the source of the bug by myself.

This is an actual dump of one of those errors:

NoMethodError
undefined method `uses_extension' for #<String:0x0000000640cb20>
Rails.root: /home/kevinkdpm/Proyectos/deployator-config

Full trace
ruby-openid (2.3.0) lib/openid/consumer/idres.rb:464:in `block in verify_discovery_single'
ruby-openid (2.3.0) lib/openid/consumer/idres.rb:463:in `each'
ruby-openid (2.3.0) lib/openid/consumer/idres.rb:463:in `verify_discovery_single'
ruby-openid (2.3.0) lib/openid/consumer/idres.rb:352:in `verify_discovery_results_openid2'
ruby-openid (2.3.0) lib/openid/consumer/idres.rb:315:in `verify_discovery_results'
ruby-openid (2.3.0) lib/openid/consumer/idres.rb:75:in `id_res'
ruby-openid (2.3.0) lib/openid/consumer/idres.rb:59:in `initialize'
ruby-openid (2.3.0) lib/openid/consumer.rb:346:in `new'
ruby-openid (2.3.0) lib/openid/consumer.rb:346:in `handle_idres'
ruby-openid (2.3.0) lib/openid/consumer.rb:386:in `complete_id_res'
ruby-openid (2.3.0) lib/openid/consumer.rb:289:in `call'
ruby-openid (2.3.0) lib/openid/consumer.rb:289:in `complete'
rack-openid (1.3.1) lib/rack/openid.rb:145:in `block in complete_authentication'
rack-openid (1.3.1) lib/rack/openid.rb:272:in `timeout_protection_from_identity_server'
rack-openid (1.3.1) lib/rack/openid.rb:143:in `complete_authentication'
rack-openid (1.3.1) lib/rack/openid.rb:95:in `call'
omniauth-openid (1.0.1) lib/omniauth/strategies/open_id.rb:87:in `openid_response'
omniauth-openid (1.0.1) lib/omniauth/strategies/open_id.rb:80:in `callback_phase'
omniauth (1.2.2) lib/omniauth/strategy.rb:227:in `callback_call'
omniauth (1.2.2) lib/omniauth/strategy.rb:184:in `call!'
omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/flash.rb:254:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.1.4) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.1.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
activerecord (4.1.4) lib/active_record/migration.rb:380:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.4) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.4) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.4) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.4) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.4) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.4) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.1.4) lib/rails/engine.rb:514:in `call'
railties (4.1.4) lib/rails/application.rb:144:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/home/kevinkdpm/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/home/kevinkdpm/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/home/kevinkdpm/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'

Request
Parameters:

{"_method"=>"post",
 "openid.ns"=>"http://specs.openid.net/auth/2.0",
 "openid.mode"=>"id_res",
 "openid.op_endpoint"=>"https://www.google.com/a/crowdint.com/o8/ud?be=o8",
 "openid.response_nonce"=>"2014-08-04T22:35:23Z2r1gwwn-8SHnng",
 "openid.return_to"=>"http://localhost:3000/users/auth/google_apps/callback?_method=post",
     "openid.assoc_handle"=>"1.AMlYA9VL4c2D9RiV6iZeWMOsAjiPeko8LyeIpt1NabVGLdOcTVa2MTky5df    ZFIPe",
 "openid.signed"=>"op_endpoint,
claimed_id,
identity,
return_to,
response_nonce,
assoc_handle,
ns.ext1,
ext1.mode,
ext1.type.ext2,
ext1.value.ext2,
ext1.type.ext3,
ext1.value.ext3,
ext1.type.ext0,
ext1.value.ext0",
 "openid.sig"=>"JivAu9eyONBCDhJGOrp/RCjf1ug=",
 "openid.identity"=>"http://crowdint.com/openid?id=107088197722891817129",
 "openid.claimed_id"=>"http://crowdint.com/openid?id=107088197722891817129",
 "openid.ns.ext1"=>"http://openid.net/srv/ax/1.0",
 "openid.ext1.mode"=>"fetch_response",
 "openid.ext1.type.ext2"=>"http://axschema.org/namePerson/first",
 "openid.ext1.value.ext2"=>"Kevin",
 "openid.ext1.type.ext3"=>"http://axschema.org/namePerson/last",
 "openid.ext1.value.ext3"=>"Pérez",
 "openid.ext1.type.ext0"=>"http://axschema.org/contact/email",
 "openid.ext1.value.ext0"=>"[email protected]"}

Session dump

OpenID::Consumer::DiscoveredServices::OpenID::Consumer::: "#<OpenID::Consumer::DiscoveredServices:0x0000000666e4b8>"
OpenID::Consumer::last_requested_endpoint: "<OpenID::OpenIDServiceEndpoint     server_url=https://www.google.com/a/crowdint.com/o8/ud?be=o8 claimed_id= local_id= canonical_id=     used_yadis=true>"
_csrf_token: "JbVhhPM8CEzNLJI3KkstGGU5XtAOETjWwpjMeMt+3Ac="
session_id: "e3c07e28ff851450ee089f77a65ebf70"

Env dump

GATEWAY_INTERFACE: "CGI/1.1"
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
HTTP_ACCEPT_ENCODING: "gzip,deflate,sdch"
HTTP_ACCEPT_LANGUAGE: "es-419,es;q=0.8,en-US;q=0.6,en;q=0.4"
REMOTE_ADDR: "127.0.0.1"
REMOTE_HOST: "127.0.0.1"
SERVER_NAME: "localhost"
SERVER_PROTOCOL: "HTTP/1.1"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.