简体   繁体   English

OAuth2访问FIWARE Lab中的Cosmos'WebHDFS

[英]OAuth2 access to Cosmos' WebHDFS in FIWARE Lab

I've recently seen the access to Cosmos' WebHDFS in FIWARE Lab has been protected with OAuth2. 我最近看到FIWARE Lab中对Cosmos的WebHDFS的访问受到了OAuth2的保护。 I know I have to add a OAuth2 token to the request in order to continue using WebHDFS, but: 我知道我必须向请求添加OAuth2令牌才能继续使用WebHDFS,但是:

  • How can I get the token? 我怎样才能获得令牌?
  • How the token is added to the request? 令牌如何添加到请求中?

Without the token, the API always returns: 如果没有令牌,API始终会返回:

$ curl -X GET "http://cosmos.lab.fi-ware.org:14000/webhdfs/v1/user/gtorodelvalle?op=liststatus&user.name=gtorodelvalle"
Auth-token not found in request header

Yes, now WebHDFS access is protected with OAuth2. 是的,现在WebHDFS访问受OAuth2保护。 This is part of the general mechanism for pretecting REST APIs in FIWARE, which performs authentication and authorization. 这是在FIWARE中预检REST API的一般机制的一部分,它执行身份验证和授权。 You can find more details here . 你可以在这里找到更多细节。

First of all, you must request an OAuth2 token to the Cosmos tokens generator. 首先,您必须向Cosmos令牌生成器请求OAuth2令牌。 This is a service running in cosmos.lab.fiware.org:13000 . 这是在cosmos.lab.fiware.org:13000运行的服务。 You can do this using any REST client, the easiest way is using the curl command: 您可以使用任何REST客户端执行此操作,最简单的方法是使用curl命令:

$ curl -k -X POST "https://cosmos.lab.fiware.org:13000/cosmos-auth/v1/token" -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=password&username=frb@tid.es&password=xxxxxxxx"
{"access_token": "qjHPUcnW6leYAqr3Xw34DWLQlja0Ix", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "V2Wlk7aFCnElKlW9BOmRzGhBtqgR2z"}

As you can see, your FIWARE Lab credentials are required in the payload, in the form of a password-based grant type. 如您所见,有效负载中需要您的FIWARE Lab凭据,采用基于密码的授权类型。

Once the access token is got (in the example above, it is qjHPUcnW6leYAqr3Xw34DWLQlja0Ix ), simply add it to the same WebHDFS request you were performing in the past. 获得访问令牌后(在上面的示例中,它是qjHPUcnW6leYAqr3Xw34DWLQlja0Ix ),只需将其添加到您过去执行的同一WebHDFS请求中。 The token is added by using the X-Auth-Token header: 使用X-Auth-Token标头添加X-Auth-Token

$ curl -X GET "http://cosmos.lab.fiware.org:14000/webhdfs/v1/user/frb/path/to/the/data?op=liststatus&user.name=frb" -H "X-Auth-Token: qjHPUcnW6leYAqr3Xw34DWLQlja0Ix"
{"FileStatuses":{"FileStatus":[...]}}

If you try the above request with a random token the server will return the token is not valid; 如果您使用随机令牌尝试上述请求,服务器将返回令牌无效; that's because you have not authenticated properly : 那是因为你没有正确认证

$ curl -X GET "http://cosmos.lab.fiware.org:14000/webhdfs/v1/user/frb/path/tp/the/data?op=liststatus&user.name=frb" -H "X-Auth-Token: randomtoken93487345"
User token not authorized

The same way, if using a valid token but trying to access another HDFS userspace, you will get the same answer; 同样,如果使用有效令牌但尝试访问另一个HDFS用户空间,您将获得相同的答案; that's because you are not authorized to access any HDFS userspace but the one owned by you: 那是因为您无权访问任何HDFS用户空间,而是您拥有的用户空间:

$ curl -X GET "http://cosmos.lab.fiware.org:14000/webhdfs/v1/user/fgalan/path/tp/the/data?op=liststatus&user.name=fgalan" -H "X-Auth-Token: qjHPUcnW6leYAqr3Xw34DWLQlja0Ix"
User token not authorized

IMPORTANT UPDATE: 重要更新:

From summer 2016, cosmos.lab.fiware.org is not workin anymore. 从2016年夏天起, cosmos.lab.fiware.org就不再适用了。 Instead, a pair of clusters, storage.cosmos.lab.fiware.org and computing.cosmos.lab.fiware.org have been setup. 相反,已经设置了一对集群, storage.cosmos.lab.fiware.orgcomputing.cosmos.lab.fiware.org Regarding the auth server of Cosmos, it currently run in computing.cosmos.lab.fiware.org , port TCP/13000. 关于Cosmos的auth服务器,它目前运行在computing.cosmos.lab.fiware.org ,端口TCP / 13000。

The right request must be: 正确的要求必须是:

curl -X POST " https://cosmos.lab.fi-ware.org:13000/cosmos-auth/v1/token " -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=password&username=user@domain.com&password=yourpassword" -k curl -X POST“ https://cosmos.lab.fi-ware.org:13000/cosmos-auth/v1/token ”-H“Content-Type:application / x-www-form-urlencoded”-d“grant_type =password&username=user@domain.com&password=yourpassword“-k

The url was incorrect, the correct is https://cosmos.lab.fi-ware.org:13000 网址不正确,正确的是https://cosmos.lab.fi-ware.org:13000

-k is for turn off certificate verification -k用于关闭证书验证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM