Class: IntuitOAuth::Migration::Migrate

Inherits:
Base
  • Object
show all
Defined in:
lib/intuit-oauth/migration.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

#migrate_tokens(consumer_key, consumer_secret, access_token, access_secret, scopes) ⇒ OAuth2Token

Exchange an OAuth 1 token for an OAuth 2 token pair. It is used for apps that are using OAuth 1.0 and want to migrate to OAuth 2.0.

Parameters:

  • the (cusomer_key)

    OAuth 1.0 Consumer key

  • the (consumer_secret)

    OAuth 1.0 Consumer Secret

  • the (access_token)

    OAuth 1.0 Access Token

  • the (access_secret)

    OAuth 1.0 Access Token Secret

  • the (scopes)

    scopes for the token.

Returns:

  • (OAuth2Token)

    the OAuth2 Token object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/intuit-oauth/migration.rb', line 34

def migrate_tokens(consumer_key, consumer_secret, access_token, access_secret, scopes)
  if %w[production prod].include? @client.environment.downcase
    migration_endpoint = IntuitOAuth::Config::MIGRATION_URL_PROD
  else
    migration_endpoint = IntuitOAuth::Config::MIGRATION_URL_SANDBOX
  end

  oauth1_tokens = {
    consumer_key: consumer_key,
    consumer_secret: consumer_secret,
    access_token: access_token,
    access_secret: access_secret
  }
  oauth1_header = IntuitOAuth::Utils.get_oauth1_header('POST', migration_endpoint, oauth1_tokens)
  headers = {
    'Content-Type': 'application/json',
    Accept: 'application/json',
    Authorization: oauth1_header
  }

  body = {
    scope: IntuitOAuth::Utils.scopes_to_string(scopes),
    redirect_uri: @client.redirect_uri,
    client_id: @client.id,
    client_secret: @client.secret
  }

  IntuitOAuth::Transport.request('POST', migration_endpoint, headers, body.to_json)
end