Skip to content

Commit 0994c20

Browse files
authored
Merge pull request #77 from mnort9/jwt-authentication
Add JWT authentication
2 parents 7f66bf9 + 6de30eb commit 0994c20

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ client = RingCentralSdk::REST::Client.new do |config|
9393
config.extension = 'myExtension'
9494
config.password = 'myPassword'
9595

96+
# JWT (optional)
97+
config.jwt = 'myJwt'
98+
9699
# Set a custom logger (optional)
97100
config.logger = Logger.new(STDOUT)
98101

lib/ringcentral_sdk/rest/client.rb

+11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def initialize
4444
authorize_password @config.username, @config.extension, @config.password
4545
end
4646

47+
authorize_jwt(@config.jwt) if @config.jwt.present?
48+
4749
@messages = RingCentralSdk::REST::Messages.new self
4850
end
4951

@@ -118,6 +120,15 @@ def authorize_password(username, extension = '', password = '', params = {})
118120
token
119121
end
120122

123+
def authorize_jwt(jwt)
124+
token = @oauth2client.get_token({
125+
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
126+
assertion: jwt,
127+
})
128+
set_token token
129+
token
130+
end
131+
121132
def token
122133
@http ? @http.builder.app.oauth2_token : nil
123134
end

lib/ringcentral_sdk/rest/configuration.rb

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Configuration
1919
attr_accessor :password
2020
attr_accessor :token
2121
attr_accessor :token_file
22+
attr_accessor :jwt
2223

2324
attr_accessor :load_env
2425
attr_accessor :headers
@@ -52,6 +53,7 @@ def load_environment
5253
@password = ENV['RINGCENTRAL_PASSWORD'] if ENV.key? 'RINGCENTRAL_PASSWORD'
5354
@token = ENV['RINGCENTRAL_TOKEN'] if ENV.key? 'RINGCENTRAL_TOKEN'
5455
@token_file = ENV['RINGCENTRAL_TOKEN_FILE'] if ENV.key? 'RINGCENTRAL_TOKEN_FILE'
56+
@jwt = ENV['RINGCENTRAL_JWT'] if ENV.key? 'RINGCENTRAL_JWT'
5557
@retry = ENV['RINGCENTRAL_RETRY'] if ENV.key? 'RINGCENTRAL_RETRY'
5658
@retry_options = ENV['RINGCENTRAL_RETRY_OPTIONS'] if ENV.key? 'RINGCENTRAL_RETRY_OPTIONS'
5759
@headers = ENV['RINGCENTRAL_HEADERS'] if ENV.key? 'RINGCENTRAL_HEADERS'

0 commit comments

Comments
 (0)