omniauth-visma 0.0.5 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6275d75a6bc6192d047c6cdaf044b49734faf2e4545acc23025c995d720dc9b
4
- data.tar.gz: a400dafc034f3330993549f13e9510bcac57737c9468bb5396834616d2b848b5
3
+ metadata.gz: e3213a7b447325323e9cc6a8428511208d5028cc484ff695df6997eac8ae1e28
4
+ data.tar.gz: cb3b818a2adda05e47de90d16e1fb7f7fc55253a9b84eb3bf5a18a0c1f708a5a
5
5
  SHA512:
6
- metadata.gz: ca93ecab3eeee34515c6153c962492e802c0ec507573943b3c711f09d9f1fc5af3f3aa9cfd9741298a5ec8cda679b0cf9eabacff1bc816895ebc5981893b3a9f
7
- data.tar.gz: d64a2f218a7384e30e603d52b2a2e2e65068019c2164220d19d22eab1baef05715b125e865ba0825984eae856a2627378f228250fcf885b918f033a5cb8b378d
6
+ metadata.gz: b809a0569715bdbde9055ce5af177ba1d4bd579a78fae71e0177362a93404dfd6c65257c9c7edd00efdb9aa4a29e52d02b65406694e36dfaeea29f5d1da28df5
7
+ data.tar.gz: 6485295bee210f20419cd1f37b24af045a59f4b1bb8b07b8de47fd4d07ce4feed1b1236e5b1e53722d1a34e474197612db431a95e2fce43d82f764fc3ad7fbd6
data/README.md CHANGED
@@ -6,13 +6,36 @@ See the [authorization documentation](https://developer.vismaonline.com/#eAccoun
6
6
 
7
7
  For more information about the API see https://developer.vismaonline.com/.
8
8
 
9
+ To easily use the API from Ruby see [VismaEaccounting](https://github.com/espen/visma_eaccounting).
10
+
9
11
  ## Basic Usage
10
12
 
11
13
  use OmniAuth::Builder do
12
14
  provider "visma", ENV['VISMA_CLIENT_ID'], ENV['VISMA_CLIENT_SECRET'], scope: 'offline_access ea:api'
13
15
  end
14
16
 
15
- The default environment is ```:production```. For testing you can use the sandbox environment by specifying ```:sandbox``` as ```environment``` in the provider setup. If changing environment after initalizing then call ```change_environment```.
17
+ ## Refreshing the access token
18
+
19
+ The retrieved ```access_token``` expires in one hour. So you need to retrieve a new token when it expires. You can do so using the ```refresh!``` method in OmniAuth. You will retrieve all new tokens so make sure you save both the ```access_token``` and ```refresh_token```.
20
+
21
+ Example:
22
+
23
+ ```ruby
24
+ if Time.at( visma_access_token_expires_at ).past?
25
+ oauth = OmniAuth::Strategies::Visma.new(nil, {
26
+ client_id: ENV['VISMA_CLIENT_ID'],
27
+ client_secret: ENV['VISMA_CLIENT_SECRET']
28
+ }
29
+ token = OAuth2::AccessToken.new(
30
+ oauth.client,
31
+ visma_access_token,
32
+ { refresh_token: visma_refresh_token }
33
+ )
34
+ new_tokens = token.refresh!
35
+ end
36
+ ```
37
+
38
+ You can then use the new ```access_token``` and when it expires you can use the new ```refresh_token``` to gain a new one.
16
39
 
17
40
  ## Credits
18
41
 
@@ -4,26 +4,12 @@ require 'multi_json'
4
4
  module OmniAuth
5
5
  module Strategies
6
6
  class Visma < OmniAuth::Strategies::OAuth2
7
- AUTH_URLS = {
8
- :sandbox => {
9
- site: "https://eaccountingapi-sandbox.test.vismaonline.com/v2/",
10
- authorize_url: "https://identity-sandbox.test.vismaonline.com/connect/authorize",
11
- token_url: "https://identity-sandbox.test.vismaonline.com/connect/token"
12
- },
13
- :production => {
14
- site: "https://eaccountingapi.vismaonline.com/v2/",
15
- authorize_url: "https://identity.vismaonline.com/connect/authorize",
16
- token_url: "https://identity.vismaonline.com/connect/token"
17
- }
18
- }
19
7
  option :name, "visma"
20
- option :client_options, AUTH_URLS[:production]
21
- option :environment, :production
22
-
23
- def initialize(*args)
24
- super(*args)
25
- update_default_environment_urls
26
- end
8
+ option :client_options, {
9
+ site: "https://eaccountingapi.vismaonline.com/v2/",
10
+ authorize_url: "https://identity.vismaonline.com/connect/authorize",
11
+ token_url: "https://identity.vismaonline.com/connect/token"
12
+ }
27
13
 
28
14
  info do
29
15
  {
@@ -50,19 +36,8 @@ module OmniAuth
50
36
  @raw_info ||= access_token.get('/v2/companysettings').parsed
51
37
  end
52
38
 
53
- def change_environment
54
- update_default_environment_urls
55
- end
56
-
57
39
  private
58
40
 
59
- def update_default_environment_urls
60
- case options.environment
61
- when :sandbox
62
- options.client_options = options.client_options.merge( AUTH_URLS[options.environment] )
63
- end
64
- end
65
-
66
41
  def callback_url
67
42
  full_host + script_name + callback_path
68
43
  end
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Visma
3
- VERSION = "0.0.5"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -31,30 +31,4 @@ describe OmniAuth::Strategies::Visma do
31
31
  end
32
32
  end
33
33
 
34
- describe '#environment' do
35
-
36
- subject do
37
- strategy = OmniAuth::Strategies::Visma.new(nil, @options || {})
38
- strategy.stub(:session) { {} }
39
- strategy
40
- end
41
-
42
- it 'should use production environment by default' do
43
- subject.client.authorize_url.should eq("https://identity.vismaonline.com/connect/authorize")
44
- end
45
-
46
- it 'should set environment' do
47
- @options = {:environment => :sandbox}
48
- subject.options.environment.should eq(:sandbox)
49
- subject.client.authorize_url.should eq("https://identity-sandbox.test.vismaonline.com/connect/authorize")
50
- end
51
-
52
- it 'should set environment after init' do
53
- subject.options.environment = :sandbox
54
- subject.change_environment
55
- subject.client.authorize_url.should eq("https://identity-sandbox.test.vismaonline.com/connect/authorize")
56
- end
57
-
58
- end
59
-
60
- end
34
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-visma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Espen Antonsen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-11 00:00:00.000000000 Z
11
+ date: 2024-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth
@@ -118,7 +118,7 @@ homepage: https://github.com/espen/omniauth-visma
118
118
  licenses:
119
119
  - MIT
120
120
  metadata: {}
121
- post_install_message:
121
+ post_install_message:
122
122
  rdoc_options: []
123
123
  require_paths:
124
124
  - lib
@@ -133,9 +133,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  - !ruby/object:Gem::Version
134
134
  version: '0'
135
135
  requirements: []
136
- rubyforge_project:
137
- rubygems_version: 2.7.3
138
- signing_key:
136
+ rubygems_version: 3.5.14
137
+ signing_key:
139
138
  specification_version: 4
140
139
  summary: OmniAuth strategy for Visma eAccounting.
141
140
  test_files: