Class: Gigya::OAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/gigya/oauth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret, oauth_callback_url = nil) ⇒ OAuth

Returns a new instance of OAuth.



5
6
7
8
9
# File 'lib/gigya/oauth.rb', line 5

def initialize(client_id, client_secret, oauth_callback_url = nil)
  @client_id          = client_id
  @client_secret      = client_secret
  @oauth_callback_url = oauth_callback_url
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



3
4
5
# File 'lib/gigya/oauth.rb', line 3

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



3
4
5
# File 'lib/gigya/oauth.rb', line 3

def client_secret
  @client_secret
end

#oauth_callback_urlObject (readonly)

Returns the value of attribute oauth_callback_url.



3
4
5
# File 'lib/gigya/oauth.rb', line 3

def oauth_callback_url
  @oauth_callback_url
end

Instance Method Details

#get_token(code) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gigya/oauth.rb', line 26

def get_token(code)
  params = {
    client_id: @client_id,
    client_secret: @client_secret,
    redirect_uri: @oauth_callback_url,
    grant_type: 'authorization_code',
    code: code
  }

  url = Gigya.build_url(Gigya::URLS[:socialize], Gigya::URIS[:get_token])

  response = Gigya.connection.post(url, params)

  JSON.parse response.body
end

#login(provider) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gigya/oauth.rb', line 11

def (provider)
  params = {
    client_id: @client_id,
    redirect_uri: @oauth_callback_url,
    response_type: 'code',
    x_provider: provider
  }

  url = Gigya.build_url(Gigya::URLS[:socialize], Gigya::URIS[:login])

  response = Gigya.connection.get(url, params)

  response['location']
end