@@ -173,7 +173,6 @@ def create_upload_token(
173173 issued_to = login .user
174174 expires_at = issued_at + datetime .timedelta (days = 180 )
175175
176- # Create the row in the database
177176 token = models .UploadToken (
178177 comment = request .comment ,
179178 app_id = app_id ,
@@ -183,11 +182,30 @@ def create_upload_token(
183182 issued_to = issued_to .id ,
184183 expires_at = expires_at ,
185184 )
185+
186186 with get_db ("writer" ) as db :
187187 db .session .add (token )
188188 db .session .commit ()
189189 token_id = token .id
190190
191+ encoded = jwt .encode (
192+ {
193+ "jti" : f"backend_{ token_id } " ,
194+ "sub" : "build" ,
195+ "scope" : request .scopes ,
196+ "repos" : request .repos ,
197+ "prefixes" : [app_id ],
198+ "iat" : issued_at ,
199+ "exp" : expires_at ,
200+ "token_type" : "app" ,
201+ },
202+ base64 .b64decode (config .settings .flat_manager_build_secret ),
203+ algorithm = "HS256" ,
204+ )
205+
206+ if config .settings .flat_manager_build_token_prefix is not None :
207+ encoded = config .settings .flat_manager_build_token_prefix + encoded
208+
191209 if app_metadata := get_json_key (f"apps:{ app_id } " ):
192210 app_name = app_metadata ["name" ]
193211 else :
@@ -212,25 +230,6 @@ def create_upload_token(
212230
213231 worker .send_email_new .send (payload )
214232
215- # Create the JWT
216- encoded = jwt .encode (
217- {
218- "jti" : jti (token ),
219- "sub" : "build" ,
220- "scope" : request .scopes ,
221- "repos" : request .repos ,
222- "prefixes" : [app_id ],
223- "iat" : issued_at ,
224- "exp" : expires_at ,
225- "token_type" : "app" ,
226- },
227- base64 .b64decode (config .settings .flat_manager_build_secret ),
228- algorithm = "HS256" ,
229- )
230-
231- if config .settings .flat_manager_build_token_prefix is not None :
232- encoded = config .settings .flat_manager_build_token_prefix + encoded
233-
234233 return NewTokenResponse (
235234 token = encoded ,
236235 details = _token_response (token , issued_to .display_name ),
0 commit comments