omniauth-free_agent 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 +50 -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: 000aa87be94113e3bb658048acec7ad00a95388e425537ac759dd26204ec3b94
|
4
|
+
data.tar.gz: e016d5c740beb7a3847a6d79f5f911f4ac0f70e24ff59c61398e012454e8f67f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b271d408c76f8a62440f81ddaab3cfe8dab4932e5b892dbb13dfd4061141459862a7f69b5b87af68e814f4ccdc1df1922a202794b564c85bfad9890fb31aea2e
|
7
|
+
data.tar.gz: c1724133915a477c7f5c1f898064d97e64ba9eac55080848d52327c6e185296ae976070e7be650f280fff4d5d1d1f1253fa2db52bbded522bc5593ca4f15f8f9
|
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,50 @@
|
|
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"]
|
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["user"]
|
37
|
+
end
|
38
|
+
|
39
|
+
def company_info
|
40
|
+
@company_info ||= access_token.get("/v2/company").parsed
|
41
|
+
end
|
42
|
+
|
43
|
+
def callback_url
|
44
|
+
options[:redirect_uri] || full_host + script_name + callback_path
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# 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.2.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:
|