Fix timestamps computing in tokens

The timestamp of timezone-aware datetimes was offset by the value of their timezone.
This commit is contained in:
Brice Gelineau 2016-11-30 15:22:58 +01:00
parent 11ef97fdbb
commit 975eb0163f
3 changed files with 40 additions and 7 deletions

View file

@ -1,5 +1,4 @@
from datetime import timedelta
import time
import uuid
from Cryptodome.PublicKey.RSA import importKey
@ -9,7 +8,7 @@ from jwkest.jwk import SYMKey
from jwkest.jws import JWS
from jwkest.jwt import JWT
from oidc_provider.lib.utils.common import get_issuer
from oidc_provider.lib.utils.common import get_issuer, to_timestamp
from oidc_provider.models import (
Code,
RSAKey,
@ -30,10 +29,10 @@ def create_id_token(user, aud, nonce='', at_hash='', request=None, scope=[]):
# Convert datetimes into timestamps.
now = timezone.now()
iat_time = int(time.mktime(now.timetuple()))
exp_time = int(time.mktime((now + timedelta(seconds=expires_in)).timetuple()))
iat_time = to_timestamp(now)
exp_time = to_timestamp(now + timedelta(seconds=expires_in))
user_auth_time = user.last_login or user.date_joined
auth_time = int(time.mktime(user_auth_time.timetuple()))
auth_time = to_timestamp(user_auth_time)
dic = {
'iss': get_issuer(request=request),