lib/ringcentral_sdk/rest/client.rb in ringcentral_sdk-3.0.1 vs lib/ringcentral_sdk/rest/client.rb in ringcentral_sdk-3.1.0
- old
+ new
@@ -21,16 +21,11 @@
REVOKE_ENDPOINT = '/restapi/oauth/revoke'.freeze
API_VERSION = 'v1.0'.freeze
URL_PREFIX = '/restapi'.freeze
DEFAULT_LANGUAGE = 'en-us'.freeze
- attr_reader :config
- attr_reader :http
- attr_reader :logger
- attr_reader :oauth2client
- attr_reader :user_agent
- attr_reader :messages
+ attr_reader :config, :http, :logger, :messages, :oauth2client, :user_agent
def initialize
init_attributes
raise ArgumentError, 'Config block not given' unless block_given?
@@ -38,14 +33,17 @@
yield config
@config.inflate
@oauth2client = new_oauth2_client
- unless @config.username.to_s.empty?
- authorize_password @config.username, @config.extension, @config.password
- end
+ # Remove Password Grant
+ # unless @config.username.to_s.empty?
+ # authorize_password @config.username, @config.extension, @config.password
+ # end
+ authorize_jwt(@config.jwt) unless @config.jwt.to_s.empty?
+
@messages = RingCentralSdk::REST::Messages.new self
end
def init_attributes
@http = nil
@@ -107,15 +105,24 @@
opts[:redirect_uri] = @config.redirect_url.to_s
end
opts
end
- def authorize_password(username, extension = '', password = '', params = {})
- token = @oauth2client.password.get_token(username, password, {
- extension: extension,
- headers: { 'Authorization' => 'Basic ' + api_key }
- }.merge(params))
+ # def authorize_password(username, extension = '', password = '', params = {})
+ # token = @oauth2client.password.get_token(username, password, {
+ # extension: extension,
+ # headers: { 'Authorization' => 'Basic ' + api_key }
+ # }.merge(params))
+ # set_token token
+ # token
+ # end
+
+ def authorize_jwt(jwt)
+ token = @oauth2client.get_token({
+ grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
+ assertion: jwt
+ })
set_token token
token
end
def token
@@ -236,11 +243,13 @@
def create_subscription
RingCentralSdk::REST::Subscription.new self
end
- alias authorize authorize_password
- alias login authorize_password
+ # alias authorize authorize_password
+ # alias login authorize_password
+ alias authorize authorize_jwt
+ alias login authorize_jwt
private :api_version_url
end
end
end