Class: PayPal::SDK::Core::OpenIDConnect::DataTypes::Tokeninfo

Inherits:
Base show all
Includes:
RequestDataType
Defined in:
lib/paypal-sdk/core/openid_connect.rb,
lib/paypal-sdk/core/openid_connect/data_types.rb

Constant Summary collapse

PATH =
"v1/identity/openidconnect/tokenservice"
FP_PATH =
"v1/oauth2/token"

Constants inherited from API::DataTypes::Base

API::DataTypes::Base::ContentKey, API::DataTypes::Base::HashOptions

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RequestDataType

#api, api, client_id, client_secret, included

Methods included from SetAPI

#client_id=, #client_secret=, #set_config

Methods inherited from API::DataTypes::Base

add_attribute, add_member, array_of, #convert_array, #convert_object, define_alias_methods, #hash_key, #initialize, #member_names, members, #members, #merge!, object_of, #set, #skip_value?, snakecase, #to_hash, #value_to_hash

Methods included from Logging

#log_event, #logger, logger, logger=

Constructor Details

This class inherits a constructor from PayPal::SDK::Core::API::DataTypes::Base

Class Method Details

.authorize_url(options = {}) ⇒ Object



100
101
102
# File 'lib/paypal-sdk/core/openid_connect.rb', line 100

def authorize_url(options = {})
  OpenIDConnect.authorize_url(options)
end

.basic_auth_header(options) ⇒ Object



62
63
64
65
66
# File 'lib/paypal-sdk/core/openid_connect.rb', line 62

def basic_auth_header(options)
  credentials = options[:client_id].to_s + ":" + options[:client_secret].to_s
  encoded = Base64.encode64(credentials.force_encoding('UTF-8')).gsub!(/\n/, "")
  "Basic #{encoded}"
end

.create_from_authorization_code(options, http_header = {}) ⇒ Object Also known as: create



68
69
70
71
72
# File 'lib/paypal-sdk/core/openid_connect.rb', line 68

def create_from_authorization_code(options, http_header = {})
  options = { :code => options } if options.is_a? String
  options = options.merge( :grant_type => "authorization_code" )
  Tokeninfo.new(api.post(PATH, with_credentials(options), http_header))
end

.create_from_future_payment_auth_code(options, http_header = {}) ⇒ Object Also known as: token_hash, create_fp



83
84
85
86
87
88
# File 'lib/paypal-sdk/core/openid_connect.rb', line 83

def create_from_future_payment_auth_code(options, http_header = {})
  options = { :code => options } if options.is_a? String
  options = options.merge( { :grant_type => "authorization_code", :response_type => "token", :redirect_uri => "urn:ietf:wg:oauth:2.0:oob" } )
  http_header = http_header.merge( { "Content-Type" => "application/x-www-form-urlencoded", "Authorization" => basic_auth_header(with_credentials(options)) } )
  Tokeninfo.new(api.post(FP_PATH, options, http_header))
end

.create_from_refresh_token(options, http_header = {}) ⇒ Object Also known as: refresh



75
76
77
78
79
80
# File 'lib/paypal-sdk/core/openid_connect.rb', line 75

def create_from_refresh_token(options, http_header = {})
  options = { :refresh_token => options } if options.is_a? String
  options = options.merge( :grant_type => "refresh_token" )
  http_header = http_header.merge( { "Content-Type" => "application/x-www-form-urlencoded", "Authorization" => basic_auth_header(with_credentials(options)) } )
  Tokeninfo.new(api.post(PATH, options, http_header))
end

.load_membersObject



47
48
49
50
51
52
53
54
# File 'lib/paypal-sdk/core/openid_connect/data_types.rb', line 47

def self.load_members
  object_of :scope, String
  object_of :access_token, String
  object_of :refresh_token, String
  object_of :token_type, String
  object_of :id_token, String
  object_of :expires_in, Integer
end

.with_credentials(options = {}) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/paypal-sdk/core/openid_connect.rb', line 92

def with_credentials(options = {})
  options = options.dup
  [ :client_id, :client_secret ].each do |key|
    options[key] = self.send(key) unless options[key] or options[key.to_s]
  end
  options
end

Instance Method Details

#logout_url(options = {}) ⇒ Object



115
116
117
# File 'lib/paypal-sdk/core/openid_connect.rb', line 115

def logout_url(options = {})
  OpenIDConnect.logout_url({ :id_token => self.id_token }.merge(options))
end

#refresh(options = {}) ⇒ Object



105
106
107
108
109
# File 'lib/paypal-sdk/core/openid_connect.rb', line 105

def refresh(options = {})
  tokeninfo = self.class.refresh({
    :refresh_token => self.refresh_token}.merge(options))
  self.merge!(tokeninfo.to_hash)
end

#userinfo(options = {}) ⇒ Object



111
112
113
# File 'lib/paypal-sdk/core/openid_connect.rb', line 111

def userinfo(options = {})
  Userinfo.get({ :access_token => self.access_token }.merge(options))
end