Class: Yammer::OAuth2Client

Inherits:
OAuth2Client::Client
  • Object
show all
Defined in:
lib/yammer/oauth2_client.rb

Constant Summary collapse

SITE_URL =
'https://www.yammer.com'
TOKEN_PATH =
'/oauth2/access_token'
AUTHORIZE_PATH =
'/oauth2/authorize'

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret, opts = {}) {|_self| ... } ⇒ OAuth2Client

Returns a new instance of OAuth2Client

Yields:

  • (_self)

Yield Parameters:


24
25
26
27
28
29
30
31
# File 'lib/yammer/oauth2_client.rb', line 24

def initialize(client_id, client_secret, opts={})
  site_url = opts.delete(:site_url) || SITE_URL
  opts[:token_path]     ||= TOKEN_PATH
  opts[:authorize_path] ||= AUTHORIZE_PATH
  super(site_url, client_id, client_secret, opts)
  yield self if block_given?
  self
end

Instance Method Details

#access_token_from_authorization_code(code, opts = {}) ⇒ Object

client_id=Configurable#client_id&code=G3Y6jU3a&grant_type=authorization_code& redirect_uri=http%3A%2F%2Flocalhost%2Foauth%2Fcb&client_secret=Configurable#client_secret


88
89
90
91
# File 'lib/yammer/oauth2_client.rb', line 88

def access_token_from_authorization_code(code, opts={})
  opts[:authenticate] ||= :body
  authorization_code.get_token(code, opts)
end

#access_token_from_client_credentials(opts = {}) ⇒ Object

Makes a request to Yammer server that will swap client credential for an access token

client = Yammer::OAuth2Client.new('ETSIGVSxmgZitijWZr0G6w', '4bJZY38TCBB9q8IpkeualA2lZsPhOSclkkSKw3RXuE') client.access_token_from_client_credentials({ :client_id => "ZitijWZr0", :client_secret => "F8TCBB9q8IpkeualA2lZsPhOSc" })

POST /oauth2/access_token HTTP/1.1 Host: www.yammer.com Content-Type: application/x-www-form-urlencoded

client_id=Configurable#client_id&client_secret=Configurable#client_secret


108
109
110
111
# File 'lib/yammer/oauth2_client.rb', line 108

def access_token_from_client_credentials(opts={})
  opts[:authenticate] ||= :body
  client_credentials.get_token(opts)
end

#access_token_from_resource_owner_credentials(username, password, opts = {}) ⇒ Object

Makes a request to Yammer server that will swap resource owner credentials for an access token

client = Yammer::OAuth2Client.new('ETSIGVSxmgZitijWZr0G6w', '4bJZY38TCBB9q8IpkeualA2lZsPhOSclkkSKw3RXuE') client.access_token_from_client_credentials({ :client_id => "ZitijWZr0", :client_secret => "F8TCBB9q8IpkeualA2lZsPhOSc", :email => "[email protected]", :password => "abc123" })

POST /oauth2/access_token HTTP/1.1 Host: www.yammer.com Content-Type: application/x-www-form-urlencoded

client_id=Configurable#client_id&client_secret=Configurable#client_secret&username=username&password=passwort


130
131
132
133
# File 'lib/yammer/oauth2_client.rb', line 130

def access_token_from_resource_owner_credentials(username, password, opts={})
  opts[:authenticate] ||= :body
  self.password.get_token(username, password, opts)
end

#webclient_authorization_url(opts = {}) ⇒ Object

Generates the Yammer URL that the user will be redirected to in order to authorize your application

client = Yammer::OAuth2Client.new('ETSIGVSxmgZitijWZr0G6w', '4bJZY38TCBB9q8IpkeualA2lZsPhOSclkkSKw3RXuE') client.webclient_authorization_url({ :redirect_uri => 'https://localhost/oauth/cb', }) https://www.yammer.com/oauth2/authorize/?client_id=Configurable#client_id& redirect_uri=http%3A%2F%2Flocalhost%2Foauth%2Fcb&response_type=token


47
48
49
# File 'lib/yammer/oauth2_client.rb', line 47

def webclient_authorization_url(opts={})
  implicit.token_url(opts)
end

#webserver_authorization_url(opts = {}) ⇒ Object

Generates the Yammer URL that the user will be redirected to in order to authorize your application

client = Yammer::OAuth2Client.new('ETSIGVSxmgZitijWZr0G6w', '4bJZY38TCBB9q8IpkeualA2lZsPhOSclkkSKw3RXuE') client.webserver_authorization_url({ :redirect_uri => 'https://localhost/oauth/cb', }) https://www.yammer.com/oauth2/authorize/?client_id=Configurable#client_id& redirect_uri=http%3A%2F%2Flocalhost%2Foauth%2Fcb&response_type=code


65
66
67
68
# File 'lib/yammer/oauth2_client.rb', line 65

def webserver_authorization_url(opts={})
  opts[:scope] = normalize_scope(opts[:scope]) if opts[:scope]
  authorization_code.authorization_url(opts)
end