Code Monkey home page Code Monkey logo

Comments (8)

talbright avatar talbright commented on July 20, 2024

Internally we use oauth2, but I wanted the open source version to use database authentication out of the box. At the same time I wanted to provide a way for users to use oauth2 if they wanted, so that's why I included the omniauth controller.

But you are not missing something, I am. This is dead code specific to LivingSocial that should be removed.

Thanks for pointing it out.

from rearview.

arikfr avatar arikfr commented on July 20, 2024

I'm assuming the missing piece of code was checking that the email belongs to one of your domains; in this case, it makes sense to leave it. We use the same pattern, and I believe other companies do the same.

Also, why oauth2 and not openid?

from rearview.

talbright avatar talbright commented on July 20, 2024

Sounds like you are using oauth2?

The implementation in our extension of Rearview::User is something like this:

  def self.valid_email?(email)
    email.present? && (email.ends_with?('hungrymachine.com')|| email.ends_with?('livingsocial.com'))
  end

This would not be generic/usable for the general public. Is this another candidate for a configuration option (maybe an email matching regex) or did you have something else in mind?

config.oauth2_valid_emails = /(hungrymachine|livingsocial)\.com$/

def self.valid_email?(email)
  email.present? && email.match(Rearview.config.oauth2_valid_emails)
end

from rearview.

arikfr avatar arikfr commented on July 20, 2024

Once you move the valid domains list to a configuration, it becomes reusable. For example:

# Rearview.config.valid_domains = ['hungrymachine.com', 'livingsocial.com']

def self.valid_email?(email)
  email.present? && Rearview.config.valid_domains.map { |domain| email.ends_with?(domain) }.any?
end

I had some issues with the oauth configuration (and omniauth in general), and ended up using this method: https://github.com/plataformatec/devise/wiki/OmniAuth%3A-Overview#google-apps although for you it won't be good, as it seems limited to a single domain.

from rearview.

talbright avatar talbright commented on July 20, 2024

What problems did you run into?

from rearview.

arikfr avatar arikfr commented on July 20, 2024

I think my main issue was that I had to add the following line to the User model:

devise :omniauthable, :omniauth_providers => [:google_apps]

Until I figured this out, I've did several changes; including rewriting Devise's initiailzier and moving from oauth2 to the gem mentioned above. If you want, I can try to reset git history and retry making oauth2 working.

from rearview.

talbright avatar talbright commented on July 20, 2024

This is an area that needs some polishing with either some documentation, configuration, and improving the view so it knows which type of sign-in to use.

You should be able to get oauth2 to work fine with those changes. For our engine host the user model devise call looks like this:

  devise :omniauthable,:database_authenticatable,:omniauth_providers => [:google_oauth2]

Keep in mind that this alone will not get oauth2 working. You need to also setup things correctly on the google side, and edit devise.rb:

config.omniauth :google_oauth2,
              'xxxx', #app ID
              'xxxx', #client ID
              :scope => 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile',
              :access_type => 'offline',
              :approval_prompt => ''

To answer your previous question RE: openid vs oauth2. Most of our internal apps now use oauth2 so rearview follows that standard. Also though, some of the other apps I work with use features like Google Drive, and oauth2 works much better when integrating with google apps. So in the end its easier to deal with if all our apps use the same auth approach.

from rearview.

arikfr avatar arikfr commented on July 20, 2024

👍 makes sense.

I think that it's better to start with documentation and switch to configuration if it seems that most users will need it.

from rearview.

Related Issues (20)

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.