Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting auth token from keystone in horizon

I want to get the auth token from keystone using horizon and then wants to pass that auth token to my backed code.

i don't know how to get this, please help me out.

I read many articles and blogs blogs but i am not able to find the answer. Please just point me into the right direction.

like image 342
Nikunj Aggarwal Avatar asked Nov 17 '13 17:11

Nikunj Aggarwal


2 Answers

Easiest is to use a Rest client to login and just take the token from the response. I like the Firefox RESTClient add-on but you can use any client you want.

  • Post a request to the Openstack Identity URL:

    POST keystone_ip:port/version/tokens
    

    (e.g. 127.0.0.1:5000/v2.0/tokens)

    with header:

    Content-Type: application/json
    

    and body:

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

    Note: If you're not sure what is the correct identity (keystone) URL you can log in manually to Horizon and look for a list of API endpoints.

  • The response body will include something like this:

    {
        "token": {
            "issued_at": "2014-02-25T08:34:56.068363",
            "expires": "2014-02-26T08:34:55Z",
            "id": "529e3a0e1c375j498315c71d08134837"
        }
    }
    
  • Use the returned token id as a header in new rest calls. For example, to get a list of servers use request:

    GET compute_endpoint_ip:port/v2/tenant_id/servers
    

    with Headers:

    X-Auth-Token: 529e3a0e1c375j498315c71d08134837
    Content-Type: application/json
    
like image 85
Noa Kuperberg Avatar answered Oct 07 '22 09:10

Noa Kuperberg


As an example of how to get at it:

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
like image 43
Mark D Avatar answered Oct 07 '22 11:10

Mark D