catchjwt.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:catchpy 作者: nmaekawa 项目源码 文件源码
def validate_token(token_payload):
    '''check for token expiration, secret-key expiration.'''

    now = now_utc()

    # check token expiration date
    issued_at = token_payload.get('issuedAt', None)
    ttl = token_payload.get('ttl', None)
    if issued_at is None or ttl is None:
        return 'missing `issuedAt` or `ttl` in auth token'
    try:
        iat = iso8601.parse_date(issued_at)
        ttl = int(ttl)
    except iso8601.ParseError as e:
        return 'invalid `issuedAt` date format, expected iso8601. {}'.format(e)
    except ValueError:
        return 'invaild `ttl` value, expected integer'

    token_exp = iat + timedelta(seconds=ttl)
    if token_exp < now:
        return 'token has expired'

    # check for issuing at future - trying to cheat expiration?
    # taking timedrift into account
    if iat > (now + timedelta(minutes=65)):
        return 'invalid `issuedAt` in the future.'

    return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号