Class: SdkOAuth2FlowBase

Version 1.5 - Updated on 12/15/2016

Contents

Overview

Base class for the two OAuth 2.0 authorization helpers.

Direct Known Subclasses

Constructor Details

#initialize(consumer_key, consumer_secret, locale = nil) ⇒ SdkOAuth2FlowBase

Returns a new instance of SdkOAuth2FlowBase.

def initialize(consumer_key, consumer_secret, locale=nil)
  if not consumer_key.is_a?(String)
    raise ArgumentError, "consumer_key must be a String, got #{consumer_key.inspect}"
  end
  if not consumer_secret.is_a?(String)
    raise ArgumentError, "consumer_secret must be a String, got #{consumer_secret.inspect}"
  end
  if not (locale.nil? or locale.is_a?(String))
    raise ArgumentError, "locale must be a String or nil, got #{locale.inspect}"
  end
  @consumer_key = consumer_key
  @consumer_secret = consumer_secret
  @locale = locale
end

Instance Method Details

_finish

#_finish(code, original_redirect_uri) ⇒ Object

Completes the OAuth 2.0 authorization process. If you used a redirect_uri, you should spcify it. This method returns an access token string that you can use with SdkClient.

def _finish(code, original_redirect_uri)
  if not code.is_a?(String)
    raise ArgumentError, "code must be a String"
  end

  uri = URI.parse("https://#{Sdk::API_SERVER}/cloud/1/oauth2/token")
  request = Net::HTTP::Post.new(uri.request_uri)
  #client_credentials = @consumer_key + ':' + @consumer_secret
  #request.add_field('Authorization', 'Basic ' + Base64.encode64(client_credentials).chomp("\n"))

  params = {
 "client_id" => @consumer_key,
 "client_secret" => @consumer_secret,
    "grant_type" => "authorization_code",
    "code" => code,
    "redirect_uri" => original_redirect_uri,
  }

  request.set_form_data(Sdk::clean_params(params))
  response = Sdk::do_http(uri, request)

  j = Sdk::parse_response(response)
  ["token_type", "access_token"].each { |k|
  
  }
  

  return j['access_token']
end

_get_authorize_url

#_get_authorize_url(redirect_uri, state) ⇒ Object

def _get_authorize_url(redirect_uri, state)
  params = {
    "client_id" => @consumer_key,
    "response_type" => "code",
    "redirect_uri" => redirect_uri,
    "state" => state,
    "locale" => @locale,
  }

  host = Sdk::WEB_SERVER
  path = "/authorize"
  logger = Logger.new(STDOUT)
	logger.info "check"
	logger.info "check"
  logger.info host
  target = URI::Generic.new("https", nil, host, nil, nil, path, nil, nil, nil)
  
  target.query = Sdk::make_query_string(params)
logger = Logger.new(STDOUT)
	logger.info "check"
  logger.info target
  target.to_s
end

Copyright © 2015-2017, Verizon and/or its Licensors. All rights reserved.