TODO: Write a gem description
Add this line to your application's Gemfile:
gem 'omniauth-youyu'
And then execute:
$ bundle
Or install it yourself as:
$ gem install omniauth-youyu
for devise:
-
Apply your app id&secret key from youyu.im
-
Update initializers/devise.rb
require 'omniauth-youyu' config.omniauth :youyu, ENV['YOUYU_AUTH_ID'], ENV['YOUYU_AUTH_SECRET'], :strategy_class => OmniAuth::Strategies::Youyu, :client_options => {:site => ENV['YOUYU_AUTH_URL']}
-
create your own OmniauthCallbackController, then update routes file.
eg:
class Cimu::OmniauthCallbacksController < Devise::OmniauthCallbacksController def youyu oauth_data = request.env["omniauth.auth"] @account = Account.find_or_create_for_youyu_oauth(oauth_data) @account.update_youyu_credentials(oauth_data) sign_in_and_redirect @account end def passthru render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false end end devise_for :accounts, :controllers => {:omniauth_callbacks => "Cimu::OmniauthCallbacks"}
-
add youyu_access_token to your account model, and update youyu_access_token after auth
def self.find_or_create_for_youyu_oauth(oauth_data) Account.find_or_initialize_by_youyu_email(oauth_data.info.email).tap do |account| account.email = oauth_data.info.email end end def self.find_or_initialize_by_youyu_email(email) account = Account.where(:email => email).first account ||= Account.new end def update_youyu_credentials(oauth_data) self.youyu_access_token = oauth_data.credentials.token end
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request