Prompt user to enter content curation server authentication token.
    Args: domain (str): domain to authenticate user
    Returns: token
501801
def prompt_token(domain):
    
    token = input("\nEnter content curation server token ('q' to quit): ").lower()
    if token == 'q':
        sys.exit()
    else:
        return token.strip()
949532
def show_domain(self, domain_id):
        
        json = self.request('/domains/%s' % domain_id, method='GET')
        status = json.get('status')
        if status == 'OK':
            domain_json = json.get('domain')
            domain = Domain.from_json(domain_json)
            return domain
        else:
            message = json.get('message')
            raise DOPException('[%s]: %s' % (status, message))
656341
def token(self, adata, load):
        '''
        
        '''
        try:
            token = self.loadauth.get_tok(load['token'])
        except Exception as exc:
            log.error('Exception occurred when generating auth token: %s', exc)
            yield {}
        if not token:
            log.warning('Authentication failure of type "token" occurred.')
            yield {}
        for sub_auth in adata:
            for sub_adata in adata:
                if token['eauth'] not in adata:
                    continue
            if not ((token['name'] in adata[token['eauth']]) |
                    ('*' in adata[token['eauth']])):
                continue
            yield {'sub_auth': sub_auth, 'token': token}
        yield {}
779797
def authenticate_token(self, load):
        '''
        
        '''
        token = self.get_tok(load['token'])

        # Bail if the token is empty or if the eauth type specified is not allowed
        if not token or token['eauth'] not in self.opts['external_auth']:
            log.warning('Authentication failure of type "token" occurred.')
            return False

        return token
353706
def login(self, user, passwd):
        
        def do_login(self, user, passwd, token=None):
            """
            Login function that handles CSRF protection (see `MediaWiki bug
            23076`_). Returns ``True`` on successful login.

            .. _`MediaWiki bug 23076`:
                https://bugzilla.wikimedia.org/show_bug.cgi?id=23076
            """
            data = {'action': 'login',
                    'lgname': user,
                    'lgpassword': passwd}
            if token:
                data['lgtoken'] = token
            result = self.call(data)
            if result['login']['result'] == 'Success':
                self._high_limits = None
                return True
            elif result['login']['result'] == 'NeedToken' and not token:
                return do_login(self, user, passwd, result['login']['token'])
            else:
                return False

        return do_login(self, user, passwd)
121129
def _verify_or_create_domain(self):
        

        # Get all domains registered with the user
        r = requests.get(
            url=self.server + "/domains",
            auth=(self.username, self.password),
            headers=self.headers,
            json=self.data
        )
        if r.ok:
            names = []
            d = r.json()
            rdata = d["data"]
            if rdata:
                for d in rdata:
                    names.append(d["name"])
            if self.domain in names:
                return
        else:
            print "Error querying for domains for the configured user"
            print r.status_code, r.text
            return

        print "Domain %s is not created on rhcloud. Creating.."

        d = {"id": self.domain}
        d.update(self.data)

        r = requests.post(
            url= self.server + "/domains",
            auth= (self.username, self.password),
            headers = self.headers,
            json=d
        )
        if r.ok:
            print "Domain %s successfully created.." % self.domain

        else:
            print "Error creating domain for the configured user"
            print r.status_code, r.text
            return

        return r
1245479
def authenticate(previous_token = None):
    

    # if we already have a session token, try to authenticate with it
    if previous_token != None:
        headers = server_connection.request("authenticate", {
            'session_token' : previous_token,
            'repository'    : config['repository']})[1] # Only care about headers

        if headers['status'] == 'ok':
            return previous_token

    # If the session token has expired, or if we don't have one, re-authenticate

    headers = server_connection.request("begin_auth", {'repository' : config['repository']})[1] # Only care about headers

    if headers['status'] == 'ok':
        signature = base64.b64encode(pysodium.crypto_sign_detached(headers['auth_token'].decode('utf-8'), config['private_key']))
        headers = server_connection.request("authenticate", {
            'auth_token' : headers['auth_token'],
            'signature'  : signature,
            'user'       : config['user'],
            'repository' : config['repository']})[1] # Only care about headers

        if headers['status'] == 'ok': return headers['session_token']
    raise SystemExit('Authentication failed')
829060
def authenticate(self, username=None, password=None):
        
        data = api_client.authenticate(username, password)
        if not data:
            return

        return User(
            data.get('pk'), data.get('token'), data.get('user_data')
        )
1357789
def AuthorizingClient(
    domain,
    auth,
    request_encoder,
    response_decoder,
    user_agent=None
):
    
    
    http_transport = transport.HttpTransport(
        api_url(domain),
        build_headers(auth, user_agent)
    )
    
    return client.Client(
        request_encoder,
        http_transport,
        response_decoder
    )
898059
def servertoken(self,serverURL,referer):
        
        if self._server_token is None or self._server_token_expires_on is None or \
           datetime.datetime.now() >= self._server_token_expires_on or \
           self._server_url != serverURL:
            self._server_url = serverURL
            result = self._generateForServerTokenSecurity(serverURL=serverURL,
                                                          token=self.token,
                                                          tokenUrl=self._token_url,
                                                          referer=referer)
            if 'error' in result:
                self._valid = False
                self._message = result
            else:
                self._valid = True
                self._message = "Server Token Generated"
        return self._server_token
60597
def get_token(self, client_id, target, api_type, grant_type,
                  id_token=None, refresh_token=None, scope='openid'):

        

        if id_token and refresh_token:
            raise ValueError('Only one of id_token or refresh_token '
                             'can be None')

        data = {
            'client_id': client_id,
            'grant_type': grant_type,
            'target': target,
            'scope': scope,
            'api_type': api_type,
        }

        if id_token:
            data.update({'id_token': id_token})
        elif refresh_token:
            data.update({'refresh_token': refresh_token})
        else:
            raise ValueError('Either id_token or refresh_token must '
                             'have a value')

        return self.post(
            'https://{}/delegation'.format(self.domain),
            headers={'Content-Type': 'application/json'},
            data=data
        )
470706
def authenticate(cls, request, route, server_config):
        
        if not server_config.getboolean("auth", False):
            return

        user = server_config.get("user", "").strip()
        password = server_config.get("password", "").strip()

        if len(user) == 0:
            return

        if "AUTHORIZATION" in request.headers:
            if request.headers["AUTHORIZATION"] == aiohttp.helpers.BasicAuth(user, password, "utf-8").encode():
                return

        log.error("Invalid auth. Username should %s", user)

        response = Response(request=request, route=route)
        response.set_status(401)
        response.headers["WWW-Authenticate"] = 'Basic realm="GNS3 server"'
        # Force close the keep alive. Work around a Qt issue where Qt timeout instead of handling the 401
        # this happen only for the first query send by the client.
        response.force_close()
        return response
1054756
def authenticated_get(username, password, url, verify=True):
    
    try:
        response = requests.get(url, auth=(username, password), verify=verify)
        if response.status_code == 401:
            raise BadCredentialsException(
                "Unable to authenticate user %s to %s with password provided!"
                % (username, url))
    except requests.exceptions.SSLError:
        raise CertificateException("Unable to verify certificate at %s!" % url)
    return response.content
639835
def domain_get(auth=None, **kwargs):
    '''
    
    '''
    cloud = get_operator_cloud(auth)
    kwargs = _clean_kwargs(**kwargs)
    return cloud.get_domain(**kwargs)
1244937
def get_domain_info(self, domain):
        
        url = self.API_TEMPLATE + self.DOMAIN_INFO.format(domain=domain)
        return self._get_json_from_response(url)
51332
def create_domain(self, name, body):
        
        url = '{0}/domain/{1}'.format(self.server, name)
        return self.__post(url, body)
1352511
def DomainTokensCreate(self, domain_id, amount):
        
        if self.__SenseApiCall__('/domains/{0}/tokens.json'.format(domain_id), 'POST', parameters = {"amount":amount}):
            return True
        else:
            self.__error__ = "api call unsuccessful"
            return False