httpbuilder icon indicating copy to clipboard operation
httpbuilder copied to clipboard

NTLM Authentication in groovy (-> Sharepoint-API)

Open schneich opened this issue 4 years ago • 0 comments

Hi, I am trying to call a Sharepoint REST-API out of a Jira-Groovy-environment. Unfortunately, I am struggling with the authentication. How do a I have to set up my code, so that NTLM authentication is used, when addressing the sharepoint REST API?

Any help or link to the right documentation is very much appreciated.

My current code, but it results in a 401 response.

import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import static groovyx.net.http.Method.*
import groovy.json.JsonSlurper
import net.sf.json.groovy.JsonSlurper
import groovyx.net.http.Method

def http = new HTTPBuilder('http://base.url')

http.request(POST, JSON) {
   requestContentType = ContentType.JSON
   headers."Accept-Encoding" = "gzip, deflate, br"
   headers."Accept" = "application/json;odata=verbose"
   headers."Content-Type" = "application/json;odata=verbose"
   headers."Connection" = "keep-alive"


   body = [username: 'user', password: 'password']

      response.success = { resp, JSON ->

         return JSON

      }

      response.failure = { resp ->
         return "Request failed with status ${resp.status}"

      }
}

schneich avatar Jan 27 '22 12:01 schneich