source/core-api/lambda_functions/auth_generate_token.py [109:167]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                refresh_token.make_signed_token(keypair)
                print(f"refresh token header: {refresh_token.serialize().split('.')[0]}")

                # save claims info and tokens in dynamo
                item = {
                        "event_id": EVENT_ID,
                        "request_id": request_id,
                        "issued_at": iat,
                        "not_before": nbf,
                        "expires": exp,
                        "queue_number": queue_number,
                        "access_token": access_token.serialize(),
                        "id_token": id_token.serialize(),
                        "refresh_token": refresh_token.serialize(),
                        "session_status": 0
                    }
                try:
                    ddb_table.put_item(
                        Item=item,
                        ConditionExpression="attribute_not_exists(request_id)"
                        )
                    response = {
                        "statusCode": 200,
                        "headers": headers,
                        "body": json.dumps({
                            "access_token": access_token.serialize(),
                            "refresh_token": refresh_token.serialize(),
                            "id_token": id_token.serialize(),
                            "token_type": "Bearer",
                            "expires_in": VALIDITY_PERIOD
                        })
                    }
                    # write to event bus
                    events_client.put_events(
                        Entries=[
                            {
                                'Source': 'custom.waitingroom',
                                'DetailType': 'token_generated',
                                'Detail': json.dumps({"event_id": EVENT_ID,
                                            "request_id": request_id}),
                                'EventBusName': EVENT_BUS_NAME
                            }
                        ]
                    )
                    # increment token counter
                    rc.incr(TOKEN_COUNTER, 1)
                # exception occurs if the token already exists in the database
                except ClientError as e:
                    if e.response['Error']['Code'] == 'ConditionalCheckFailedException':
                        # query the item, and calculate when it expired
                        result = ddb_table.query(
                            KeyConditionExpression=Key('request_id').eq(request_id))
                        expires = int(result['Items'][0]['expires'])
                        cur_time = int(time.time())
                        remaining_time = expires - cur_time
                        response = { 
                            "statusCode": 200,
                            "headers": headers,
                            "body": json.dumps({
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



source/core-api/lambda_functions/generate_token.py [104:162]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                refresh_token.make_signed_token(keypair)
                print(f"refresh token header: {refresh_token.serialize().split('.')[0]}")

                # save claims info and tokens in dynamo
                item = {
                        "event_id": EVENT_ID,
                        "request_id": request_id,
                        "issued_at": iat,
                        "not_before": nbf,
                        "expires": exp,
                        "queue_number": queue_number,
                        "access_token": access_token.serialize(),
                        "id_token": id_token.serialize(),
                        "refresh_token": refresh_token.serialize(),
                        "session_status": 0
                    }
                try:
                    ddb_table.put_item(
                        Item=item,
                        ConditionExpression="attribute_not_exists(request_id)"
                    )
                    response = {
                        "statusCode": 200,
                        "headers": headers,
                        "body": json.dumps({
                            "access_token": access_token.serialize(),
                            "refresh_token": refresh_token.serialize(),
                            "id_token": id_token.serialize(),
                            "token_type": "Bearer",
                            "expires_in": VALIDITY_PERIOD
                        })
                    }
                    # write to event bus
                    events_client.put_events(
                        Entries=[
                            {
                                'Source': 'custom.waitingroom',
                                'DetailType': 'token_generated',
                                'Detail': json.dumps({"event_id": EVENT_ID,
                                                      "request_id": request_id}),
                                'EventBusName': EVENT_BUS_NAME
                            }
                        ]
                    )
                    # increment token counter
                    rc.incr(TOKEN_COUNTER, 1)

                except ClientError as e:
                    if e.response['Error']['Code'] == 'ConditionalCheckFailedException':
                        # query the item, and calculate when it expired
                        result = ddb_table.query(
                            KeyConditionExpression=Key('request_id').eq(request_id))
                        expires = int(result['Items'][0]['expires'])
                        cur_time = int(time.time())
                        remaining_time = expires - cur_time
                        response = {
                            "statusCode": 200,
                            "headers": headers,
                            "body": json.dumps({
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



