コード例 #1
0
def generate_token(key, user_id):
    consumer = Consumer.fetch(key)

    if consumer is None:
        raise Exception, "Cannot generate token: invalid consumer key specified"

    issue_time = datetime.datetime.now(UTC).isoformat()
    token = hashlib.sha256(consumer.secret + user_id + issue_time).hexdigest()

    return dict(consumerKey=key,
                authToken=token,
                authTokenIssueTime=issue_time,
                authTokenTTL=consumer.ttl,
                userId=user_id)
コード例 #2
0
ファイル: auth.py プロジェクト: csillag/annotator-store
def generate_token(key, user_id):
    consumer = Consumer.fetch(key)

    if consumer is None:
        raise Exception, "Cannot generate token: invalid consumer key specified"

    issue_time = datetime.datetime.now(UTC).isoformat()
    token = hashlib.sha256(consumer.secret + user_id + issue_time).hexdigest()

    return dict(
        consumerKey=key,
        authToken=token,
        authTokenIssueTime=issue_time,
        authTokenTTL=consumer.ttl,
        userId=user_id
    )
コード例 #3
0
ファイル: auth.py プロジェクト: csillag/annotator-store
def verify_token(token, key, user_id, issue_time):
    consumer = Consumer.fetch(key)

    if consumer is None:
        return False # invalid account key

    computed_token = hashlib.sha256(consumer.secret + user_id + issue_time).hexdigest()

    if computed_token != token:
        return False # Token inauthentic: computed hash doesn't match.

    validity = iso8601.parse_date(issue_time)
    expiry = validity + datetime.timedelta(seconds=consumer.ttl)

    if validity > datetime.datetime.now(UTC):
        return False # Token not yet valid

    if expiry < datetime.datetime.now(UTC):
        return False # Token expired: issue_time + ttl > now

    return True
コード例 #4
0
def verify_token(token, key, user_id, issue_time):
    consumer = Consumer.fetch(key)

    if consumer is None:
        return False  # invalid account key

    computed_token = hashlib.sha256(consumer.secret + user_id +
                                    issue_time).hexdigest()

    if computed_token != token:
        return False  # Token inauthentic: computed hash doesn't match.

    validity = iso8601.parse_date(issue_time)
    expiry = validity + datetime.timedelta(seconds=consumer.ttl)

    if validity > datetime.datetime.now(UTC):
        return False  # Token not yet valid

    if expiry < datetime.datetime.now(UTC):
        return False  # Token expired: issue_time + ttl > now

    return True
コード例 #5
0
    def test_key(self):
        c = Consumer(key='foo')
        save(c)

        c = Consumer.fetch('foo')
        h.assert_equal(c.key, 'foo')
コード例 #6
0
    def test_key(self):
        c = Consumer(key='foo')
        save(c)

        c = Consumer.fetch('foo')
        h.assert_equal(c.key, 'foo')