Class: OmniAuth::Strategies::Yammer

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/oauth2/yammer.rb

Overview

OAuth 2.0 based authentication with GitHub. In order to sign up for an application, you need to register an application and provide the proper credentials to this middleware.

Instance Attribute Summary

Attributes inherited from OAuth2

#client_id, #client_options, #client_secret, #options

Instance Method Summary collapse

Methods inherited from OAuth2

#callback_url, #client

Constructor Details

#initialize(app, client_id = nil, client_secret = nil, options = {}, &block) ⇒ Yammer

Returns a new instance of Yammer.



10
11
12
13
14
15
16
17
# File 'lib/omniauth/strategies/oauth2/yammer.rb', line 10

def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
  client_options = {
    :token_url => '/oauth2/access_token.json',
    :authorize_url => '/dialog/oauth',
    :site => 'https://www.yammer.com'
  }
  super(app, :yammer, client_id, client_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/omniauth/strategies/oauth2/yammer.rb', line 19

def auth_hash
  OmniAuth::Utils.deep_merge(
    super, {
      'uid' => user_hash['id'],
      'user_info' => ,
      'extra' => {
        'user_hash' => user_hash,
      },
    }
  )
end

#build_access_tokenObject



46
47
48
49
50
51
52
53
54
# File 'lib/omniauth/strategies/oauth2/yammer.rb', line 46

def build_access_token
  # Dance to get the real token out of the object returned by Yammer
  verifier = request.params['code']
  temp_access_token = client.auth_code.get_token(verifier, {:redirect_uri => callback_url}.merge(options))
  token = eval(temp_access_token.token)['token']
  @access_token = ::OAuth2::AccessToken.new(client, token, temp_access_token.params)
rescue ::OAuth2::Error => e
  raise e.response.inspect
end

#user_hashObject



56
57
58
# File 'lib/omniauth/strategies/oauth2/yammer.rb', line 56

def user_hash
  @user_hash ||= MultiJson.decode(@access_token.get('/api/v1/users/current.json').body)
end

#user_infoObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/omniauth/strategies/oauth2/yammer.rb', line 31

def 
  user_hash = self.user_hash
  {
    'nickname' => user_hash['name'],
    'name' => user_hash['full_name'],
    'location' => user_hash['location'],
    'image' => user_hash['mugshot_url'],
    'description' => user_hash['job_title'],
    'email' => user_hash['contact']['email_addresses'][0]['address'],
    'urls' => {
      'Yammer' => user_hash['web_url'],
    },
  }
end