sourav-mazumder / Data-Science-Extensions

71 stars 63 forks source link

How to pass user authentication in notebook #3

Closed ashitabh closed 1 year ago

ashitabh commented 5 years ago

How do I pass header -> Authorization : Bearer xxxyyyzzz" in notebook

mikeyoungyoung commented 5 years ago

@ashitabh have you solved this yet? I'm running into the same issue. I can only successfully authenticate when the keys are held as query params. Header params are not working for me

@sourav-mazumder any help with that?

ashitabh commented 5 years ago

Hi Mike, I did some changes in RestConnectorUtil.scala. Line no: 53 for Get method

 var httpc = (method: @switch) match {
      //case "GET" => Http(addQryParmToUri(uri, data)).header("contenty-type",
       //              "application/x-www-form-urlencoded")
       case "GET" => Http(addQryParmToUri(uri, data)).header("Authorization",authToken)
      case "PUT" => Http(uri).put(data).header("content-type", contentType)
      case "DELETE" => Http(uri).method("DELETE")
      case "POST" => Http(uri).postData(data).header("content-type", contentType)
    }

and then from notebook/ spark code I used the following

val sodauri = "https://somesrestapi.com/v4/entity/user"
val parmg = Map("url" -> sodauri, "input" -> "sodainputtbl", "method" -> "GET","authType"->"Basic","authToken"->"Auth-Token xxxxx","readTimeout" -> "200000", "connectionTimeout" -> "200000", "partitions" -> "10")
val sodasDf = spark.read.format("org.apache.dsext.spark.datasource.rest.RestDataSource").options(parmg).load()
mikeyoungyoung commented 5 years ago

@ashitabh okay cool, I was expecting something similar. Unfortunately the headers in most of the apis I use are very different... so will have to build a header builder util or something

amandal1810 commented 5 years ago

the authorization header key-value can be added for the POST method as well case "POST" => Http(uri).postData(data).header("Content-Type", contentType).header("Authorization",authToken)