Skip to content

Minimal example of using the PKCE authorisation flow with Xero

License

Notifications You must be signed in to change notification settings

sde1000/python-xero-minimal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-xero-minimal

Example of using the Xero API from the command line, with minimal external dependencies. This example simply fetches an organisation name and shortcode using the Organisation endpoint.

Start by creating a "Mobile or desktop app" at https://developer.xero.com/app/manage — this shows as an app of type "PKCE" in your list of apps.

You will need a redirect URI for this app. Feel free to make use of https://quicktill.assorted.org.uk/xero.html which simply displays its URI in a box to make copying and pasting easier.

You will need to be able to open links from your terminal, and paste from your web browser into the terminal.

Warning: this demo creates a file called xerostate.json that contains an access token for your Xero organisation. Delete this file, or run the demo again with the --disconnect option to invalidate the token, when you are finished!

Running the demo

Ensure poetry is installed.

Run poetry install to install dependencies, then poetry run xero-demo to start the demo.

The first time you run the demo, you will be prompted to enter (paste!) the client ID and redirect URI for the app you created. These, and other persistent state, will be stored in a file called xerostate.json. If you need to change them you should delete this file.

The demo will display a URL for you to visit. At this URL you will be prompted to log in to Xero and authorise one or more organisations for the demo to access. You will end up at your redirect URI and must paste the URI into the demo.

A list of available Xero tenants will be displayed: enter the index of the tenant you want the demo to access.

Finally, the demo will use the Organisation endpoint to fetch and display the organisation name and shortcode.

On the second and subsequent run, the demo will use the token retrieved in the first run (refreshing it if necessary) and should be able to access the Organisation endpoint with no further interaction.

To disconnect after running the demo, use poetry run xero-demo --disconnect to revoke the refresh token.

About

Minimal example of using the PKCE authorisation flow with Xero

Topics

Resources

License

Stars

Watchers

Forks

Languages