Sha256: 7b3584e4c9a4888e3dbe6ca07172abf8e9e9807a33dc81f97a4c70725f1a63db
Contents?: true
Size: 1.02 KB
Versions: 45
Compression:
Stored size: 1.02 KB
Contents
module Alula class TokenExchange def self.token_for_user(user_id) url = '/rest/v1/oauth/accesstokens' payload = { data: { attributes: { userId: user_id } } } opts = {} response = Alula::Client.request(:post, url, payload, opts) if response.ok? ImpersonatedToken.new(response.data['data']['attributes']) else error_class = AlulaError.for_response(response) raise error_class end end class ImpersonatedToken # Simple Oauth::Response reader object attr_reader :date_created, :access_token, :expires_in, :expires_at, :refresh_token, :scope def initialize(attributes) @raw_response = attributes @date_created = Time.parse(attributes['dateCreated']) @access_token = attributes['accessToken'] @expires_at = Time.parse(attributes['expires']) @expires_in = (@expires_at - Time.now.utc).to_i @refresh_token = attributes['refresh_token'] @scope = attributes['scope'] end end end end
Version data entries
45 entries across 45 versions & 1 rubygems