@@ -318,6 +318,52 @@ func (s *RPC) initiateAuth(
318
318
return authProvider .InitiateAuth (ctx , verifCtx , intent .Data .Verifier , intent .Signers ()[0 ], storeSessFn )
319
319
}
320
320
321
+ func (s * RPC ) openScopedSession (
322
+ ctx context.Context , dbSess * data.Session , intent * intents.IntentTyped [intents.IntentDataOpenScopedSession ],
323
+ ) (* proto.IntentResponse , error ) {
324
+ tnt := tenant .FromContext (ctx )
325
+ att := attestation .FromContext (ctx )
326
+ sessData , _ , err := crypto .DecryptData [* proto.SessionData ](ctx , dbSess .EncryptedKey , dbSess .Ciphertext , tnt .KMSKeys )
327
+ if err != nil {
328
+ return nil , fmt .Errorf ("decrypting session data: %w" , err )
329
+ }
330
+
331
+ scopedSessData := & proto.SessionData {
332
+ ID : intent .Data .ScopedSessionID ,
333
+ ProjectID : sessData .ProjectID ,
334
+ UserID : sessData .UserID ,
335
+ Identity : sessData .Identity ,
336
+ CreatedAt : time .Now (),
337
+ ExpiresAt : sessData .ExpiresAt ,
338
+ }
339
+ encryptedKey , algorithm , ciphertext , err := crypto .EncryptData (ctx , att , tnt .KMSKeys [0 ], scopedSessData )
340
+ if err != nil {
341
+ return nil , fmt .Errorf ("encrypting scoped session data: %w" , err )
342
+ }
343
+
344
+ scopedSess := & data.Session {
345
+ ID : intent .Data .ScopedSessionID ,
346
+ ProjectID : sessData .ProjectID ,
347
+ UserID : sessData .UserID ,
348
+ Identity : sessData .Identity ,
349
+ EncryptedKey : encryptedKey ,
350
+ Algorithm : algorithm ,
351
+ Ciphertext : ciphertext ,
352
+ CreatedAt : scopedSessData .CreatedAt ,
353
+ RefreshedAt : scopedSessData .CreatedAt ,
354
+ }
355
+ if err := s .Sessions .Put (ctx , scopedSess ); err != nil {
356
+ return nil , fmt .Errorf ("saving scoped session: %w" , err )
357
+ }
358
+
359
+ res , err := s .Wallets .SendIntent (waasapi .Context (ctx ), waasapi .ConvertToAPIIntent (intent .ToIntent ()))
360
+ if err != nil {
361
+ return nil , fmt .Errorf ("sending intent: %w" , err )
362
+ }
363
+
364
+ return convertIntentResponse (res ), nil
365
+ }
366
+
321
367
func (s * RPC ) dropSession (
322
368
ctx context.Context , sess * data.Session , intent * intents.IntentTyped [intents.IntentDataCloseSession ],
323
369
) (bool , error ) {
0 commit comments