如何在keystoneclient v3中获取令牌ID

时间:2016-09-07 13:50:23

标签: openstack keystone

过去,我使用此命令在kystoneclient v2中获得了令牌ID:

d2

但是当我们转移到keystone客户端v3时,我只是尝试使用上面的命令。但我总是得到一个错误。 请你告诉我如何获得令牌ID。

3 个答案:

答案 0 :(得分:1)

在keystone客户端v3中,身份验证响应会在其标头中返回令牌ID,而不是在名为“X-Subject-Token”的响应正文中返回。

您可以参考此处的更改:

https://developer.openstack.org/api-ref/identity/v3/index.html?expanded=list-endpoints-detail,create-credential-detail,validate-and-show-information-for-token-detail,password-authentication-with-unscoped-authorization-detail

我试图通过Perl获取令牌:

my $res = $agent->post(
    $self->{auth_url} . "/auth/tokens",
    content_type => 'application/json',
    content      => to_json($authKeystone)
);
my $headerData = $res->{_headers};
my $tokenId = $headerData->{'x-subject-token'};

有效!

答案 1 :(得分:1)

  

keystone.auth_ref [ '的auth_token']

或使用curl如下:

  

curl -sd'{“auth”:{“passwordCredentials”:{“username”:“admin”,   “password”:“mysecret”}}}'-H“内容类型:application / json”   http://192.168.131.129:5000/v2.0/tokens | python -m json.tool

答案 2 :(得分:0)

from keystoneauth1.identity import v3
from keystoneauth1 import session


auth = v3.Password(auth_url='http://172.16.50.247:5000/v3',
                   username='admin',
                   password='dawncreat',
                   project_name='admin',
                   user_domain_id='default',
                   project_domain_id='default')
sess = session.Session(auth=auth)
token = sess.get_token()