'Obtains a token from the authentication service
:param user_id: user id
:param username: user name
:param user_domain_id: the user domain id
:param user_domain_name: the user domain name
:param project_domain_id: the project domain id
:param project_domain_name: the project domain name
:param domain_id: a domain id to scope to
:param domain_name: a domain name to scope to
:param project_id: a project id to scope to
:param project_name: a project name to scope to
:param token: a token to re-scope.
Accepts different combinations of credentials.
Sample sample valid combinations:
- token
- token, project_name, project_domain_id
- user_id, password
- username, password, user_domain_id
- username, password, project_name, user_domain_id, project_domain_id
Validation is left to the server side.'

def auth(self, user_id=None, username=None, password=None, project_id=None, project_name=None, user_domain_id=None, user_domain_name=None, project_domain_id=None, project_domain_name=None, domain_id=None, domain_name=None, token=None):

    creds = {'auth': {'identity': {'methods': []}}}
    id_obj = creds['auth']['identity']
    if token:
        id_obj['methods'].append('token')
        id_obj['token'] = {'id': token}
    if ((user_id or username) and password):
        id_obj['methods'].append('password')
        id_obj['password'] = {'user': {'password': password}}
        if user_id:
            id_obj['password']['user']['id'] = user_id
        else:
            id_obj['password']['user']['name'] = username
        _domain = None
        if (user_domain_id is not None):
            _domain = dict(id=user_domain_id)
        elif (user_domain_name is not None):
            _domain = dict(name=user_domain_name)
        if _domain:
            id_obj['password']['user']['domain'] = _domain
    if (project_id or project_name):
        _project = dict()
        if project_id:
            _project['id'] = project_id
        elif project_name:
            _project['name'] = project_name
        if (project_domain_id is not None):
            _project['domain'] = {'id': project_domain_id}
        elif (project_domain_name is not None):
            _project['domain'] = {'name': project_domain_name}
        creds['auth']['scope'] = dict(project=_project)
    elif domain_id:
        creds['auth']['scope'] = dict(domain={'id': domain_id})
    elif domain_name:
        creds['auth']['scope'] = dict(domain={'name': domain_name})
    body = json.dumps(creds, sort_keys=True)
    (resp, body) = self.post(self.auth_url, body=body)
    self.expected_success(201, resp.status)
    return rest_client.ResponseBody(resp, body)
