Skip to content

Commit

Permalink
feat: add oauth support for ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
manisha1997 committed Nov 13, 2024
1 parent 6fcd61d commit 347e4ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
8 changes: 2 additions & 6 deletions lib/twilio-ruby/credential/orgs_credential_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ def initialize(client_id, client_secret, orgs_token = nil)
end

def to_auth_strategy
if @orgs_token.nil?
@orgs_token = TokenManager.new(@grant_type, @client_id, @client_secret)
end
if @auth_strategy.nil?
@auth_strategy = TokenAuthStrategy.new(@orgs_token)
end
@orgs_token = TokenManager.new(@grant_type, @client_id, @client_secret) if @orgs_token.nil?
@auth_strategy = TokenAuthStrategy.new(@orgs_token) if @auth_strategy.nil?
@auth_strategy
end
end
Expand Down
22 changes: 11 additions & 11 deletions oauth_test.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true
require './lib/twilio-ruby'
require './lib/twilio-ruby/base/client_base'
require './lib/twilio-ruby/credential/orgs_credential_provider'
credentialProvider = Twilio::REST::OrgsCredentialProvider.new(ENV['CLIENT_ID'], ENV['CLIENT_SECRET'])
client = Twilio::REST::Client.new().credential_provider(credentialProvider)
response = client.preview_iam.organizations(ENV['ORG_SID'])
.accounts('').fetch
client_2 = Twilio::REST::Client.new(ENV['SID'], ENV['TOKEN'])
# response = client_2.messages.create(from: ENV['FROM'], to: ENV['TO'], body: 'Hello World')
puts response
# # frozen_string_literal: true
# require './lib/twilio-ruby'
# require './lib/twilio-ruby/base/client_base'
# require './lib/twilio-ruby/credential/orgs_credential_provider'
# credentialProvider = Twilio::REST::OrgsCredentialProvider.new(ENV['CLIENT_ID'], ENV['CLIENT_SECRET'])
# client = Twilio::REST::Client.new().credential_provider(credentialProvider)
# response = client.preview_iam.organizations(ENV['ORG_SID'])
# .accounts('').fetch
# client_2 = Twilio::REST::Client.new(ENV['SID'], ENV['TOKEN'])
# # response = client_2.messages.create(from: ENV['FROM'], to: ENV['TO'], body: 'Hello World')
# puts response

0 comments on commit 347e4ef

Please sign in to comment.