Skip to content

This project demonstrates how the Linx Xero Authentication Service can be used to handle OAuth 2.0 authentication and make API calls to Xero's accounting platform. It includes example functions for authenticating users, managing tokens, retrieving tenant information, and accessing Xero API endpoints such as the Balance Sheet API.

License

Notifications You must be signed in to change notification settings

linx-software/XeroAuthenticationServiceExample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Linx Xero Authentication Service Example

Description

This repository contains an example Linx solution demonstrating how to implement and use the Xero Authentication Service. The solution provides a practical implementation for connecting to the Xero API, retrieving tenant information, and fetching accounting data such as balance sheets.

The example showcases the proper authentication flow with Xero, token management, and making authenticated API calls - all using the Linx Xero Authentication Service plugin.

Installation

  1. Clone this repository to your local machine
  2. Open the solution using Linx Designer
  3. Configure the required settings (see Configuration section below)
  4. Debug the solution

Prerequisites

  • Linx Designer (latest version)
  • Access to a database for storing authentication tokens
  • A registered Xero application with API credentials
  • A Xero user with active company (Demo Company will work)

Configuration

Before running the solution, you need to configure the following settings:

  • XeroAuthURL: The service URI for handling the authorization. The service will listen for incoming requests at [authorization-uri]/authorize
  • XeroRedirectURL: The URI to which users will be redirected after the authorization process is complete
  • XeroClientID: Client ID from your registered Xero application
  • XeroClientSecret: Client secret from your registered Xero application
  • XeroDatabaseConnection: Database connection string where the authentication tables will be created to store client tenant and token information
  • XeroBaseURI: The base URI for Xero API calls

Important: In your Xero application settings, set the Redirect URI to [authorization-uri]/callback

Usage

The solution includes the following key components:

XeroService

The core authentication service that handles OAuth 2.0 authorization with Xero. This service is documented in the Linx Xero Authentication Service documentation.

ExampleMainFunction

This function demonstrates the proper usage of the Xero Authentication Service:

  1. Set the XeroUserIDToBeUsed variable with the Xero User ID
  2. Call StartServiceXeroAuth to start the service (only required when running in debug mode)
  3. Call GetTenants to retrieve available tenants
  4. Loop through tenants and call GetBalanceSheet for each one

GetBalanceSheet

This function demonstrates how to call the Xero Balance Sheet API and process the response. It:

  1. Makes an authenticated API call to Xero's Balance Sheet endpoint
  2. Processes the response and assigns it to a typed object
  3. Returns the balance sheet data

Authentication Process

To authenticate a client and obtain a User ID:

  1. Configure the solution with your Xero app credentials
  2. Run the solution in debug mode using ExampleMainFunction
  3. Visit the Authorization URI in your browser ([XeroAuthURL]/authorize)
  4. Follow the authentication flow as described in the Xero Authentication Service documentation
  5. After successful authentication, retrieve the User ID for future API calls

Types

Data types for the API responses are stored in the Types folder. These can be:

  • Imported directly from documentation
  • Created by debugging API calls as strings, then importing the JSON response as a new type

Contributing

For questions and support, please ask the Linx community.

License

MIT

About

This project demonstrates how the Linx Xero Authentication Service can be used to handle OAuth 2.0 authentication and make API calls to Xero's accounting platform. It includes example functions for authenticating users, managing tokens, retrieving tenant information, and accessing Xero API endpoints such as the Balance Sheet API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published