From 734dac28f619f459faf00fd948806b21c486ff26 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Wed, 21 Sep 2022 22:02:55 -0700 Subject: [PATCH] fix oauth token refresh. make sure raw request query params are passed in. --- backend/pkg/hub/internal/fhir/aetna/client.go | 1 + backend/pkg/hub/internal/fhir/base/base_client.go | 4 +++- backend/pkg/web/handler/source.go | 13 ++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/pkg/hub/internal/fhir/aetna/client.go b/backend/pkg/hub/internal/fhir/aetna/client.go index 4f256b3e..696a40cf 100644 --- a/backend/pkg/hub/internal/fhir/aetna/client.go +++ b/backend/pkg/hub/internal/fhir/aetna/client.go @@ -22,6 +22,7 @@ func NewClient(ctx context.Context, appConfig config.Interface, globalLogger log }, updatedSource, err } +//Overrides func (c AetnaClient) GetPatientBundle(patientId string) (fhir401.Bundle, error) { bundle := fhir401.Bundle{} diff --git a/backend/pkg/hub/internal/fhir/base/base_client.go b/backend/pkg/hub/internal/fhir/base/base_client.go index 4735b54f..3e3898e0 100644 --- a/backend/pkg/hub/internal/fhir/base/base_client.go +++ b/backend/pkg/hub/internal/fhir/base/base_client.go @@ -10,6 +10,7 @@ import ( "github.com/sirupsen/logrus" "golang.org/x/oauth2" "io" + "log" "net/http" "net/url" "os" @@ -42,7 +43,7 @@ func NewBaseClient(ctx context.Context, appConfig config.Interface, globalLogger ClientSecret: "", Endpoint: oauth2.Endpoint{ AuthURL: source.OauthAuthorizationEndpoint, - TokenURL: source.OauthTokenEndpointAuthMethods, + TokenURL: source.OauthTokenEndpoint, }, //RedirectURL: "", //Scopes: nil, @@ -54,6 +55,7 @@ func NewBaseClient(ctx context.Context, appConfig config.Interface, globalLogger Expiry: time.Unix(source.ExpiresAt, 0), } if token.Expiry.Before(time.Now()) { // expired so let's update it + log.Println("access token expired, refreshing...") src := conf.TokenSource(ctx, token) newToken, err := src.Token() // this actually goes and renews the tokens if err != nil { diff --git a/backend/pkg/web/handler/source.go b/backend/pkg/web/handler/source.go index af0dbd40..9574da55 100644 --- a/backend/pkg/web/handler/source.go +++ b/backend/pkg/web/handler/source.go @@ -10,6 +10,7 @@ import ( "github.com/sirupsen/logrus" "io/ioutil" "net/http" + "net/url" "strings" ) @@ -181,7 +182,17 @@ func RawRequestSource(c *gin.Context) { } var resp map[string]interface{} - err = client.GetRequest(strings.TrimSuffix(c.Param("path"), "/"), &resp) + + parsedUrl, err := url.Parse(strings.TrimSuffix(c.Param("path"), "/")) + if err != nil { + logger.Errorf("Error parsing request, %v", err) + c.JSON(http.StatusInternalServerError, gin.H{"success": false, "error": err.Error()}) + return + } + //make sure we include all query string parameters with the raw request. + parsedUrl.RawQuery = c.Request.URL.Query().Encode() + + err = client.GetRequest(parsedUrl.String(), &resp) if err != nil { logger.Errorf("Error making raw request, %v", err) c.JSON(http.StatusInternalServerError, gin.H{"success": false, "error": err.Error()})