我正在努力使用Apache HUE Rest API和django csrf。
问题是我可以进行登录,但是其余的行不通。我总是被重定向到登录页面。好像服务器不喜欢我的csrftoken
或sessionid
Cookie。
我完全不知道为什么。这是我的登录代码:
val accessToken = getAccessToken(Http(s"$baseUrl/accounts/login/?next=/").asString)
val response =
Http(s"$baseUrl/accounts/login/")
.postForm(Seq(
"username" -> username,
"password" -> password,
"csrfmiddlewaretoken" -> accessToken.csrftoken.getValue,
"next" -> "/"
))
.cookie(accessToken.csrftoken)
.asString
getAccessToken(response) // wrapper for cookies and headers from response
现在我尝试仅从csrf保护的HUE获取页面
def getDir(hdfsPathDirParent: String): Unit = {
val accessToken = login()
val response = Http(s"$baseUrl/filebrowser/view=$hdfsPathDirParent")
.cookie(accessToken.csrftoken) // retrieved after login
.cookie(accessToken.sessionid) // retrieved after login
.header("X-CSRFToken", accessToken.csrftoken.getValue)
.header("Host", "localhost:8888")
.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
.header("Connection", "keep-alive")
.header("Sec-Fetch-Dest", "empty")
.header("Sec-Fetch-Mode", "cors")
.header("Sec-Fetch-Site", "same-origin")
//.header("Sec-Fetch-User", "?1")
.header("Upgrade-Insecure-Requests", "1")
.header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36")
.header("Accept-Encoding", "gzip, deflate, br")
.header("Accept-Language", "en,en-US;q=0.9,ru;q=0.8")
.header("Cache-Control", "max-age=0")
.header("X-Requested-With", "XMLHttpRequest")
.asString
我实际上是从Google Chrome调试面板复制粘贴了所有令牌。它不起作用
[30/May/2020 05:19:29 -0700] access WARNING 172.17.0.1 test_user - "POST /accounts/login/ HTTP/1.1" -- Successful login for user: test_user
[30/May/2020 05:19:29 -0700] middleware INFO Redirecting to login page: /filebrowser/view=/user/test_user
[30/May/2020 05:19:29 -0700] access INFO 172.17.0.1 -anon- - "GET /filebrowser/view=/user/test_user HTTP/1.1" -- login redirection
所以我确实通过了登录表格,但是其余的都行不通。找不到我想念的东西...
他们的代码示例不起作用
http://cloudera.github.io/hue/latest/developer/api/
您不找回HTTP 302重定向而不是200重定向吗? (因此您需要在代码后跟随它)。
同样在文档站点上方也是陈旧的,https://docs.gethue.com/developer/api/#python是新的。