예제 #1
0
  def cleanupNonces(self):
    """Remove expired nonces from the store.

    Discards any nonce from storage that is old enough that its
    timestamp would not pass L{useNonce}.

    This method is not called in the normal operation of the
    library.  It provides a way for store admins to keep
    their storage from filling up with expired data.

    @return: the number of nonces expired.
    @returntype: int
    """
    query = UsedNonce.gql('WHERE timestamp < :1', self._expiration_datetime())
    return self._cleanup_batch(query)
예제 #2
0
  def useNonce(self, server_url, timestamp, salt):
    """Called when using a nonce.

    This method should return C{True} if the nonce has not been
    used before, and store it for a while to make sure nobody
    tries to use the same value again.  If the nonce has already
    been used or the timestamp is not current, return C{False}.

    You may use L{openid.store.nonce.SKEW} for your timestamp window.

    @change: In earlier versions, round-trip nonces were used and
       a nonce was only valid if it had been previously stored
       with C{storeNonce}.  Version 2.0 uses one-way nonces,
       requiring a different implementation here that does not
       depend on a C{storeNonce} call.  (C{storeNonce} is no
       longer part of the interface.)

    @param server_url: The URL of the server from which the nonce
        originated.

    @type server_url: C{str}

    @param timestamp: The time that the nonce was created (to the
        nearest second), in seconds since January 1 1970 UTC.
    @type timestamp: C{int}

    @param salt: A random string that makes two nonces from the
        same server issued during the same second unique.
    @type salt: str

    @return: Whether or not the nonce was valid.

    @rtype: C{bool}
    """
    query = UsedNonce.gql(
      'WHERE server_url = :1 AND salt = :2 AND timestamp >= :3',
      server_url, salt, self._expiration_datetime())
    return query.fetch(1) == []