Class: IntuitOAuth::Flow::Token

Inherits:
Base
  • Object
show all
Defined in:
lib/intuit-oauth/flow/token.rb

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from IntuitOAuth::Base

Instance Method Details

#get_bearer_token(auth_code, realm_id = nil) ⇒ AccessToken

Exchange the authorization Code for the Bearer Token

Parameters:

  • the (auth_code)

    Code send to your redirect_uri

  • the (realm_id)

    company ID for the Company

Returns:

  • (AccessToken)

    the AccessToken


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/intuit-oauth/flow/token.rb', line 31

def get_bearer_token(auth_code, realm_id=nil)
  if realm_id != nil
    @client.realm_id = realm_id
  end

  headers = {
    Accept: 'application/json',
    "Content-Type": 'application/x-www-form-urlencoded',
    Authorization: IntuitOAuth::Utils.get_auth_header(@client.id, @client.secret)
  }

  body = {
    grant_type: 'authorization_code',
    code: auth_code,
    redirect_uri: @client.redirect_uri
  }

  IntuitOAuth::Transport.request('POST', @client.token_endpoint, headers, URI.encode_www_form(body))
end

#refresh_tokens(token) ⇒ AccessToken

Using the token passed to generate a new refresh token and access token

Parameters:

  • the (token)

    refresh token used to refresh token

Returns:

  • (AccessToken)

    the AccessToken


55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/intuit-oauth/flow/token.rb', line 55

def refresh_tokens(token)
  headers = {
    "Content-Type": 'application/x-www-form-urlencoded',
    Authorization: IntuitOAuth::Utils.get_auth_header(@client.id, @client.secret)
  }

  body = {
    grant_type: 'refresh_token',
    refresh_token: token
  }

  IntuitOAuth::Transport.request('POST', @client.token_endpoint, headers, URI.encode_www_form(body))
end

#revoke_tokens(token) ⇒ boolean

Revoke the specific access token or refresh token. Return true if success, false otherwise

Parameters:

  • the (token)

    refresh token or access token to be invoked

Returns:

  • (boolean)

    True if successfully revoked. False otherwise


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/intuit-oauth/flow/token.rb', line 73

def revoke_tokens(token)
  headers = {
    "Content-Type": 'application/json',
    Authorization: IntuitOAuth::Utils.get_auth_header(@client.id, @client.secret)
  }

  body = {
    token: token
  }

  response = IntuitOAuth::Transport.request('POST', @client.revoke_endpoint, headers, body.to_json, false)
  if response.code == 200
    return true
  end

  return false
end