Exemplo n.º 1
0
    def GetAuthHeader(self, http_method, http_url):
        """Generates the Authorization header.

    The form of the secure AuthSub Authorization header is
    Authorization: AuthSub token="token" sigalg="sigalg" data="data" sig="sig"
    and  data represents a string in the form
    data = http_method http_url timestamp nonce

    Args:
      http_method: string HTTP method i.e. operation e.g. GET, POST, PUT, etc.
      http_url: string or atom.url.Url HTTP URL to which request is made.
      
    Returns:
      dict Header to be sent with every subsequent request after authentication.
    """
        timestamp = int(math.floor(time.time()))
        nonce = '%lu' % random.randrange(1, 2**64)
        data = '%s %s %d %s' % (http_method, str(http_url), timestamp, nonce)
        sig = cryptomath.bytesToBase64(self.rsa_key.hashAndSign(data))
        header = {
            'Authorization':
            '%s"%s" data="%s" sig="%s" sigalg="rsa-sha1"' %
            (AUTHSUB_AUTH_LABEL, self.token_string, data, sig)
        }
        return header
Exemplo n.º 2
0
  def GetAuthHeader(self, http_method, http_url):
    """Generates the Authorization header.

    The form of the secure AuthSub Authorization header is
    Authorization: AuthSub token="token" sigalg="sigalg" data="data" sig="sig"
    and  data represents a string in the form
    data = http_method http_url timestamp nonce

    Args:
      http_method: string HTTP method i.e. operation e.g. GET, POST, PUT, etc.
      http_url: string or atom.url.Url HTTP URL to which request is made.
      
    Returns:
      dict Header to be sent with every subsequent request after authentication.
    """
    timestamp = int(math.floor(time.time()))
    nonce = '%lu' % random.randrange(1, 2**64)
    data = '%s %s %d %s' % (http_method, str(http_url), timestamp, nonce)
    sig = cryptomath.bytesToBase64(self.rsa_key.hashAndSign(data))
    header = {'Authorization': '%s"%s" data="%s" sig="%s" sigalg="rsa-sha1"' %
              (AUTHSUB_AUTH_LABEL, self.token_string, data, sig)}
    return header