Obtaining an authentication token from keystone in the horizon

I want to get the auth token from a trace using the horizon, and then I want to pass this authentication token to my code.

I do not know how to get this, please help me.

I read many articles and blogs, but I can not find the answer. Please just point me in the right direction.

+4
source share
6 answers

The easiest way is to use the Rest client to log in and just take the token from the response. I like the Firefox RESTClient add-in, but you can use any client you want.

  • Send a request to the Openstack Identity URL:

    POST keystone_ip:port/version/tokens
    

    (, 127.0.0.1:5000/v2.0/tokens)

    :

    Content-Type: application/json
    

    :

    {
        "auth": {
            "tenantName": "enter_your_tenantname",
            "passwordCredentials": {
                "username": "enter_your_username",
                "password": "enter_your_password"
            }
        }
    }
    

    . , URL- () Horizon API.

  • :

    {
        "token": {
            "issued_at": "2014-02-25T08:34:56.068363",
            "expires": "2014-02-26T08:34:55Z",
            "id": "529e3a0e1c375j498315c71d08134837"
        }
    }
    
  • . , , :

    GET compute_endpoint_ip:port/v2/tenant_id/servers
    

    :

    X-Auth-Token: 529e3a0e1c375j498315c71d08134837
    Content-Type: application/json
    
+6

python-keystoneclient. , ,

 username='admin'
 password='1234'
 tenant_name='admin'
 auth_url='http://127.0.0.1:5000/v2.0'
 keystone = client.Client(username=username, password=password, tenant_name=tenant_name, auth_url=auth_url)

. auth_ref ( ) , , , .

token_dict = keystone.auth_ref

, token_dict - , .

+2

node, Keystone. vi/etc/keystone/keystone.conf

, admin_token. :

admin_token = 05131394ad6b49c56f217

. python:

>>> from keystoneclient.v2_0.client as ksclient
>>> keystone = ksclient.Client(auth_url="http://service-stack.linxsol.com:35357/v2.0", username="admin", password="123456", tenant_name="admin")

, auth_url, * , * tenant_name . api:

keystone.tenants.list()
keystone.users.list()
keystone.roles.list()

dir (keystone), .

:

auth_ref = keystone.auth_ref or token = ksclient.get_raw_token_from_identity_service(auth_url="http://service-stack.linxsol.com:35357/v2.0", username="admin", password="123456", tenant_name="admin")

, , .

, , python-keystoneclient.

, .

+1

, :

import keystoneclient.v2_0.client as ksclient
# authenticate with keystone to get a token

keystone = ksclient.Client(auth_url="http://192.168.10.5:35357/v2.0",
                           username="admin",
                           password="admin",
                           tenant_name="admin")


token = keystone.auth_ref['token']['id']

# use this token for whatever other services you are accessing.
print token
+1

python-keystoneclient.

, , , URL- URL- , ,

from keystoneclient.v2_0 import client
username='admin'
password='1234'
tenant_name='demo'
auth_url='http://10.0.2.15:5000/v2.0' # Or auth_url='http://192.168.206.133:5000/v2.0'

If your username, password or tenant_name is incorrect, you will get keystoneclient.openstack.common.apiclient.exceptions.Unauthorized: Invalid user / password  keystone = client.Client (username = username, password = password, tenant_name = tenant_name, auth_url = auth_url) token_dict = keystone.auth_ref token_dict

0
source

All Articles