# xivo-auth-client

A python library to connect to xivo-auth. HTTPS is used by default. Certificates are verified by default: if you want to
omit the check or use a different CA bundle, use the verify_certificate argument when instantiating the client.

Usage:

```python
from xivo_auth_client import Client

c = Client('localhost', username='alice', password='alice')

token_data = c.token.new('xivo_user', expiration=3600)  # Creates a new token expiring in 3600 seconds

token_data
{u'expires_at': u'2015-06-04T09:49:30.449625',
 u'issued_at': u'2015-06-04T08:49:30.449607',
 u'token': u'3d95d849-94e5-fc72-4ff8-93b597e6acf6',
 u'auth_id': u'5cdff4a3-24a3-494f-8d32-9c8695e868f9',
 u'xivo_user_uuid': u'5cdff4a3-24a3-494f-8d32-9c8695e868f9',
 u'acls': [u'dird']}

c.token.is_valid(token_data['token'])
True

c.token.get(token_data['token'])
{u'expires_at': u'2015-06-04T09:49:30.449625',
 u'issued_at': u'2015-06-04T08:49:30.449607',
 u'token': u'3d95d849-94e5-fc72-4ff8-93b597e6acf6',
 u'auth_id': u'5cdff4a3-24a3-494f-8d32-9c8695e868f9',
 u'xivo_user_uuid': u'5cdff4a3-24a3-494f-8d32-9c8695e868f9',
 u'acls': [u'dird']}

c.token.get(token_data['token'], required_acls='foobar')  # 403

c.token.is_valid(token_data['token'], required_acl='foobar')
False

c.token.revoke(token_data['token'])

c.token.is_valid(token_data['token'])
False

c.backends.list()
['xivo_user']
```

To use a given certificate file

```python
from xivo_auth_client import Client

c = Client('localhost', username='alice', password='alice', verify_certificate='</path/to/trusted/certificate>')

token_data = c.token.new('xivo_user')
```

## Running integration tests

The tests will be launced in docker.

But first you need to build the environment (dockers) needed for the integration test.

You need Docker installed.

1. First install the requirements :

```bash
cd integration_tests
```

1. Then build the test setup:

```bash
make test-setup
```

1. And finally run the test

```bash
make test
```

1. You can clean everything with

```bash
make distclean
```

## SSL

generate an adequate certificate for 10 years

```sh
openssl req -x509 -sha256 -nodes -days 3650 -newkey rsa:2048 -config openssl.cfg -keyout server.key -out server.crt
```

verify validity

```sh
openssl x509 -in server.crt -noout -text
```
