Browse Source

issue_date as param

Guénaël Muller 6 years ago
parent
commit
d6dec5c880
1 changed files with 6 additions and 5 deletions
  1. 6 5
      tracim/tracim/lib/jitsi_meet/token.py

+ 6 - 5
tracim/tracim/lib/jitsi_meet/token.py View File

107
         self.duration = duration
107
         self.duration = duration
108
         self.context = context
108
         self.context = context
109
 
109
 
110
-    def generate(self) -> str:
110
+    def generate(self, issue_date: typing.Optional[datetime.datetime] = None) -> str:
111
         """
111
         """
112
         Generate JWT token
112
         Generate JWT token
113
         :return: JWT token as str
113
         :return: JWT token as str
114
         """
114
         """
115
-        now = datetime.datetime.utcnow()
116
-        exp = now+datetime.timedelta(seconds=self.duration)
115
+        if not issue_date:
116
+            issue_date = datetime.datetime.utcnow()
117
+        exp = issue_date+datetime.timedelta(seconds=self.duration)
117
         data = {
118
         data = {
118
             "iss": self.app_id,  # Issuer
119
             "iss": self.app_id,  # Issuer
119
             "room": self.room,  # Custom-param for jitsi_meet
120
             "room": self.room,  # Custom-param for jitsi_meet
120
             "aud": "*",  # TODO: Understood this param
121
             "aud": "*",  # TODO: Understood this param
121
             "exp": exp,  # Expiration date
122
             "exp": exp,  # Expiration date
122
-            "nbf": now,  # NotBefore
123
-            "iat": now,   # IssuedAt
123
+            "nbf": issue_date,  # NotBefore
124
+            "iat": issue_date,   # IssuedAt
124
         }
125
         }
125
         if self.context:
126
         if self.context:
126
             data['context'] = self.context.as_dict()
127
             data['context'] = self.context.as_dict()