Skip to content

Commit

Permalink
Use autentication header when strategy is token
Browse files Browse the repository at this point in the history
  • Loading branch information
gridanjbf committed Apr 22, 2024
1 parent 07e7f45 commit 9b57590
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
15 changes: 9 additions & 6 deletions lib/sharepoint/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Sharepoint
class Client
FILENAME_INVALID_CHARS = '~"#%&*:<>?/\{|}'

def authenticating
def authenticating_with_token
generate_new_token
yield
end
Expand Down Expand Up @@ -326,11 +326,11 @@ def create_folder(name, path, site_path = nil)
path = path[1..-1] if path[0].eql?('/')
url = uri_escape "#{url}GetFolderByServerRelativeUrl('#{path}')/Folders"
easy = ethon_easy_json_requester
easy.headers = {
easy.headers = with_bearer_authentication_header({
'accept' => 'application/json;odata=verbose',
'content-type' => 'application/json;odata=verbose',
'X-RequestDigest' => xrequest_digest(site_path)
}
})
payload = {
'__metadata' => {
'type' => 'SP.Folder'
Expand Down Expand Up @@ -539,6 +539,7 @@ def computed_web_api_url(site)
end

def ethon_easy_json_requester

easy = ethon_easy_requester
easy.headers = with_bearer_authentication_header({ 'accept' => 'application/json;odata=verbose' })
easy
Expand All @@ -550,9 +551,11 @@ def ethon_easy_options

def ethon_easy_requester
if token_auth?
easy = Ethon::Easy.new({ followlocation: 1, maxredirs: 5 }.merge(ethon_easy_options))
easy.headers = with_bearer_authentication_header({})
easy
authenticating_with_token do
easy = Ethon::Easy.new({ followlocation: 1, maxredirs: 5 }.merge(ethon_easy_options))
easy.headers = with_bearer_authentication_header({})
easy
end
elsif ntlm_auth?
easy = Ethon::Easy.new({ httpauth: :ntlm, followlocation: 1, maxredirs: 5 }.merge(ethon_easy_options))
easy.username = config.username
Expand Down
3 changes: 1 addition & 2 deletions lib/sharepoint/client/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def expired?
(fetched_at + expires_in) < Time.now.utc.to_i
end

def
def(_request_new_token)
def request_new_token
auth_request = {
client_id: config.client_id,
client_secret: config.client_secret,
Expand Down

0 comments on commit 9b57590

Please sign in to comment.