Authenticate the given client against UAA.  The resulting token
        will be cached for reuse.
963980
def authenticate(self, client_id, client_secret, use_cache=True):
        
        # We will reuse a token for as long as we have one cached
        # and it hasn't expired.
        if use_cache:
            client = self._get_client_from_cache(client_id)
            if (client) and (not self.is_expired_token(client)):
                self.authenticated = True
                self.client = client
                return

        # Let's authenticate the client
        client = {
            'id': client_id,
            'secret': client_secret
        }

        res = self._authenticate_client(client_id, client_secret)
        client.update(res)

        expires = datetime.datetime.now() + \
                  datetime.timedelta(seconds=res['expires_in'])
        client['expires'] = expires.isoformat()

        # Cache it for repeated use until expired
        self._write_to_uaa_cache(client)

        self.client = client
        self.authenticated = True
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
1058144
def authenticated(f):
    """"""
    @wraps(f)
    def new_f(self, *args, **kwargs):
        if not self.nova_client.client.auth_token:
            self.authenticate()
        return f(self, *args, **kwargs)
    return new_f
1028598
def authenticate(self, request):
        
        auth = get_authorization_header(request).split()

        if not auth or auth[0].lower() != b'token':
            return None

        if len(auth) == 1:
            msg = _('Invalid auth token header. No credentials provided.')
            raise AuthenticationFailed(msg)
        elif len(auth) > 2:
            msg = _('Invalid auth token.')
            raise AuthenticationFailed(msg)

        try:
            token = urlsafe_b64decode(auth[1])
        except ValueError:
            msg = _('Invalid auth token.')
            raise AuthenticationFailed(msg)

        return self.authenticate_credentials(token, request)
968936
public static TrainingApi authenticate(RestClient restClient, final String apiKey) {
        return new TrainingApiImpl(restClient).withApiKey(apiKey);
    }
963178
def create_client(self, client_id, client_secret):
        
        assert self.is_admin, "Must authenticate() as admin to create client"
        return self.uaac.create_client(client_id, client_secret)
455542
def authenticate(self, api_key):
        """"""
        self._api_key = api_key

        # Attach auth to session.
        self._session.auth = ('', self._api_key)

        return self._verify_api_key()
1280919
public GitlabHTTPRequestor authenticate(String token, TokenType type, AuthMethod method) {
        this.apiToken = token;
        this.tokenType = type;
        this.authMethod = method;
        return this;
    }
988809
def verify_token(self, token):
        '''
        
        '''
        try:
            result = self.resolver.get_token(token)
        except Exception as ex:
            raise EauthAuthenticationError(
                "Token validation failed with {0}.".format(repr(ex)))

        return result
93385
def authenticate_with_auth_code(authorization_code, redirect_uri)
      response = @oauth_connection.post do |req|
        req.url '/oauth/token'
        req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
        req.body = {:grant_type => 'authorization_code', :client_id => api_key, :client_secret => api_secret, :code => authorization_code, :redirect_uri => redirect_uri}
      end

      @oauth_token = OAuthToken.new(response.body)
      configure_oauth
      @oauth_token
    end
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
    )
415768
def _authenticate(self):
        
        for authenticator in self.authenticators:
            try:
                user_auth_tuple = authenticator.authenticate(self)
            except exceptions.APIException:
                self._not_authenticated()
                raise

            if user_auth_tuple is not None:
                self._authenticator = authenticator
                self.user, self.auth = user_auth_tuple
                return

        self._not_authenticated()
755825
def authorize(credentials, client_class=Client):
    
    client = client_class(auth=credentials)
    client.login()
    return client
408917
def authenticate!
      return unless @authenticated.nil?

      id, access_token = @params.retrieve_id, @params.retrieve_access_token
      @key_for_access_token = @scope.key_for_access_token(id, access_token)

      if access_token && !access_token.empty?
        ApiWarden.redis { |conn| @value_for_access_token = conn.get(@key_for_access_token) }
      end

      unless @value_for_access_token
        @authenticated = false
        raise AuthenticationError        
      end

      @authenticated = true
      @id = id
      @access_token = access_token
      self
    end
1077204
def __authenticate(self):
        
        if self.api_token:
            # verify current API token
            check_auth_uri = self.uri.split('/api/v1')[0] + '/check_token'
            req = self.request(check_auth_uri)
            try:
                ping = req.get().json()
            except Exception as exc:
                if str(exc).startswith('User not authenticated'):
                    self.api_token = None
            else:
                if self.email == ping['hello']:
                    return
                print "Authentication failed"
                sys.exit(1)

        auth_uri = self.uri.split('/api/v1')[0] + '/auth'
        payload = {
            'email': self.email,
            'password': self.password,
            'org_id': self.org_name
        }
        data = json.dumps(payload)
        req = self.request(auth_uri, data=data)
        response = req.post().json()
        token = response.get('mist_api_token', None)
        if token:
            # backwards compatibility with old Authentication system
            self.api_token = "mist_1 %s:%s" % (self.email, token)
        else:
            self.api_token = response.get('token', None)
561721
def authenticate(self):
        
        basic_auth = request.authorization
        is_valid = False
        user = None
        if basic_auth:
            is_valid, user = self.check_basic_auth(
                basic_auth.username, basic_auth.password
            )
        else:  # Try token auth
            token = request.headers.get('Authorization', None)
            param_token = request.args.get('access_token')
            if token or param_token:
                if token:
                    # slice the 'token ' piece of the header (following
                    # github style):
                    token = token[6:]
                else:
                    # Grab it from query dict instead
                    token = param_token
                log.debug('Received token: %s', token)

                is_valid, user = self.check_token_auth(token)
        return (is_valid, user)
539725
def authenticate_account(self, authc_token):
        
        try:
            identifier = authc_token.identifier
        except AttributeError:
            msg = 'Failed to obtain authc_token.identifiers'
            raise AttributeError(msg)

        tc = authc_token.__class__
        try:
            verifier = self.token_resolver[tc]
        except KeyError:
            raise TypeError('realm does not support token type: ', tc.__name__)

        account = self.get_authentication_info(identifier)

        try:
            if account.get('account_locked'):
                msg = "Account Locked:  {0} locked at: {1}".\
                    format(account['account_id'], account['account_locked'])
                raise LockedAccountException(msg)
        except (AttributeError, TypeError):
            if not account:
                msg = "Could not obtain account credentials for: " + str(identifier)
                raise AccountException(msg)

        self.assert_credentials_match(verifier, authc_token, account)

        return account