# REST API authentication for hub

**URL:** <https://forums.docker.com/t/rest-api-authentication-for-hub/2308>\
**Category:** Docker Hub\
**Created:** [July 9, 2015, 12:04pm UTC](https://forums.docker.com/t/rest-api-authentication-for-hub/2308 "2015-07-09T12:04:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andresriancho](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/andresriancho/32/1311_2.png) [@andresriancho](https://forums.docker.com/u/andresriancho)\
**Post date:** [July 9, 2015, 12:04pm UTC](https://forums.docker.com/t/rest-api-authentication-for-hub/2308/1 "2015-07-09T12:04:37Z")

</div>

I’m trying to improve [docker-tag-naming](https://github.com/andresriancho/docker-tag-naming/) to support private repositories. To do this I need to be able to authenticate and then retrieve image tags.

The docs at [https://docs.docker.com/reference/api/docker-io\_api/](https://docs.docker.com/reference/api/docker-io_api/) are not clear on how I should generate a token to access a private repo information, could someone help me it out?

Extra brownie points if you answer only with `curl` commands 👍

---

<div class="post-metadata">

**Author:** ![andresriancho](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/andresriancho/32/1311_2.png) [@andresriancho](https://forums.docker.com/u/andresriancho)\
**Post date:** [July 9, 2015, 12:31pm UTC](https://forums.docker.com/t/rest-api-authentication-for-hub/2308/2 "2015-07-09T12:31:52Z")

</div>

DONE!

```python
import requests
import json

index_endpoint = 'https://registry.hub.docker.com'
namespace = 'andresriancho'
repos = 'private'
user_credentials = ('andresriancho', 'long-password-not-shown-in-forums')

resp = requests.get('{0}/v1/repositories/{1}/{2}/images'.format(index_endpoint, namespace, repos),
                    auth=tuple(user_credentials),
                    headers={'X-Docker-Token': 'true'})

token = resp.headers.get('x-docker-token')
endpoint = resp.headers.get('x-docker-endpoints')

resp = requests.get('https://{0}/v1/repositories/{1}/{2}/tags'.format(endpoint, namespace, repos),
                    headers={'Authorization': 'Token ' + token})

print(json.dumps(resp.json(), indent=4))

```

---

<div class="post-metadata">

**Author:** ![jessemortenson](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/jessemortenson/32/12935_2.png) [@jessemortenson](https://forums.docker.com/u/jessemortenson)\
**Post date:** [August 8, 2016, 11:01pm UTC](https://forums.docker.com/t/rest-api-authentication-for-hub/2308/3 "2016-08-08T23:01:01Z")

</div>

Cool script! Problem: it only retrieves 6 of the tags from my private repository. Have you run into this at all? I cannot figure out why.

I have the same problem with your docker-tag-naming library. Running the script above connects and retrieves proper tags for the image I specify, but appears limited to 6 results. It seems to have some kind of pagination or limit going on, but I cannot find any reference to pagination parameters in the v1 API documentation.
