From 6433de8f2545eb2c4bf5f6720183738dc659a6c1 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Sun, 30 Jul 2023 19:51:47 -0700 Subject: [PATCH] make sure refreshed token is stored in the database when making raw unsafe requests. --- .idea/dataSources.xml | 12 ++++++++++++ backend/pkg/web/handler/unsafe.go | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index 2eb8bcbb..bc641538 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -8,5 +8,17 @@ jdbc:sqlite:$PROJECT_DIR$/fasten.db $ProjectFileDir$ + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:$PROJECT_DIR$/fasten-jason.db + $ProjectFileDir$ + + + file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.40.1/org/xerial/sqlite-jdbc/3.40.1.0/sqlite-jdbc-3.40.1.0.jar + + + \ No newline at end of file diff --git a/backend/pkg/web/handler/unsafe.go b/backend/pkg/web/handler/unsafe.go index 0096fdc5..d7dc7822 100644 --- a/backend/pkg/web/handler/unsafe.go +++ b/backend/pkg/web/handler/unsafe.go @@ -1,11 +1,13 @@ package handler import ( + "fmt" "github.com/fastenhealth/fasten-sources/clients/factory" sourcePkg "github.com/fastenhealth/fasten-sources/pkg" "github.com/fastenhealth/fastenhealth-onprem/backend/pkg" "github.com/fastenhealth/fastenhealth-onprem/backend/pkg/config" "github.com/fastenhealth/fastenhealth-onprem/backend/pkg/database" + "github.com/fastenhealth/fastenhealth-onprem/backend/pkg/models" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" "net/http" @@ -79,6 +81,22 @@ func UnsafeRequestSource(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{"success": false, "error": err.Error(), "data": resp}) return } + + //update source incase the access token/refresh token has been updated + sourceCredential := client.GetSourceCredential() + sourceCredentialConcrete, ok := sourceCredential.(*models.SourceCredential) + if !ok { + logger.Errorln("An error occurred while updating source credential, source credential is not of type *models.SourceCredential") + c.JSON(http.StatusOK, gin.H{"success": false, "data": resp, "error": fmt.Errorf("An error occurred while updating source credential, source credential is not of type *models.SourceCredential")}) + return + } + err = databaseRepo.UpdateSource(c, sourceCredentialConcrete) + if err != nil { + logger.Errorf("An error occurred while updating source credential: %v", err) + c.JSON(http.StatusOK, gin.H{"success": false, "data": resp, "error": fmt.Errorf("An error occurred while updating source credential: %v", err)}) + return + } + c.JSON(http.StatusOK, gin.H{"success": true, "data": resp}) }