Class: Vend::Oauth2::AuthCode

Inherits:
Object
  • Object
show all
Defined in:
lib/vend/oauth2/auth_code.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{}
AUTHORIZE_URL =
'/connect'
TOKEN_URL =
'/api/1.0/token'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store, client_id, secret, redirect_uri, options = {}) ⇒ AuthCode

Returns a new instance of AuthCode.



12
13
14
15
16
17
18
# File 'lib/vend/oauth2/auth_code.rb', line 12

def initialize(store, client_id, secret, redirect_uri, options = {})
  @store = store
  @client_id = client_id
  @secret = secret
  @redirect_uri = redirect_uri
  @options = DEFAULT_OPTIONS.merge(options)
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



10
11
12
# File 'lib/vend/oauth2/auth_code.rb', line 10

def client_id
  @client_id
end

#redirect_uriObject

Returns the value of attribute redirect_uri.



10
11
12
# File 'lib/vend/oauth2/auth_code.rb', line 10

def redirect_uri
  @redirect_uri
end

#secretObject

Returns the value of attribute secret.



10
11
12
# File 'lib/vend/oauth2/auth_code.rb', line 10

def secret
  @secret
end

#storeObject

Returns the value of attribute store.



10
11
12
# File 'lib/vend/oauth2/auth_code.rb', line 10

def store
  @store
end

Instance Method Details

#authorize_urlObject



20
21
22
# File 'lib/vend/oauth2/auth_code.rb', line 20

def authorize_url
  get_oauth2_client.auth_code.authorize_url(redirect_uri: redirect_uri)
end

#refresh_token(auth_token, refresh_token) ⇒ Object



29
30
31
32
# File 'lib/vend/oauth2/auth_code.rb', line 29

def refresh_token(auth_token, refresh_token)
  access_token = OAuth2::AccessToken.new(get_oauth2_client(store), auth_token, {refresh_token: refresh_token})
  access_token.refresh!
end

#token_from_code(code) ⇒ Object



24
25
26
27
# File 'lib/vend/oauth2/auth_code.rb', line 24

def token_from_code(code)
  client = get_oauth2_client(store)
  client.auth_code.get_token(code, redirect_uri: redirect_uri)
end