def api_client(api_config, oauth2_token): def token_getter(): return oauth2_token return ApiClient(configuration=api_config, pool_threads=1, oauth2_token_getter=token_getter)
def test_token_api_refresh_token(xero_client_id, xero_client_secret, xero_scope, vcr, vcr_cassette_name): # Given all oauth2 credential and refresh token api_client = ApiClient(pool_threads=1) token_api = TokenApi(api_client, xero_client_id, xero_client_secret) refresh_token = get_token_value( "test_refresh_token") or "test-refresh-token" # When getting new token with vcr.use_cassette(vcr_cassette_name, record_mode="none") as cassette: token = token_api.refresh_token(refresh_token, xero_scope) assert cassette.all_played # uncomment to save new token for next run use # with open(join(dirname(__file__), "oauth2_token.py"), "w") as token_file: # token_file.write("token = {!r}".format(token)) # Then new oauth2 token received assert isinstance(token, dict) assert token.get("refresh_token") assert token["refresh_token"] != refresh_token assert token.get("access_token") assert token.get("expires_in") assert token.get("id_token") assert token.get("token_type") assert token.get("scope") assert token["scope"].split() == xero_scope
def __init__(self, api_client=None, base_url=None): if api_client is None: api_client = ApiClient() self.api_client = api_client self.base_url = base_url or self.base_url
client_id=app.config["CLIENT_ID"], client_secret=app.config["CLIENT_SECRET"], endpoint_url="https://api.xero.com/", authorization_url="https://login.xero.com/identity/connect/authorize", access_token_url="https://identity.xero.com/connect/token", refresh_token_url="https://identity.xero.com/connect/token", scope="offline_access openid profile email accounting.transactions " "accounting.reports.read accounting.journals.read accounting.settings " "accounting.contacts accounting.attachments assets projects", ) # type: OAuth2Application # configure xero-python sdk client api_client = ApiClient( Configuration( debug=app.config["DEBUG"], oauth2_token=OAuth2Token(client_id=app.config["CLIENT_ID"], client_secret=app.config["CLIENT_SECRET"]), ), pool_threads=1, ) # configure token persistence and exchange point between flask-oauthlib and xero-python @xero.tokengetter @api_client.oauth2_token_getter def obtain_xero_oauth2_token(): return session.get("token") @xero.tokensaver @api_client.oauth2_token_saver def store_xero_oauth2_token(token):