Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
logankoester-authlogic-oauth
Advanced tools
= Authlogic OAuth
Authlogic OAuth is an extension of the Authlogic library to add OAuth support. One use case for authentication with OAuth is allowing users to log in with their Twitter credentials.
== Helpful links
== Install and use
=== 1. Install Authlogic and setup your application
=== 2. Install OAuth and Authlogic_Oauth
$ sudo gem install oauth $ sudo gem install authlogic-oauth
Now add the gem dependencies in your config:
config.gem "oauth" config.gem "authlogic-oauth", :lib => "authlogic_oauth"
Or for older version of rails, install it as a plugin:
$ script/plugin install git://github.com/jrallison/authlogic_oauth.git
=== 3. Make some simple changes to your database:
class AddUsersOauthFields < ActiveRecord::Migration def self.up add_column :users, :oauth_token, :string add_column :users, :oauth_secret, :string add_index :users, :oauth_token
change_column :users, :login, :string, :default => nil, :null => true
change_column :users, :crypted_password, :string, :default => nil, :null => true
change_column :users, :password_salt, :string, :default => nil, :null => true
end
def self.down
remove_column :users, :oauth_token
remove_column :users, :oauth_secret
[:login, :crypted_password, :password_salt].each do |field|
User.all(:conditions => "#{field} is NULL").each { |user| user.update_attribute(field, "") if user.send(field).nil? }
change_column :users, field, :string, :default => "", :null => false
end
end
end
=== 4. Make sure you save your objects properly
You only need to save your objects this way if you want the user to authenticate with their OAuth provider.
That being said, you probably want to do this in your controllers. You should do this for BOTH your User objects and UserSession objects (assuming you are authenticating users). It should look something like this:
@user_session.save do |result| if result flash[:notice] = "Login successful!" redirect_back_or_default account_url else render :action => :new end end
You should save your @user objects this way as well, because you also want the user to authenticate with OAuth.
Notice we are saving with a block. Why? Because we need to redirect the user to their OAuth provider so that they can authenticate. When we do this, we don't want to execute that block of code, because if we do, we will get a DoubleRender error. This lets us skip that entire block and send the user along their way without any problems.
=== 5. Define the oauth_consumer class method on your UserSession model
The oauth_consumer should return an OAuth::Consumer which is configured for your OAuth provider. Here's an example for Twitter:
class UserSession < Authlogic::Session::Base
def self.oauth_consumer
OAuth::Consumer.new("TOKEN", "SECRET",
{ :site=>"http://twitter.com",
:authorize_url => "http://twitter.com/oauth/authorize?force_login=true" })
end
end
=== 6. Add login and register buttons to your views
<%= oauth_register_button :value => "Register with Twitter" %> <%= oauth_login_button :value => "Login with Twitter" %>
That's it! The rest is taken care of for you.
= Here are some next steps for the plugin.
FAQs
Unknown package
We found that logankoester-authlogic-oauth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.