EzDevInfo.com

authlogic

A simple ruby authentication solution. Documentation for binarylogic/authlogic (master)

Authlogic's current_user object in models

I need to know the ID of the current user in a model:

def after_save
  desc, points=nil, nil

  if answer_index == daily_question.correct_answer_index 
    desc = I18n.t('daily_question.point_log.description.correct') 
    points=daily_question.points
  else
    desc = I18n.t('daily_question.point_log.description.incorrect')
  end

  current_user.give_points(:description => desc,
                           :points => points
                          )
end

But I guess that is not how it is done?

Regards,

Jacob


Source: (StackOverflow)

Authlogic Facebook Connect Snafu

I have an application configured with authlogic and authlogic_facebook_connect, but every time I click to "Connect" button, my UserSession fails validation, saying "You did not provide any details for authentication"

Isn't the authlogic_facebook_connect supposed to bypass login/password authentication? Am I missing some configuration step?

Any help would be appreciated!


Source: (StackOverflow)

Advertisements

Using Facebook Connect with Authlogic

I am trying to make Authlogic and Facebook Connect (using Facebook) play nice so that you can create an account either the normal registration way or with Facebook connect. I have been able to get the connect to work one way but logging out only loggs out on facebook and not on my site, I have to delete the cookies to make it working. Any help would be awesome, thank you!


Source: (StackOverflow)

Ruby-OpenID: Requiring email-address from OpenID provider

I'm playing with the authlogic-example-app and I'm failing to get the email address from the OpenID provider (in my case: Google and Yahoo) when I register a user, resp. I get an empty response instead of an email address (check the comments in code below).

This is how my user model looks like (everything else looks like the "with_openid"-branch of the authlogic-example-app mentioned above). Besides the missing 'email', the openid-authentication-process works as expected:

class User < ActiveRecord::Base
  acts_as_authentic do |c| 
    # not needed because I use OpenID
    c.validate_login_field = false
    # avoid failed validation before OpenID request
    c.validate_email_field = false
    # this one sets 'openid.sreg.required=email'
    c.required_fields = [:email]
  end

  private

  # overwriting the existing method in '/lib/authlogic_openid/acts_as_authentic.rb'
  def map_openid_registration(registration)
    # this is my problem: 'registration' is an empty hash
    self.email ||= registration[:email] if respond_to?(:email) && !registration[:email].blank?
  end

end

Any idea how to solve this? Has anyone here done this before using authlogic? Or even better: Do you have a working example?

Update: I checked the Google Account Authentication API and compared the request submitted by authlogic (using ruby-openid-gem and openid-authentication-plugin) with the example requests on the Google Account Authentication API docs:


Example request to authenticate and fetch email address by Google:

https://www.google.com/accounts/o8/ud
?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0
&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
&openid.return_to=http%3A%2F%2Fwww.example.com%2Fcheckauth
&openid.realm=http%3A%2F%2Fwww.example.com%2F
&openid.assoc_handle=ABSmpf6DNMw
&openid.mode=checkid_setup
&openid.ns.ext1=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0
&openid.ext1.mode=fetch_request
&openid.ext1.type.email=http%3A%2F%2Faxschema.org%2Fcontact%2Femail
&openid.ext1.required=email


Request submitted by my appliation:

https://www.google.com/accounts/o8/ud
?openid.assoc_handle=AOQobUcdICerEyK6SXJfukaz8ygXiBqF_gKXv68OBtPXmeafBSdZ6576
&openid.ax.mode=fetch_request
&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
&openid.mode=checkid_setup
&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0
&openid.ns.ax=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0
&openid.ns.sreg=http%3A%2F%2Fopenid.net%2Fextensions%2Fsreg%2F1.1
&openid.realm=http%3A%2F%2Flocalhost%3A3000%2F
&openid.return_to=http%3A%2F%2Flocalhost%3A3000%2Faccount%3Ffor_model%3D1%26_method%3Dpost%26open_id_complete%3D1
&openid.sreg.required=email

While debugging the whole setup, I've found out that the openid-authentication-plugin never receives an email in the response it receives from the openid provider, this at least explains why the registration hash in my user-model is empty...

UPDATE: If you're playing around with authlogic and openid, don't forget to check out the latest railscast on this subject!


Source: (StackOverflow)

Application Controller helper methods not available for Views Specs

I have a helper method called current_user in my Application Controller (used with Authlogic).

Spec for views using that helper fail (but the view is working when i use the browser)

ActionView::Template::Error: undefined local variable or method 'current_user' for #<#<Class:0x0000000229b060>:0x00000002004248>

I use rspec 2.6.0.

Anyone had the same problem? Please advice. Thanks


Source: (StackOverflow)

RESTful-Authentication or Authlogic?

I'm having trouble deciding between the two. They both seem like great plugins but I'd like to know which is easier to control.

What are your guy's experiences with these plugins? Which would you recommend?


Source: (StackOverflow)

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

I am using Authlogic-Connect for third party logins. After running appropriate migrations, Twitter/Google/yahoo logins seem to work fine but the facebook login throws exception:

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

The dev log shows

OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed):
  app/controllers/users_controller.rb:37:in `update'

Please suggest..


Source: (StackOverflow)

Rails 3 Authentication: Authlogic vs Devise

I have always used Authlogic in Rails 2.3 but now that I am using Rails 3 I think I might try out a new authentication solution.

How does Devise compare with Authlogic? What are their differences?


Source: (StackOverflow)

Migrating from Authlogic to Devise

I've previously implemented Authlogic for authorization on my site. Now however I wish to switch over to using Devise instead, and I'm wondering if anyone has any experience with this. Perhaps anyone's seen a blog post on the subject?

Thank you.


Source: (StackOverflow)

Rails 3 authentication with OpenID, Twitter or Facebook

Can you suggest some working example of it? I tried Authlogic and Devise withous success.


Source: (StackOverflow)

Using custom authlogic error messages

I am using the authlogic gem for user validation on one of my sites. All is going well, but I am wondering if it's possible to change the error message that gets returned when the user types in an invalid email address.

Thanks!


Source: (StackOverflow)

authlogic email as username

How do i override/set authlogic to use the email field instead of the username field for both signup and authentication, having a username + an email is occasionally too intense for some some registration scenarios


Source: (StackOverflow)

Authlogic openid with multiple openid identifiers per account

How would you go about allowing a user to log in with multiple openid accounts and optionally a password, using authlogic?


Source: (StackOverflow)

The Authlogic record method. What does this do

I came across this method called record that Ryan bates uses in his authlogic Railscast and can't seem to understand what it does. I have been through the documentation but I can't seem to follow how that helper is useful.

def current_user
  return @current_user if defined?(@current_user)

  current_user_session && current_user_session.record
end

What I want to know is does this simply fetch the record from the database and why is it different from the standard way of fetching data from the database.

Thank you.


Source: (StackOverflow)

Authlogic accessing user id in session object

I was wondering if anyone knows how I can access the user ID from the session object in Rails using the Authlogic gem ?

I have a sweeper that runs to expire a cache fragment specific to a user:

 def expire_cache_for(record)
    ActiveRecord::Base.logger.debug "team: #{record.team_id}"
    ActiveRecord::Base.logger.debug("User: #{session}")

    # Expire a fragment
    expire_fragment(:controller => 'groups',  :action => "team_#{record.team_id}_user_#{current_user.id}")
  end

How can I access the user ID from my sweeper to expire the fragment using Authlogic ?


Source: (StackOverflow)