Giter Site home page Giter Site logo

map7 / xero-ruby-oauth2-app Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xeroapi/xero-ruby-oauth2-app

0.0 0.0 0.0 6.08 MB

Ruby on rails app for demonstrating the xero-ruby SDK

Ruby 50.74% JavaScript 2.96% CSS 0.53% HTML 41.44% SCSS 4.33%

xero-ruby-oauth2-app's Introduction

Xero Ruby OAuth 2.0 App

This Ruby On Rails project demonstrates how to use the https://github.com/XeroAPI/xero-ruby SDK.

Its purpose is to speed up new ruby devs looking to build amazing applications with the data of users of the Xero Accounting platform: https://xero.com/. Secure authentication is setup using industry standard OAuth2.0. Access/Refresh tokens fuel authorized api calls.

Note: this project was built using:

  • ruby 2.7.0
  • Rails 6.0.2.2
git clone [email protected]:XeroAPI/xero-ruby-oauth2-app.git
cd xero-ruby-oauth2-app
bundle install
yarn

Configure with your credentials

Create a .env in the root of your project directory or replace the env.sample

CLIENT_ID=...
CLIENT_SECRET=...
REDIRECT_URI=...

Start your server

bundle exec rake db:create db:migrate
yarn
rails s

By default rails runs on port 3000. Make sure you have in your /myapps dashboard 'http://localhost:3000/callback' or specify the port with rails s -p 8080 etc.

walkthrough


Important structure

The project shows a strategy to effectively leverage the xero-ruby SDK. It is best documented by cloning/running the app but here are a few tips to quickly understanding the structure if you are not familair with Rails.

Routes

  • config/routes.rb will give a great picture of this apps functionality

User model

  • One table :users - utilizes super basic authentication.
  • A JSON column :token_set that stores the entire token_set returned from the auth flow
  • A string column active_tenant_id that references the actively selected tenant/org

Application Controller

Bulk of the auth flow logic. This uses a few helpers but shows how to handle the full authentication flow, refresh a token, disconnect an org, and even change which org you want to make api calls to.

  • callback
  • refresh_token
  • change_organisation
  • disconnect

Application Helper

This includes some helpers that showcase how to decode the individual pieces of the token_set and show the multiple ways you can setup the xero_client, etc..

  • token_expired
  • id_token
  • access_token
  • current_user
  • xero_client
  • accounting_api
  • authorization_url
  • latest_connection

Debugging

  • put -fail or binding.pry in your code for an interactive brower or terminal shell where you can inspect the current request, manipulate results and see where your code went wrong ;)

Contributing

You are very welcome to add/improve functionality - we will continue to make improvements that show more complex API usage like filter/sorting, paginating, and will add more CRUD workflows as new API sets are added to the ruby-sdk. Please open an issue if something is not working correctly.

xero-ruby-oauth2-app's People

Contributors

serknight avatar dependabot[bot] avatar rjaus avatar rettbehrens avatar dbastin avatar drnic avatar map7 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.