Skip to content

Commit

Permalink
Merge pull request #539 from kitebuggy/custom-connections
Browse files Browse the repository at this point in the history
Added Custom Connections
  • Loading branch information
CloCkWeRX authored Sep 11, 2021
2 parents fe4606e + 193e0b6 commit b78a9a0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ pkg/
.DS_Store
.idea/
Gemfile.lock
tmp/
tmp/
*~ # emacs backup files
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ access_secret = client.access_token.secret

### Private Applications

Note: Private Applications are now deprecated by Xero. Please see the section below on Custom Connections for their replacement.

Private applications use a 2-legged authorisation process. When you register your application, you will select
the organisation that is authorised to your application. This cannot be changed afterwards, although you can
register another private application if you have multiple organisations.
Expand Down Expand Up @@ -345,6 +347,19 @@ client.renew_access_token
```
If you lose these details at any stage you can always reauthorise by redirecting the user back to the Xero OAuth gateway.

#### Custom Connections
Custom Connections are a paid-for option for private M2M applications. The generated token expires and needs recreating if expired.

```ruby
client = Xeroizer::OAuth2Application.new(
YOUR_OAUTH2_CLIENT_ID,
YOUR_OAUTH2_CLIENT_SECRET
)

token = client.authorize_from_client_credentials
```
You can check the status of the token with the `expires?` and `expired?` methods.


Retrieving Data
---------------
Expand Down
4 changes: 4 additions & 0 deletions lib/xeroizer/oauth2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def authorize_from_code(code, options = {})
@access_token = @client.auth_code.get_token(code, options)
end

def authorize_from_client_credentials(params = {}, options = {})
@access_token = @client.client_credentials.get_token(params, options)
end

def renew_access_token
@access_token = @access_token.refresh!
end
Expand Down
1 change: 1 addition & 0 deletions lib/xeroizer/oauth2_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class OAuth2Application < GenericApplication
extend Forwardable
def_delegators :client,
:authorize_from_access,
:authorize_from_client_credentials,
:authorize_from_code,
:authorize_url,
:renew_access_token,
Expand Down

0 comments on commit b78a9a0

Please sign in to comment.