class NexaasID::Client::Identity

Nexaas ID Client for resources owned by an Identity

API

Documentation:

@example Obtaining a user's profile:

client = NexaasID::Client::Identity.new(user_credentials)
client.profile.get

Constants

ATTRIBUTES

Attributes

credentials[R]
token[RW]

Public Class Methods

new(credentials, config = nil) click to toggle source

Creates an instance of this client.

@param [

#access_token, #access_token=,
#refresh_token, #refresh_token=,
#expires_at, #expires_at=
#expires_in, #expires_in=] The user credentials, obtained through the OAuth2 authorization flow.
Calls superclass method NexaasID::Client::Base::new
# File lib/nexaas_id/client/identity.rb, line 22
def initialize(credentials, config = nil)
  super(config)
  @credentials = credentials
  @token = NexaasID::Client::ExceptionWrapper.new(OAuth2::AccessToken.from_hash(client, hash))
end

Public Instance Methods

profile() click to toggle source

Provides a Profile resource. @return [NexaasID::Resources::Profile] the profile resource.

# File lib/nexaas_id/client/identity.rb, line 30
def profile
  NexaasID::Resources::Profile.new(api_token, config)
end
widget() click to toggle source

Provides a Widget resource. @return [NexaasID::Resources::Widget] the widget resource.

# File lib/nexaas_id/client/identity.rb, line 36
def widget
  NexaasID::Resources::Widget.new(api_token, config)
end

Protected Instance Methods

api_token() click to toggle source
# File lib/nexaas_id/client/identity.rb, line 42
def api_token
  token.expired? ? refresh_token : token
end

Private Instance Methods

hash() click to toggle source
# File lib/nexaas_id/client/identity.rb, line 52
def hash
  ATTRIBUTES.map { |attr| [attr, credentials.send(attr)] }.to_h
end
refresh_token() click to toggle source
# File lib/nexaas_id/client/identity.rb, line 56
def refresh_token
  token.refresh!.tap do |token|
    self.token = NexaasID::Client::ExceptionWrapper.new(token)
    credentials.access_token = token.token
    (ATTRIBUTES - [:access_token]).each { |attr| credentials.send("#{attr}=", token.send(attr)) }
  end
end