Verify 2-legged oauth request. Parameters accepted as
        values in the "Authorization" header, as a GET request parameter,
        or in a POST body.
428797
def is_authenticated(self, request, **kwargs):
        
        log.info("OAuth20Authentication")
        try:
            key = request.GET.get('oauth_consumer_key')
            if not key:
                for header in ['Authorization', 'HTTP_AUTHORIZATION']:
                    auth_header_value = request.META.get(header)
                    if auth_header_value:
                        key = auth_header_value.split(' ', 1)[1]
                        break
            if not key and request.method == 'POST':
                if request.META.get('CONTENT_TYPE') == 'application/json':
                    decoded_body = request.body.decode('utf8')
                    key = json.loads(decoded_body)['oauth_consumer_key']
            if not key:
                log.info('OAuth20Authentication. No consumer_key found.')
                return None
            """
            If verify_access_token() does not pass, it will raise an error
            """
            token = self.verify_access_token(key, request, **kwargs)

            # If OAuth authentication is successful, set the request user to
            # the token user for authorization
            request.user = token.user

            # If OAuth authentication is successful, set oauth_consumer_key on
            # request in case we need it later
            request.META['oauth_consumer_key'] = key
            return True
        except KeyError:
            log.exception("Error in OAuth20Authentication.")
            request.user = AnonymousUser()
            return False
        except Exception:
            log.exception("Error in OAuth20Authentication.")
            return False
1277285
def verify_request(self, uri, http_method='GET', body=None, headers=None,
                       scopes=None):
        """"""
        request = Request(uri, http_method, body, headers)
        request.token_type = self.find_token_type(request)
        request.scopes = scopes
        token_type_handler = self.tokens.get(request.token_type,
                                             self.default_token_type_handler)
        log.debug('Dispatching token_type %s request to %r.',
                  request.token_type, token_type_handler)
        return token_type_handler.validate_request(request), request
1086157
function(params, stateData) {
          // Handle an error response from the OAuth server
          if (params.error) {
            authLogger.log("RedirectLoginService.finish(), error", params.error, params.error_description, params.error_uri);
            return $q.reject({
              error: params.error,
              error_description: params.error_description,
              error_uri: params.error_uri
            });
          }

          // Handle an access_token fragment response
          if (params.access_token) {
            return $q.when({
              token: params.access_token,
              ttl: params.expires_in,
              then: stateData.then,
              verified: stateData.verified
            });
          }

          // No token and no error is invalid
          return $q.reject({
            error: "invalid_request",
            error_description: "No API token returned"
          });
        }
1141658
def __verify_auth_params(username, password, access_token):
        """"""

        if all(v is not None for v in [username, password, access_token]):
            raise ValueError('Cannot supply a username/password and a access token')

        if (username is None or password is None) and access_token is None:
            raise ValueError('Must supply a username/password or access token')
1021366
def validate_authorization_request(self, uri, http_method='GET', body=None,
                                       headers=None):
        """"""
        request = Request(
            uri, http_method=http_method, body=body, headers=headers)

        request.scopes = utils.scope_to_list(request.scope)

        response_type_handler = self.response_types.get(
            request.response_type, self.default_response_type_handler)
        return response_type_handler.validate_authorization_request(request)
959263
def authenticate!
      response = connection.post '/services/oauth2/token' do |req|
        req.body = encode_www_form(params)
      end

      if response.status >= 500
        raise Restforce::ServerError, error_message(response)
      elsif response.status != 200
        raise Restforce::AuthenticationError, error_message(response)
      end

      @options[:instance_url] = response.body['instance_url']
      @options[:oauth_token]  = response.body['access_token']

      @options[:authentication_callback]&.call(response.body)

      response.body
    end
281165
def make_request(self, url, params, auth=None):
        
        req = urllib2.Request(url + urllib.urlencode(params))

        if auth:
            req.add_header('AUTHORIZATION', 'Basic ' + auth)

        return urllib2.urlopen(req)
464016
def _validate_auth(self, path, obj, _):
        
        errs = []

        if obj.type == 'apiKey':
            if not obj.passAs:
                errs.append('need "passAs" for apiKey')
            if not obj.keyname:
                errs.append('need "keyname" for apiKey')

        elif obj.type == 'oauth2':
            if not obj.grantTypes:
                errs.append('need "grantTypes" for oauth2')

        return path, obj.__class__.__name__, errs
235568
def post(self, url, postParameters=None, urlParameters=None):
        
        if urlParameters:
            url = url + "?" + self.getParameters(urlParameters)
        headers = {'Authorization':'GoogleLogin auth=%s' % self.auth_token,
                    'Content-Type': 'application/x-www-form-urlencoded'
                    }
        postString = self.postParameters(postParameters)
        req = requests.post(url, data=postString, headers=headers)
        return req.text
1203475
def verify_oauth_token_and_set_current_user():
    
    for func in oauth2._before_request_funcs:
        func()

    if not hasattr(request, 'oauth') or not request.oauth:
        scopes = []
        try:
            valid, req = oauth2.verify_request(scopes)
        except ValueError:
            abort(400, 'Error trying to decode a non urlencoded string.')

        for func in oauth2._after_request_funcs:
            valid, req = func(valid, req)

        if valid:
            request.oauth = req
1118552
private String getAuthorizationHeaderValue(HttpRequest request, byte[] body) {
		return signingUtils.buildAuthorizationHeaderValue(request, body, oauth1Credentials);
	}
1256230
def _authenticate_user(self, user, password):
        
        headers = self._get_headers()
        params = {
                'username': user,
                'password': password,
                'grant_type': 'password',
                }
        uri = self.uri + '/oauth/token'

        logging.debug("URI=" + str(uri))
        logging.debug("HEADERS=" + str(headers))
        logging.debug("BODY=" + str(params))

        response = requests.post(uri, headers=headers, params=params)
        if response.status_code == 200:
            logging.debug("RESPONSE=" + str(response.json()))
            return response.json()
        else:
            logging.warning("Failed to authenticate %s" % (user))
            response.raise_for_status()
333553
function oAuthRequest($url, $method, $parameters, $multi = false) {

    if (strrpos($url, 'http://') !== 0 && strrpos($url, 'https://') !== 0) {
      $url = "{$this->host}{$url}.{$this->format}";
  }

  switch ($method) {
    case 'GET':
      $url = $url . '?' . http_build_query($parameters);
      return $this->http($url, 'GET');
    default:
      $headers = array();
      if (!$multi && (is_array($parameters) || is_object($parameters)) ) {
        $body = http_build_query($parameters);
      } else {
        $body = self::build_http_query_multi($parameters);
        $headers[] = "Content-Type: multipart/form-data; boundary=" . self::$boundary;
      }
      return $this->http($url, $method, $body, $headers);
  }
  }
111275
def _do_request(self, method, endpoint, data=None):
        
        # No token - authorize
        if self.token is None:
            self._do_authorize()

        r = requests.request(
            method,
            "{0}{1}".format(self.base_url, endpoint),
            headers={
                "Authorization": "Bearer {0}".format(self.token),
                "Content-Type": "application/json"
            },
            json=data,
            verify=self.verify_certificate,
            timeout=self.timeout
        )

        if r.status_code == 401:
            self._do_authorize()
            r = requests.request(
                method,
                "{0}{1}".format(self.base_url, endpoint),
                headers={
                    "Authorization": "Bearer {0}".format(self.token),
                    "Content-Type": "application/json"
                },
                json=data,
                verify=self.verify_certificate,
                timeout=self.timeout
            )

        return r
323501
def receive_verify_post(self, post_params):
        
        if isinstance(post_params,  dict):
            required_params = ['action', 'email', 'send_id', 'sig']
            if not self.check_for_valid_postback_actions(required_params, post_params):
                return False
        else:
            return False

        if post_params['action'] != 'verify':
            return False

        sig = post_params['sig']
        post_params = post_params.copy()
        del post_params['sig']

        if sig != get_signature_hash(post_params, self.secret):
            return False

        send_response = self.get_send(post_params['send_id'])

        try:
            send_body = send_response.get_body()
            send_json = json.loads(send_body)
            if 'email' not in send_body:
                return False
            if send_json['email'] != post_params['email']:
                return False
        except ValueError:
            return False

        return True
57411
def is_valid(self):
        """"""

        try:
            request = self.get_oauth_request()
            client = self.get_client(request)
            params = self._server.verify_request(request, client, None)
        except Exception as e:
            raise e

        return client
787018
def request(path, params = {})
      if oauth_configured?
        oauth_request(path, params)
      else
        http_request(path, params)
      end
    end