omniauth-free_agent 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +101 -15
- data/lib/omniauth/free_agent/version.rb +1 -1
- data/lib/omniauth/free_agent.rb +2 -9
- data/lib/omniauth/strategies/free_agent.rb +52 -0
- data/lib/omniauth/strategies/free_agent_sandbox.rb +19 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c879db6832b5d305f8b98fc1cceca219e5f1cfa2578fffe239cfad1787b6f77
|
4
|
+
data.tar.gz: 193b1e0bddc547e6b3843bc1444334c14fa098f5f4eb110546711bfa5a22bdfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c2ecdb8a0b9b94b155aee617190e50370345494cc5612973eb617eb74fa106728c7e283283c9e70981407898efd5fa7822e17379bb8172b76dc2f856c502b75
|
7
|
+
data.tar.gz: 75c1857822dda93a9658e0a9b05d34aa51aabe86a2344572289bb4478b302169f79905d0d73a34139976ccaac5a9afa4b605a07d34755b1532acccb003417d22
|
data/README.md
CHANGED
@@ -1,29 +1,115 @@
|
|
1
|
-
#
|
1
|
+
# OmniAuth FreeAgent
|
2
2
|
|
3
|
-
|
3
|
+
An OmniAuth strategy for FreeAgent
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
Add the OmniAuth FreeAgent and OmniAuth rails_csrf_protection gems to your Gemfile
|
8
8
|
|
9
|
-
|
9
|
+
```ruby
|
10
|
+
gem 'omniauth-free_agent'
|
11
|
+
gem 'omniauth-rails_csrf_protection'
|
12
|
+
```
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
## Usage
|
14
15
|
|
15
|
-
|
16
|
+
You can create an application on the [FreeAgent Developer Dashboard](https://dev.freeagent.com/) and get your app and secret keys.
|
16
17
|
|
17
|
-
|
18
|
+
Here's an example for adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
|
18
19
|
|
19
|
-
|
20
|
+
```ruby
|
21
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
22
|
+
provider :free_agent, ENV["FREEAGENT_CLIENT"], ENV["FREEAGENT_SECRET"]
|
23
|
+
end
|
24
|
+
```
|
20
25
|
|
21
|
-
|
26
|
+
Or for the FreeAgent Sandbox:
|
22
27
|
|
23
|
-
|
28
|
+
```ruby
|
29
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
30
|
+
provider :free_agent_sandbox, ENV["FREEAGENT_CLIENT"], ENV["FREEAGENT_SECRET"]
|
31
|
+
end
|
32
|
+
```
|
24
33
|
|
25
|
-
|
34
|
+
## Auth Hash
|
26
35
|
|
27
|
-
|
36
|
+
Here's an example Auth hash available in `request.env["omniauth.auth"]`:
|
28
37
|
|
29
|
-
|
38
|
+
```json
|
39
|
+
{
|
40
|
+
"provider": "free_agent_sandbox",
|
41
|
+
"uid": "https://api.sandbox.freeagent.com/v2/users/ID",
|
42
|
+
"info": {
|
43
|
+
"email": "test@test.com",
|
44
|
+
"first_name": "Test",
|
45
|
+
"last_name": "User",
|
46
|
+
"name": "Test User"
|
47
|
+
},
|
48
|
+
"credentials": {
|
49
|
+
"token": "abc123",
|
50
|
+
"refresh_token": "123abc",
|
51
|
+
"expires_at": 123123123,
|
52
|
+
"expires": true
|
53
|
+
},
|
54
|
+
"extra": {
|
55
|
+
"user": {
|
56
|
+
"url": "https://api.sandbox.freeagent.com/v2/users/ID",
|
57
|
+
"first_name": "Test",
|
58
|
+
"last_name": "User",
|
59
|
+
"hidden": false,
|
60
|
+
"email": "test@test.com",
|
61
|
+
"role": "Owner",
|
62
|
+
"permission_level": 8,
|
63
|
+
"opening_mileage": "0.0",
|
64
|
+
"updated_at": "2024-08-12T14:15:01.000Z",
|
65
|
+
"created_at": "2024-08-12T14:09:02.000Z"
|
66
|
+
},
|
67
|
+
"company": {
|
68
|
+
"company": {
|
69
|
+
"url": "https://api.sandbox.freeagent.com/v2/company",
|
70
|
+
"id": 22954,
|
71
|
+
"name": "My Company",
|
72
|
+
"subdomain": "mycompany",
|
73
|
+
"type": "UkSoleTrader",
|
74
|
+
"company_start_date": "2024-04-06",
|
75
|
+
"currency": "GBP",
|
76
|
+
"mileage_units": "miles",
|
77
|
+
"short_date_format": "dd mmm yy",
|
78
|
+
"freeagent_start_date": "2024-04-06",
|
79
|
+
"first_accounting_year_end": "2025-04-05",
|
80
|
+
"annual_accounting_periods": [
|
81
|
+
{
|
82
|
+
"starts_on": "2024-04-06",
|
83
|
+
"ends_on": "2025-04-05"
|
84
|
+
}
|
85
|
+
],
|
86
|
+
"address1": "1 A Road",
|
87
|
+
"town": "2 A Town",
|
88
|
+
"postcode": "AA11 1AA",
|
89
|
+
"country": "United Kingdom",
|
90
|
+
"locale": "en",
|
91
|
+
"business_category": "Software Development",
|
92
|
+
"cis_enabled": false,
|
93
|
+
"locked_attributes": [
|
94
|
+
"currency"
|
95
|
+
],
|
96
|
+
"created_at": "2024-08-12T14:09:02.000Z",
|
97
|
+
"updated_at": "2024-08-12T14:09:46.000Z",
|
98
|
+
"sales_tax_registration_status": "Not Registered",
|
99
|
+
"ec_vat_reporting_enabled": false,
|
100
|
+
"sales_tax_name": "VAT",
|
101
|
+
"sales_tax_effective_date": "2024-04-06",
|
102
|
+
"sales_tax_rates": [
|
103
|
+
"20.0",
|
104
|
+
"5.0",
|
105
|
+
"0.0"
|
106
|
+
],
|
107
|
+
"supports_auto_sales_tax_on_purchases": true,
|
108
|
+
"initially_on_frs": false,
|
109
|
+
"sales_tax_is_value_added": true,
|
110
|
+
"initial_vat_basis": "Invoice"
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
```
|
data/lib/omniauth/free_agent.rb
CHANGED
@@ -1,10 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require_relative "free_agent/version"
|
4
|
-
|
5
|
-
|
6
|
-
module FreeAgent
|
7
|
-
class Error < StandardError; end
|
8
|
-
# Your code goes here...
|
9
|
-
end
|
10
|
-
end
|
2
|
+
require "omniauth/strategies/free_agent"
|
3
|
+
require "omniauth/strategies/free_agent_sandbox"
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "omniauth/strategies/oauth2"
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
module Strategies
|
7
|
+
class FreeAgent < OmniAuth::Strategies::OAuth2
|
8
|
+
option :name, "free_agent"
|
9
|
+
|
10
|
+
option :client_options, {
|
11
|
+
site: "https://api.freeagent.com",
|
12
|
+
authorize_url: "https://api.freeagent.com/v2/approve_app",
|
13
|
+
token_url: "https://api.freeagent.com/v2/token_endpoint",
|
14
|
+
}
|
15
|
+
|
16
|
+
uid do
|
17
|
+
user_info["url"].split("/").last.to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
info do
|
21
|
+
{
|
22
|
+
email: user_info["email"],
|
23
|
+
first_name: user_info["first_name"],
|
24
|
+
last_name: user_info["last_name"],
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
extra do
|
29
|
+
{
|
30
|
+
user: user_info,
|
31
|
+
company: company_info
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def user_info
|
36
|
+
@user_info ||= access_token.get("/v2/users/me").parsed
|
37
|
+
@user_info["user"] || {}
|
38
|
+
end
|
39
|
+
|
40
|
+
def company_info
|
41
|
+
@company_info ||= access_token.get("/v2/company").parsed
|
42
|
+
@company_info["company"] || {}
|
43
|
+
end
|
44
|
+
|
45
|
+
def callback_url
|
46
|
+
options[:redirect_uri] || full_host + script_name + callback_path
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# OmniAuth.config.add_camelization "freeagent", "FreeAgent"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "omniauth/strategies/oauth2"
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
module Strategies
|
7
|
+
class FreeAgentSandbox < OmniAuth::Strategies::FreeAgent
|
8
|
+
|
9
|
+
option :name, "free_agent_sandbox"
|
10
|
+
|
11
|
+
option :client_options, {
|
12
|
+
site: "https://api.sandbox.freeagent.com",
|
13
|
+
authorize_url: "https://api.sandbox.freeagent.com/v2/approve_app",
|
14
|
+
token_url: "https://api.sandbox.freeagent.com/v2/token_endpoint",
|
15
|
+
}
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-free_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dean Perry
|
@@ -49,6 +49,8 @@ files:
|
|
49
49
|
- Rakefile
|
50
50
|
- lib/omniauth/free_agent.rb
|
51
51
|
- lib/omniauth/free_agent/version.rb
|
52
|
+
- lib/omniauth/strategies/free_agent.rb
|
53
|
+
- lib/omniauth/strategies/free_agent_sandbox.rb
|
52
54
|
homepage: https://github.com/deanpcmad/omniauth-free_agent
|
53
55
|
licenses: []
|
54
56
|
metadata:
|