Permalink
Browse files

Use omniauth-yammer gem

  • Loading branch information...
1 parent 9f37039 commit 96dab62aa8acd6ad32ca3f70ad75e1c4c15de33d @masonforest masonforest committed Oct 1, 2012
View
@@ -25,7 +25,7 @@ gem 'hirefireapp'
gem 'jquery-rails'
gem 'newrelic_rpm'
gem 'omniauth', '~> 1.0'
-gem 'omniauth-oauth2', '~> 1.0.2'
+gem 'omniauth-yammer'
gem 'paperclip', '~> 3.0.4'
gem 'pg'
gem 'rest-client'
View
@@ -127,7 +127,7 @@ GEM
httparty (0.8.3)
multi_json (~> 1.0)
multi_xml
- httpauth (0.1)
+ httpauth (0.2.0)
i18n (0.6.0)
journey (1.0.4)
jquery-rails (2.1.1)
@@ -167,9 +167,11 @@ GEM
omniauth (1.1.1)
hashie (~> 1.2)
rack
- omniauth-oauth2 (1.0.3)
+ omniauth-oauth2 (1.1.1)
oauth2 (~> 0.8.0)
omniauth (~> 1.0)
+ omniauth-yammer (0.0.3)
+ omniauth-oauth2 (>= 1.1)
paperclip (3.0.4)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
@@ -321,7 +323,7 @@ DEPENDENCIES
mail_view
newrelic_rpm
omniauth (~> 1.0)
- omniauth-oauth2 (~> 1.0.2)
+ omniauth-yammer
paperclip (~> 3.0.4)
pg
pry
@@ -38,7 +38,7 @@ def auth
def find_or_create_with_auth
User.find_or_create_with_auth(
- access_token: auth[:info][:access_token],
+ access_token: auth[:credentials][:token],
yammer_staging: auth[:provider] == "yammer_staging",
yammer_user_id: auth[:uid]
)
@@ -1,4 +1,3 @@
-require Rails.root.join('lib', 'yammer-strategy')
require Rails.root.join('lib', 'yammer-staging-strategy')
OmniAuth.config.on_failure = SessionsController.action(:oauth_failure)
OmniAuth.config.logger = Rails.logger
@@ -2,52 +2,14 @@
module OmniAuth
module Strategies
- class YammerStaging < OmniAuth::Strategies::OAuth2
- # Give your strategy a name.
+ class YammerStaging < OmniAuth::Strategies::Yammer
option :name, 'yammer_staging'
option :client_options, {
site: 'https://www.staging.yammer.com',
authorize_url: '/dialog/oauth',
token_url: '/oauth2/access_token.json'
}
-
- # Available as request.env['omniauth.auth']['uid']
- uid { raw_info['id'] }
-
- info do
- {
- access_token: access_token.token,
- email: primary_email,
- image: raw_info['mugshot_url'],
- name: raw_info['full_name'],
- nickname: raw_info['name'],
- yammer_network_id: raw_info['network_id'],
- yammer_profile_url: raw_info['web_url']
- }
- end
-
- extra do
- {
- 'raw_info' => raw_info
- }
- end
-
- def build_access_token
- access_token = super
- token = YammerAccessToken.new(access_token.token).real_token
- @access_token = ::OAuth2::AccessToken.new(client, token, access_token.params)
- end
-
- private
-
- def raw_info
- @raw_info ||= access_token.params['user']
- end
-
- def primary_email
- raw_info['contact']['email_addresses'].detect{|address| address['type'] == 'primary'}['address']
- end
end
end
end
View
@@ -1,53 +0,0 @@
-require 'omniauth-oauth2'
-
-module OmniAuth
- module Strategies
- class Yammer < OmniAuth::Strategies::OAuth2
- # Give your strategy a name.
- option :name, 'yammer'
-
- option :client_options, {
- site: 'https://www.yammer.com',
- authorize_url: '/dialog/oauth',
- token_url: '/oauth2/access_token.json'
- }
-
- # Available as request.env['omniauth.auth']['uid']
- uid { raw_info['id'] }
-
- info do
- {
- access_token: access_token.token,
- email: primary_email,
- image: raw_info['mugshot_url'],
- name: raw_info['full_name'],
- nickname: raw_info['name'],
- yammer_network_id: raw_info['network_id'],
- yammer_profile_url: raw_info['web_url']
- }
- end
-
- extra do
- {
- 'raw_info' => raw_info
- }
- end
-
- def build_access_token
- access_token = super
- token = YammerAccessToken.new(access_token.token).real_token
- @access_token = ::OAuth2::AccessToken.new(client, token, access_token.params)
- end
-
- private
-
- def raw_info
- @raw_info ||= access_token.params['user']
- end
-
- def primary_email
- raw_info['contact']['email_addresses'].detect{|address| address['type'] == 'primary'}['address']
- end
- end
- end
-end
@@ -1,12 +0,0 @@
-require 'spec_helper'
-
-describe YammerAccessToken, '#parse_out_token' do
- let(:real_token) { 'abc123' }
- let(:token_string) do
- %Q({"created_at"=>"2012/05/22 12:50:00 +0000", "network_name"=>"Yammer", "view_groups"=>true, "view_messages"=>true, "expires_at"=>nil, "token"=>"#{real_token}", "user_id"=>5556661234, "view_tags"=>true, "view_subscriptions"=>true, "network_permalink"=>"yammer.com", "modify_subscriptions"=>true, "authorized_at"=>"2012/05/22 12:50:00 +0000", "view_members"=>true, "modify_messages"=>true, "network_id"=>12345})
- end
-
- it 'returns the correct token' do
- YammerAccessToken.new(token_string).real_token.should == real_token
- end
-end
@@ -1,78 +0,0 @@
-require 'spec_helper'
-
-describe OmniAuth::Strategies::Yammer do
- include Rack::Test::Methods
-
- subject { OmniAuth::Strategies::Yammer.new(app) }
-
- it 'is named "yammer"' do
- subject.name.should == 'yammer'
- end
-
- it 'has correct URLs' do
- subject.options.client_options.site.should == 'https://www.yammer.com'
- subject.client.options[:authorize_url].should == '/dialog/oauth'
- subject.client.options[:token_url].should == '/oauth2/access_token.json'
- end
-
- it 'sets the correct info' do
- subject.stubs(raw_info: yammer_raw_info)
- subject.stubs(access_token: stub(token: 'abc123'))
-
- subject.info[:access_token].should == 'abc123'
- subject.info[:email].should == 'henry@example.com'
- subject.info[:image].should == 'https://www.yammer.com/mugshot/48x48/12345678'
- subject.info[:name].should == 'Henry Smith'
- subject.info[:nickname].should == 'henry'
- subject.info[:yammer_profile_url].should == 'https://www.yammer.com/example.com/users/henry'
- subject.extra.should_not be_nil
- end
-
- def app
- Rack::Builder.new do |builder|
- builder.use Rack::Session::Cookie
- builder.use OmniAuth::Strategies::Yammer
- builder.run lambda { |env| [200, {}, ['Not Found']] }
- end.to_app
- end
-
- def yammer_raw_info
- {"interests"=>"",
- "location"=>"",
- "significant_other"=>"",
- "birth_date"=>"",
- "external_urls"=>[],
- "network_domains"=>["example.com"],
- "kids_names"=>"",
- "url"=>"https://www.yammer.com/api/v1/users/1112223333",
- "guid"=>nil,
- "schools"=>[],
- "contact"=>{"im"=>{"provider"=>"aim", "username"=>""},
- "email_addresses"=>[{"address"=>"henry@example.com",
- "type"=>"primary"}],
- "phone_numbers"=>[{"type"=>"work", "number"=>"5551234567"}]},
- "id"=>1112223333,
- "full_name"=>"Henry Smith",
- "expertise"=>"",
- "previous_companies"=>[],
- "timezone"=>"Eastern Time (US & Canada)",
- "type"=>"user",
- "can_broadcast"=>"false",
- "stats"=>{"followers"=>5, "updates"=>13, "following"=>11},
- "department"=>nil,
- "job_title"=>"Developer",
- "verified_admin"=>"false",
- "network_id"=>63286,
- "admin"=>"false",
- "state"=>"active",
- "hire_date"=>nil,
- "mugshot_url_template"=>"https://www.yammer.com/mugshot/{width}x{height}/12345678",
- "settings"=>{"xdr_proxy"=>"https://xdrproxy.yammer.com"},
- "activated_at"=>"2012/05/21 13:30:44 +0000",
- "mugshot_url"=>"https://www.yammer.com/mugshot/48x48/12345678",
- "web_url"=>"https://www.yammer.com/example.com/users/henry",
- "name"=>"henry",
- "summary"=>"",
- "network_name"=>"Example"}
- end
-end
@@ -30,15 +30,17 @@ def mock_yammer_oauth(email=nil)
OmniAuth.config.mock_auth[:yammer] = {
uid: generate(:yammer_uid),
info: {
- access_token: generate(:yammer_token),
email: email,
image: generate(:image),
name: generate(:yammer_user_name),
nickname: generate(:yammer_nickname),
yammer_network_id: 1,
yammer_profile_url: generate(:yammer_profile_url)
},
- extra: generate(:extra)
+ credentials: {
+ token: FactoryGirl.generate(:yammer_token)
+ },
+ extra: generate(:extra)
}
end
View
@@ -6,8 +6,10 @@
info: {
name: FactoryGirl.generate(:yammer_user_name),
email: FactoryGirl.generate(:email),
- access_token: FactoryGirl.generate(:yammer_token),
yammer_profile_url: FactoryGirl.generate(:yammer_profile_url),
yammer_network_id: 1
+ },
+ credentials: {
+ token: FactoryGirl.generate(:yammer_token)
}
}

0 comments on commit 96dab62

Please sign in to comment.