fix oauth token refresh.
make sure raw request query params are passed in.
This commit is contained in:
parent
38dbc465bf
commit
734dac28f6
|
@ -22,6 +22,7 @@ func NewClient(ctx context.Context, appConfig config.Interface, globalLogger log
|
||||||
}, updatedSource, err
|
}, updatedSource, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Overrides
|
||||||
func (c AetnaClient) GetPatientBundle(patientId string) (fhir401.Bundle, error) {
|
func (c AetnaClient) GetPatientBundle(patientId string) (fhir401.Bundle, error) {
|
||||||
|
|
||||||
bundle := fhir401.Bundle{}
|
bundle := fhir401.Bundle{}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -42,7 +43,7 @@ func NewBaseClient(ctx context.Context, appConfig config.Interface, globalLogger
|
||||||
ClientSecret: "",
|
ClientSecret: "",
|
||||||
Endpoint: oauth2.Endpoint{
|
Endpoint: oauth2.Endpoint{
|
||||||
AuthURL: source.OauthAuthorizationEndpoint,
|
AuthURL: source.OauthAuthorizationEndpoint,
|
||||||
TokenURL: source.OauthTokenEndpointAuthMethods,
|
TokenURL: source.OauthTokenEndpoint,
|
||||||
},
|
},
|
||||||
//RedirectURL: "",
|
//RedirectURL: "",
|
||||||
//Scopes: nil,
|
//Scopes: nil,
|
||||||
|
@ -54,6 +55,7 @@ func NewBaseClient(ctx context.Context, appConfig config.Interface, globalLogger
|
||||||
Expiry: time.Unix(source.ExpiresAt, 0),
|
Expiry: time.Unix(source.ExpiresAt, 0),
|
||||||
}
|
}
|
||||||
if token.Expiry.Before(time.Now()) { // expired so let's update it
|
if token.Expiry.Before(time.Now()) { // expired so let's update it
|
||||||
|
log.Println("access token expired, refreshing...")
|
||||||
src := conf.TokenSource(ctx, token)
|
src := conf.TokenSource(ctx, token)
|
||||||
newToken, err := src.Token() // this actually goes and renews the tokens
|
newToken, err := src.Token() // this actually goes and renews the tokens
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -181,7 +182,17 @@ func RawRequestSource(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp map[string]interface{}
|
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 {
|
if err != nil {
|
||||||
logger.Errorf("Error making raw request, %v", err)
|
logger.Errorf("Error making raw request, %v", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"success": false, "error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"success": false, "error": err.Error()})
|
||||||
|
|
Loading…
Reference in New Issue