class IntuitOAuth::Flow::Token

Public Instance Methods

get_bearer_token(auth_code, realm_id=nil) click to toggle source

Exchange the authorization Code for the Bearer Token

@param [auth_code] the Code send to your redirect_uri @param [realm_id] the company ID for the Company @return [AccessToken] the AccessToken

# 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) click to toggle source

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

@param [token] the refresh token used to refresh token @return [AccessToken] the AccessToken

# 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) click to toggle source

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

@param [token] the refresh token or access token to be invoked @return [boolean] True if successfully revoked. False otherwise

# 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