Fix Xero token request

This commit is contained in:
Rene Vergara 2023-03-15 15:52:52 -05:00
parent cce6811df2
commit 75a6896ec8
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
3 changed files with 14 additions and 6 deletions

View file

@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Separate periodic tasks from API server - Separate periodic tasks from API server
- Zcash transaction monitoring changed to use memo parser - Zcash transaction monitoring changed to use memo parser
### Fixed
- Xero token generation for brand new users
## [1.2.5] - 2023-02-01 ## [1.2.5] - 2023-02-01
### Fixed ### Fixed

View file

@ -30,6 +30,6 @@ main = do
then do then do
let t = map (cast' . Doc) tokens let t = map (cast' . Doc) tokens
case creds of case creds of
Just c -> mapM_ (refreshToken pipe db c "") t Just c -> mapM_ (refreshToken pipe db c "" "") t
Nothing -> fail "No credentials" Nothing -> fail "No credentials"
else putStrLn "No tokens to refresh1" else putStrLn "No tokens to refresh1"

View file

@ -290,10 +290,11 @@ requestXeroToken :: Pipe -> T.Text -> Xero -> T.Text -> T.Text -> IO Bool
requestXeroToken pipe dbName cred code address = do requestXeroToken pipe dbName cred code address = do
token <- access pipe master dbName $ findToken address token <- access pipe master dbName $ findToken address
let oToken = token >>= cast' . Doc let oToken = token >>= cast' . Doc
refreshToken pipe dbName cred code oToken refreshToken pipe dbName cred code address oToken
refreshToken :: Pipe -> T.Text -> Xero -> T.Text -> Maybe XeroToken -> IO Bool refreshToken ::
refreshToken pipe dbName cred code token = do Pipe -> T.Text -> Xero -> T.Text -> T.Text -> Maybe XeroToken -> IO Bool
refreshToken pipe dbName cred code address token = do
let pars = let pars =
case token of case token of
Just x -> "grant_type=refresh_token&refresh_token=" <> t_refresh x Just x -> "grant_type=refresh_token&refresh_token=" <> t_refresh x
@ -316,9 +317,12 @@ refreshToken pipe dbName cred code token = do
200 -> do 200 -> do
let newToken = getResponseBody (res :: Response XeroToken) let newToken = getResponseBody (res :: Response XeroToken)
let accCode = t_code <$> token let accCode = t_code <$> token
let address = t_address <$> token {-let address = t_address <$> token-}
pToken <- pToken <-
processToken newToken (fromMaybe "" address) (fromMaybe "" accCode) processToken
newToken
(maybe address t_address token)
(fromMaybe "" accCode)
--print pToken --print pToken
_ <- access pipe master dbName $ upsertToken pToken _ <- access pipe master dbName $ upsertToken pToken
_ <- getTenantId pipe dbName pToken _ <- getTenantId pipe dbName pToken