mirror of
https://github.com/status-im/spiffworkflow-connector.git
synced 2025-02-22 19:48:07 +00:00
Refresh Xero OAuth token (#16)
* WIP - sending refreshed token back * Small cleanup
This commit is contained in:
parent
f790e3eae8
commit
a6b31a8442
@ -164,8 +164,13 @@ class CreateInvoice:
|
|||||||
client_id = config["XERO_CLIENT_ID"]
|
client_id = config["XERO_CLIENT_ID"]
|
||||||
client_secret = config["XERO_CLIENT_SECRET"]
|
client_secret = config["XERO_CLIENT_SECRET"]
|
||||||
|
|
||||||
|
# this should be called token_set to match the docs
|
||||||
access_token = json.loads(self.access_token)
|
access_token = json.loads(self.access_token)
|
||||||
|
|
||||||
|
# need a mutable "store" to appease the libs
|
||||||
|
token_store = {}
|
||||||
|
token_store_key = "token"
|
||||||
|
|
||||||
api_client = ApiClient(
|
api_client = ApiClient(
|
||||||
Configuration(
|
Configuration(
|
||||||
debug=True,
|
debug=True,
|
||||||
@ -179,12 +184,16 @@ class CreateInvoice:
|
|||||||
@api_client.oauth2_token_getter
|
@api_client.oauth2_token_getter
|
||||||
def obtain_xero_oauth2_token():
|
def obtain_xero_oauth2_token():
|
||||||
"""Obtain_xero_oauth2_token."""
|
"""Obtain_xero_oauth2_token."""
|
||||||
return access_token
|
return token_store[token_store_key]
|
||||||
|
|
||||||
@api_client.oauth2_token_saver
|
@api_client.oauth2_token_saver
|
||||||
def store_xero_oauth2_token(token):
|
def store_xero_oauth2_token(token):
|
||||||
"""Store_xero_oauth2_token."""
|
"""Store_xero_oauth2_token."""
|
||||||
access_token = token # noqa
|
token_store[token_store_key] = token # noqa
|
||||||
|
|
||||||
|
store_xero_oauth2_token(access_token)
|
||||||
|
|
||||||
|
api_client.refresh_oauth2_token()
|
||||||
|
|
||||||
api_instance = AccountingApi(api_client)
|
api_instance = AccountingApi(api_client)
|
||||||
summarize_errors = "True"
|
summarize_errors = "True"
|
||||||
@ -223,7 +232,11 @@ class CreateInvoice:
|
|||||||
created_invoices = api_instance.create_invoices(
|
created_invoices = api_instance.create_invoices(
|
||||||
xero_tenant_id, invoices, summarize_errors, unitdp
|
xero_tenant_id, invoices, summarize_errors, unitdp
|
||||||
)
|
)
|
||||||
response = json.dumps(serialize(created_invoices))
|
response = json.dumps({
|
||||||
|
"api_response": serialize(created_invoices),
|
||||||
|
"refreshed_token_set": obtain_xero_oauth2_token(),
|
||||||
|
"auth": "xero/OAuth",
|
||||||
|
})
|
||||||
status = 200
|
status = 200
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# TODO better error logging/reporting in debug
|
# TODO better error logging/reporting in debug
|
||||||
|
Loading…
x
Reference in New Issue
Block a user