Skip to content

This is a starter app to perform OAuth 2.0 authentication with xero-ruby

License

Notifications You must be signed in to change notification settings

XeroAPI/xero-ruby-oauth2-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a basic application showing how to get started with the Xero's official xero-ruby SDK

It uses Sinatra which is a DSL for creating simple web applications in Ruby with minimal effort

Getting Started

1) This app is tested with Ruby 3.3.0

ruby -v
ruby 3.3.0

2) Create an app in Xero's developer portal

https://developer.xero.com/myapps/

3) Decide what scopes your application needs

https://developer.xero.com/documentation/oauth2/scopes

4) Clone app and rename sample.env to .env and replace with the 4 required parameters

$ git clone [email protected]:XeroAPI/xero-ruby-oauth2-starter.git
$ cd xero-ruby-oauth2-starter/
$ mv sample.env .env

Replace CLIENT_ID, CLIENT_SECRET, REDIRECT_URI & SCOPES with your unique parameters

5) Install dependencies & run the app

$ bundle install
$ bundle exec ruby xero_app.rb

Visit http://localhost:4567/ and start exploring the code in your editor of choice 🥳


Sample getting started code

Setting up and connecting to the XeroAPI with the xero-ruby SDK is simple

@xero_client = XeroRuby::ApiClient.new(credentials: {
  client_id: ENV['CLIENT_ID'],
  client_secret: ENV['CLIENT_SECRET'],
  redirect_uri: 'http://localhost:4567/callback',
  scopes: ENV['SCOPES']
})

get '/auth' do
  redirect to(@xero_client.authorization_url)
end

get '/auth/callback' do
  @xero_client.get_token_set_from_callback(params)
  tenant_id = @xero_client.connections.last['tenantId']
  @invoices = @xero_client.accounting_api.get_invoices(tenant_id).invoices
end

Checkout xero_app.rb for all the sample code you need to get started for your own app

App functionality

walkthrough

About

This is a starter app to perform OAuth 2.0 authentication with xero-ruby

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published