'Handles the various `request for token and service end point(s)` calls.
There are various formats to support the various auth servers in the
past. Examples::
GET <auth-prefix>/v1/<act>/auth
X-Auth-User: <act>:<usr>  or  X-Storage-User: <usr>
X-Auth-Key: <key>         or  X-Storage-Pass: <key>
GET <auth-prefix>/auth
X-Auth-User: <act>:<usr>  or  X-Storage-User: <act>:<usr>
X-Auth-Key: <key>         or  X-Storage-Pass: <key>
GET <auth-prefix>/v1.0
X-Auth-User: <act>:<usr>  or  X-Storage-User: <act>:<usr>
X-Auth-Key: <key>         or  X-Storage-Pass: <key>
On successful authentication, the response will have X-Auth-Token and
X-Storage-Token set to the token to use with Swift and X-Storage-URL
set to the URL to the default Swift cluster to use.
:param req: The swob.Request to process.
:returns: swob.Response, 2xx on success with data set as explained
above.'

def handle_get_token(self, req):

    try:
        pathsegs = split_path(req.path_info, 1, 3, True)
    except ValueError:
        self.logger.increment('errors')
        return HTTPNotFound(request=req)
    if ((pathsegs[0] == 'v1') and (pathsegs[2] == 'auth')):
        account = pathsegs[1]
        user = req.headers.get('x-storage-user')
        if (not user):
            user = req.headers.get('x-auth-user')
            if ((not user) or (':' not in user)):
                self.logger.increment('token_denied')
                auth = ('Swift    realm="%s"' % account)
                return HTTPUnauthorized(request=req, headers={'Www-Authenticate': auth})
            (account2, user) = user.split(':', 1)
            if (account != account2):
                self.logger.increment('token_denied')
                auth = ('Swift    realm="%s"' % account)
                return HTTPUnauthorized(request=req, headers={'Www-Authenticate': auth})
        key = req.headers.get('x-storage-pass')
        if (not key):
            key = req.headers.get('x-auth-key')
    elif (pathsegs[0] in ('auth', 'v1.0')):
        user = req.headers.get('x-auth-user')
        if (not user):
            user = req.headers.get('x-storage-user')
        if ((not user) or (':' not in user)):
            self.logger.increment('token_denied')
            auth = 'Swift    realm="unknown"'
            return HTTPUnauthorized(request=req, headers={'Www-Authenticate': auth})
        (account, user) = user.split(':', 1)
        key = req.headers.get('x-auth-key')
        if (not key):
            key = req.headers.get('x-storage-pass')
    else:
        return HTTPBadRequest(request=req)
    if (not all((account, user, key))):
        self.logger.increment('token_denied')
        realm = (account or 'unknown')
        return HTTPUnauthorized(request=req, headers={'Www-Authenticate': ('Swift    realm="%s"' % realm)})
    account_user = ((account + ':') + user)
    if (account_user not in self.users):
        self.logger.increment('token_denied')
        auth = ('Swift    realm="%s"' % account)
        return HTTPUnauthorized(request=req, headers={'Www-Authenticate': auth})
    if (self.users[account_user]['key'] != key):
        self.logger.increment('token_denied')
        auth = 'Swift    realm="unknown"'
        return HTTPUnauthorized(request=req, headers={'Www-Authenticate': auth})
    account_id = self.users[account_user]['url'].rsplit('/', 1)[(-1)]
    memcache_client = cache_from_env(req.environ)
    if (not memcache_client):
        raise Exception('Memcache    required')
    token = None
    memcache_user_key = ('%s/user/%s' % (self.reseller_prefix, account_user))
    candidate_token = memcache_client.get(memcache_user_key)
    if candidate_token:
        memcache_token_key = ('%s/token/%s' % (self.reseller_prefix, candidate_token))
        cached_auth_data = memcache_client.get(memcache_token_key)
        if cached_auth_data:
            (expires, old_groups) = cached_auth_data
            old_groups = old_groups.split(',')
            new_groups = self._get_user_groups(account, account_user, account_id)
            if ((expires > time()) and (set(old_groups) == set(new_groups.split(',')))):
                token = candidate_token
    if (not token):
        token = ('%stk%s' % (self.reseller_prefix, uuid4().hex))
        expires = (time() + self.token_life)
        groups = self._get_user_groups(account, account_user, account_id)
        memcache_token_key = ('%s/token/%s' % (self.reseller_prefix, token))
        memcache_client.set(memcache_token_key, (expires, groups), time=float((expires - time())))
        memcache_user_key = ('%s/user/%s' % (self.reseller_prefix, account_user))
        memcache_client.set(memcache_user_key, token, time=float((expires - time())))
    resp = Response(request=req, headers={'x-auth-token': token, 'x-storage-token': token, 'x-auth-token-expires': str(int((expires - time())))})
    url = self.users[account_user]['url'].replace('$HOST', resp.host_url)
    if (self.storage_url_scheme != 'default'):
        url = ((self.storage_url_scheme + ':') + url.split(':', 1)[1])
    resp.headers['x-storage-url'] = url
    return resp
