forge_auth 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 513e923f89645609bfd1e04f5be62fb1c9b40f93
4
+ data.tar.gz: 2c366559e555e7f53b114de471f494c795cd26e3
5
+ SHA512:
6
+ metadata.gz: 0bbefded8a924d71e063fa9337e537c4a713877fa810b02cb0faea8328d6158ec0c14becffb5be0d0c26a358696c480893cacac39027141018842266044550b9
7
+ data.tar.gz: f710455e072c66930190fb9757237949b364f2c5660132b1d839795c10a54a57f935f4987b7659507690627d5a31f5d12428ff5ec694e3bb2d05ddae8c02e1c4
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in forge_auth.gemspec
4
+ gemspec
@@ -0,0 +1,93 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://developer-dev.api.autodesk.com/authentication/v1/authenticate
6
+ body:
7
+ encoding: UTF-8
8
+ string: client_id=<CLIENT_ID>&client_secret=<CLIENT_SECRET>&grant_type=client_credentials&scope=data%3Aread
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Cache-Control:
24
+ - no-cache, no-store, no-store
25
+ Content-Security-Policy:
26
+ - referrer origin
27
+ Content-Type:
28
+ - application/json;charset=utf-8
29
+ Date:
30
+ - Tue, 12 Dec 2017 22:05:10 GMT
31
+ Expires:
32
+ - Thu, 01 Jan 1970 00:00:00 GMT
33
+ Pragma:
34
+ - no-cache
35
+ Set-Cookie:
36
+ - PF=ceBSEes9dD8HUdHfB0jABm;Path=/;Secure;HttpOnly
37
+ X-Frame-Options:
38
+ - SAMEORIGIN
39
+ Content-Length:
40
+ - '436'
41
+ Connection:
42
+ - keep-alive
43
+ body:
44
+ encoding: UTF-8
45
+ string: "{\"access_token\":\"eyJhbGciOiJIUzI1NiIsImtpZCI6Imp3dF9zeW1tZXRyaWNfa2V5X2RldiJ9.eyJjbGllbnRfaWQiOiJnUHI1ZjZmWWI4d21HQ01WNVlRSTZKMk5QQjlueUxaaSIsImV4cCI6MTUxMzExOTkxMCwic2NvcGUiOlsiZGF0YTpyZWFkIl0sImF1ZCI6Imh0dHBzOi8vYXV0b2Rlc2suY29tL2F1ZC9qd3RleHA2MCIsImp0aSI6IlhlZkJnZEpJSW4xZnZudlhheDh3azJTbUJWVXBvUXFTeW5XWnVvTFZ2RmVyMEI5OVZoQjJBM3poQkgxODlmYngifQ.DQ0SGJvnVUoxL7TFTkmpg6p2vQFOC0YtHq403rW7ePI\",\"token_type\":\"Bearer\",\"expires_in\":3599}\r\n"
46
+ http_version:
47
+ recorded_at: Tue, 12 Dec 2017 22:05:05 GMT
48
+ - request:
49
+ method: post
50
+ uri: https://developer-dev.api.autodesk.com/authentication/v1/authenticate
51
+ body:
52
+ encoding: UTF-8
53
+ string: client_id=<CLIENT_ID>&client_secret=<CLIENT_SECRET>&grant_type=client_credentials&scope=data%3Aread
54
+ headers:
55
+ User-Agent:
56
+ - Faraday v0.9.2
57
+ Content-Type:
58
+ - application/x-www-form-urlencoded
59
+ Accept-Encoding:
60
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
61
+ Accept:
62
+ - "*/*"
63
+ response:
64
+ status:
65
+ code: 200
66
+ message: OK
67
+ headers:
68
+ Cache-Control:
69
+ - no-cache, no-store, no-store
70
+ Content-Security-Policy:
71
+ - referrer origin
72
+ Content-Type:
73
+ - application/json;charset=utf-8
74
+ Date:
75
+ - Tue, 12 Dec 2017 22:05:12 GMT
76
+ Expires:
77
+ - Thu, 01 Jan 1970 00:00:00 GMT
78
+ Pragma:
79
+ - no-cache
80
+ Set-Cookie:
81
+ - PF=K5MVjYNVSBHU9NFZWwxcF6;Path=/;Secure;HttpOnly
82
+ X-Frame-Options:
83
+ - SAMEORIGIN
84
+ Content-Length:
85
+ - '436'
86
+ Connection:
87
+ - keep-alive
88
+ body:
89
+ encoding: UTF-8
90
+ string: "{\"access_token\":\"eyJhbGciOiJIUzI1NiIsImtpZCI6Imp3dF9zeW1tZXRyaWNfa2V5X2RldiJ9.eyJjbGllbnRfaWQiOiJnUHI1ZjZmWWI4d21HQ01WNVlRSTZKMk5QQjlueUxaaSIsImV4cCI6MTUxMzExOTkxMiwic2NvcGUiOlsiZGF0YTpyZWFkIl0sImF1ZCI6Imh0dHBzOi8vYXV0b2Rlc2suY29tL2F1ZC9qd3RleHA2MCIsImp0aSI6ImtXN3dyZUVlU2VWd3lKVkJjVVlScmJXMEtyVzJ6VlNBN2UxcHFWVVpZOVlCdVlFZDdhWjZjSnBkQW9jOUNqUnMifQ.YIr4qcOE0eo3YLx6NAzVVDhSAHxYXKRNOl1gMJbLy3k\",\"token_type\":\"Bearer\",\"expires_in\":3599}\r\n"
91
+ http_version:
92
+ recorded_at: Tue, 12 Dec 2017 23:05:06 GMT
93
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,93 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://developer-dev.api.autodesk.com/authentication/v1/authenticate
6
+ body:
7
+ encoding: UTF-8
8
+ string: client_id=<CLIENT_ID>&client_secret=<CLIENT_SECRET>&grant_type=client_credentials
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Cache-Control:
24
+ - no-cache, no-store, no-store
25
+ Content-Security-Policy:
26
+ - referrer origin
27
+ Content-Type:
28
+ - application/json;charset=utf-8
29
+ Date:
30
+ - Tue, 12 Dec 2017 22:05:14 GMT
31
+ Expires:
32
+ - Thu, 01 Jan 1970 00:00:00 GMT
33
+ Pragma:
34
+ - no-cache
35
+ Set-Cookie:
36
+ - PF=eVeEbVLQnI3MRnJHwWB9G7;Path=/;Secure;HttpOnly
37
+ X-Frame-Options:
38
+ - SAMEORIGIN
39
+ Content-Length:
40
+ - '421'
41
+ Connection:
42
+ - keep-alive
43
+ body:
44
+ encoding: UTF-8
45
+ string: "{\"access_token\":\"eyJhbGciOiJIUzI1NiIsImtpZCI6Imp3dF9zeW1tZXRyaWNfa2V5X2RldiJ9.eyJjbGllbnRfaWQiOiJnUHI1ZjZmWWI4d21HQ01WNVlRSTZKMk5QQjlueUxaaSIsImV4cCI6MTUxMzExOTkxNCwic2NvcGUiOltdLCJhdWQiOiJodHRwczovL2F1dG9kZXNrLmNvbS9hdWQvand0ZXhwNjAiLCJqdGkiOiIwc0poTGUyeURtUnJOQXhuOXJ6WWtQQ0xaYVlMNE52cm9aRWVtZDJmWGhta0twOWRrOVhjMUFtSTBrczhJM05LIn0.iNulpKmOtL3uc5ld-BsloOCStyLylLCaJJmd7wA51o8\",\"token_type\":\"Bearer\",\"expires_in\":3599}\r\n"
46
+ http_version:
47
+ recorded_at: Tue, 12 Dec 2017 22:05:10 GMT
48
+ - request:
49
+ method: post
50
+ uri: https://developer-dev.api.autodesk.com/authentication/v1/authenticate
51
+ body:
52
+ encoding: UTF-8
53
+ string: client_id=<CLIENT_ID>&client_secret=<CLIENT_SECRET>&grant_type=client_credentials
54
+ headers:
55
+ User-Agent:
56
+ - Faraday v0.9.2
57
+ Content-Type:
58
+ - application/x-www-form-urlencoded
59
+ Accept-Encoding:
60
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
61
+ Accept:
62
+ - "*/*"
63
+ response:
64
+ status:
65
+ code: 200
66
+ message: OK
67
+ headers:
68
+ Cache-Control:
69
+ - no-cache, no-store, no-store
70
+ Content-Security-Policy:
71
+ - referrer origin
72
+ Content-Type:
73
+ - application/json;charset=utf-8
74
+ Date:
75
+ - Tue, 12 Dec 2017 22:05:17 GMT
76
+ Expires:
77
+ - Thu, 01 Jan 1970 00:00:00 GMT
78
+ Pragma:
79
+ - no-cache
80
+ Set-Cookie:
81
+ - PF=1M4yehhhrLaKwhSLNIYD5F;Path=/;Secure;HttpOnly
82
+ X-Frame-Options:
83
+ - SAMEORIGIN
84
+ Content-Length:
85
+ - '421'
86
+ Connection:
87
+ - keep-alive
88
+ body:
89
+ encoding: UTF-8
90
+ string: "{\"access_token\":\"eyJhbGciOiJIUzI1NiIsImtpZCI6Imp3dF9zeW1tZXRyaWNfa2V5X2RldiJ9.eyJjbGllbnRfaWQiOiJnUHI1ZjZmWWI4d21HQ01WNVlRSTZKMk5QQjlueUxaaSIsImV4cCI6MTUxMzExOTkxNywic2NvcGUiOltdLCJhdWQiOiJodHRwczovL2F1dG9kZXNrLmNvbS9hdWQvand0ZXhwNjAiLCJqdGkiOiJxSTRDYWNGRkV3NEdkeHdmRkVTbWx2eG9WWVFtNjZaVU02WnBZbTkzYkV6M0NqdVBDV0k0UllobDRaeGx5OXVHIn0.V8FH6ea_FnhEVLXMoPgTodqugIYoGNhV8NN6sZtN6mQ\",\"token_type\":\"Bearer\",\"expires_in\":3599}\r\n"
91
+ http_version:
92
+ recorded_at: Tue, 12 Dec 2017 23:05:11 GMT
93
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://developer-dev.api.autodesk.com/authentication/v1/authenticate
6
+ body:
7
+ encoding: UTF-8
8
+ string: client_id=<CLIENT_ID>&client_secret=<CLIENT_SECRET>&grant_type=client_credentials&scope=data%3Aread
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Cache-Control:
24
+ - no-cache, no-store, no-store
25
+ Content-Security-Policy:
26
+ - referrer origin
27
+ Content-Type:
28
+ - application/json;charset=utf-8
29
+ Date:
30
+ - Tue, 12 Dec 2017 22:05:05 GMT
31
+ Expires:
32
+ - Thu, 01 Jan 1970 00:00:00 GMT
33
+ Pragma:
34
+ - no-cache
35
+ Set-Cookie:
36
+ - PF=Tizm0zBZtFVYPBL1eOvRzr;Path=/;Secure;HttpOnly
37
+ X-Frame-Options:
38
+ - SAMEORIGIN
39
+ Content-Length:
40
+ - '436'
41
+ Connection:
42
+ - keep-alive
43
+ body:
44
+ encoding: UTF-8
45
+ string: "{\"access_token\":\"eyJhbGciOiJIUzI1NiIsImtpZCI6Imp3dF9zeW1tZXRyaWNfa2V5X2RldiJ9.eyJjbGllbnRfaWQiOiJnUHI1ZjZmWWI4d21HQ01WNVlRSTZKMk5QQjlueUxaaSIsImV4cCI6MTUxMzExOTkwNSwic2NvcGUiOlsiZGF0YTpyZWFkIl0sImF1ZCI6Imh0dHBzOi8vYXV0b2Rlc2suY29tL2F1ZC9qd3RleHA2MCIsImp0aSI6IlhYRThjMkY0T2ZuNHMzZEljVjVsSDIwcFJFTUZ4Q09zMFpJS2cwNkdPU0p4R3NENThyZVpYOW1kRjh4Wm84cloifQ.Ai-drdCcT7ZmInJsnj8X3J2UquypLqb5ow2OsZWyLmo\",\"token_type\":\"Bearer\",\"expires_in\":3599}\r\n"
46
+ http_version:
47
+ recorded_at: Tue, 12 Dec 2017 22:05:00 GMT
48
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://developer-dev.api.autodesk.com/authentication/v1/authenticate
6
+ body:
7
+ encoding: UTF-8
8
+ string: client_id=<CLIENT_ID>&client_secret=<CLIENT_SECRET>&grant_type=client_credentials
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Cache-Control:
24
+ - no-cache, no-store, no-store
25
+ Content-Security-Policy:
26
+ - referrer origin
27
+ Content-Type:
28
+ - application/json;charset=utf-8
29
+ Date:
30
+ - Tue, 12 Dec 2017 22:05:07 GMT
31
+ Expires:
32
+ - Thu, 01 Jan 1970 00:00:00 GMT
33
+ Pragma:
34
+ - no-cache
35
+ Set-Cookie:
36
+ - PF=JQhcqstAiKP0OnQ50HZzOE;Path=/;Secure;HttpOnly
37
+ X-Frame-Options:
38
+ - SAMEORIGIN
39
+ Content-Length:
40
+ - '421'
41
+ Connection:
42
+ - keep-alive
43
+ body:
44
+ encoding: UTF-8
45
+ string: "{\"access_token\":\"eyJhbGciOiJIUzI1NiIsImtpZCI6Imp3dF9zeW1tZXRyaWNfa2V5X2RldiJ9.eyJjbGllbnRfaWQiOiJnUHI1ZjZmWWI4d21HQ01WNVlRSTZKMk5QQjlueUxaaSIsImV4cCI6MTUxMzExOTkwNywic2NvcGUiOltdLCJhdWQiOiJodHRwczovL2F1dG9kZXNrLmNvbS9hdWQvand0ZXhwNjAiLCJqdGkiOiJJSDZQdmdxbXRXR2xRV0dzQ21hMGVqSUhUM3ZkSlAwTEV1bE9UU3l3NktNbTZ4TTRienVWaGdIbzNyU1ZRWU9oIn0.Yzbev_rP-QQCnHv-_UlpGWJQeWKPJsYfyBn-PcTUVto\",\"token_type\":\"Bearer\",\"expires_in\":3599}\r\n"
46
+ http_version:
47
+ recorded_at: Tue, 12 Dec 2017 22:05:02 GMT
48
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "forge_auth"
6
+ s.version = "0.0.1"
7
+ s.authors = ["Nir Levi"]
8
+ s.email = ["nir.levi@autodesk.com"]
9
+ s.homepage = "https://git.autodesk.com/BIM360/forge_auth"
10
+ s.summary = "A simple Forge authentication client"
11
+ s.description = "A simple Forge authentication client"
12
+
13
+ s.rubyforge_project = "forge_auth"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency "faraday", "= 0.9.2"
21
+ s.add_dependency "faraday-detailed_logger", "~> 1.0"
22
+ s.add_dependency "faraday_middleware", "~> 0.10"
23
+
24
+ s.add_development_dependency "rspec", "~> 3.4"
25
+ s.add_development_dependency "pry-nav"
26
+ s.add_development_dependency "activesupport"
27
+ s.add_development_dependency "vcr", "~> 3.0"
28
+ s.add_development_dependency "webmock", "~> 2.0"
29
+ end
@@ -0,0 +1,21 @@
1
+ module ForgeAuth
2
+ class Token
3
+ EXPIRATION_BUFFER = 0.05 # 5% buffer
4
+
5
+ attr_reader :access_token, :token_type, :expires_in
6
+
7
+ def initialize(access_token:, token_type:, expires_in:)
8
+ @access_token = access_token
9
+ @token_type = token_type
10
+ @expires_in = expires_in
11
+ end
12
+
13
+ def full_token
14
+ "#{token_type} #{access_token}"
15
+ end
16
+
17
+ def short_expiration
18
+ @short_expiration ||= expires_in * (1 - EXPIRATION_BUFFER)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,68 @@
1
+ require "faraday"
2
+ require "faraday/detailed_logger"
3
+ require "faraday_middleware"
4
+
5
+ module ForgeAuth
6
+ class Tokenizer
7
+ def initialize(auth_host:, auth_path:, client_id:, client_secret:, grant_type: "client_credentials", cache: nil, scope: nil, logger: nil)
8
+ @auth_host = auth_host
9
+ @auth_path = auth_path
10
+ @cache = cache
11
+ @logger = logger
12
+ @params = { client_id: client_id,
13
+ client_secret: client_secret,
14
+ scope: scope,
15
+ grant_type: grant_type }
16
+
17
+ @params.delete(:scope) unless scope
18
+ end
19
+
20
+ def get_token
21
+ if with_cache?
22
+ token = @cache.fetch(cache_key)
23
+ return token if token
24
+
25
+ token = get_token_from_remote
26
+ @cache.write(cache_key, token, expires_in: token.short_expiration)
27
+ token
28
+ else
29
+ get_token_from_remote
30
+ end
31
+ rescue => exc
32
+ handle_error(exc)
33
+ end
34
+
35
+ private
36
+
37
+ def handle_error(exc)
38
+ if @logger
39
+ @logger.info "[Tokenizer] - #{exc}"
40
+ end
41
+
42
+ raise exc
43
+ end
44
+
45
+ def with_cache?
46
+ @cache
47
+ end
48
+
49
+ def cache_key
50
+ @params.values.unshift(@auth_url).join('_')
51
+ end
52
+
53
+ def connection
54
+ Faraday.new(url: @auth_host) do |faraday|
55
+ faraday.request :url_encoded
56
+ faraday.adapter :net_http
57
+ faraday.response :json
58
+ faraday.response :detailed_logger, @logger if @logger
59
+ end
60
+ end
61
+
62
+ def get_token_from_remote
63
+ raw_token_data = connection.post(@auth_path, @params).body
64
+ raw_token_data = Hash[raw_token_data.map { |(k, v)| [k.to_sym, v] }]
65
+ ForgeAuth::Token.new(**raw_token_data)
66
+ end
67
+ end
68
+ end
data/lib/forge_auth.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'forge_auth/tokenizer'
2
+ require 'forge_auth/token'
@@ -0,0 +1,23 @@
1
+ require 'rspec'
2
+ require 'vcr'
3
+ require 'forge_auth'
4
+ require 'pry-nav'
5
+ require 'active_support'
6
+
7
+ def test_cache
8
+ ActiveSupport::Cache::MemoryStore.new
9
+ end
10
+
11
+ VCR.configure do |config|
12
+ config.cassette_library_dir = "fixtures/vcr_cassettes"
13
+ config.hook_into :webmock
14
+ config.configure_rspec_metadata!
15
+ config.allow_http_connections_when_no_cassette = false
16
+ config.filter_sensitive_data("<CLIENT_ID>") { ENV['CLIENT_ID'] }
17
+ config.filter_sensitive_data("<CLIENT_SECRET>") { ENV['CLIENT_SECRET'] }
18
+ config.default_cassette_options = {
19
+ erb: true,
20
+ record: :none,
21
+ match_requests_on: [:method, :uri, :body, :headers]
22
+ }
23
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ describe ForgeAuth::Tokenizer do
4
+ let(:base_params) do
5
+ {
6
+ auth_host: 'https://developer-dev.api.autodesk.com',
7
+ auth_path: '/authentication/v1/authenticate',
8
+ client_id: ENV['CLIENT_ID'],
9
+ client_secret: ENV['CLIENT_SECRET']
10
+ }
11
+ end
12
+
13
+ def test_token(token)
14
+ expect(token).to be_a ForgeAuth::Token
15
+ expect(token.token_type).to be_a String
16
+ expect(token.access_token).to be_a String
17
+ expect(token.full_token).to eq "#{token.token_type} #{token.access_token}"
18
+ expect(token.expires_in).to be_a Integer
19
+ expect(token.short_expiration).to eq 0.95 * token.expires_in
20
+ end
21
+
22
+ describe ".get_token" do
23
+ context "without cache" do
24
+ shared_examples "fetches a token" do
25
+ it "returns a token" do
26
+ token = tokenizer.get_token
27
+
28
+ test_token(token)
29
+ end
30
+ end
31
+
32
+ context "with scope", vcr: { cassette_name: "tokenizer/current_with_scope" } do
33
+ let(:tokenizer) { ForgeAuth::Tokenizer.new base_params.merge(scope: 'data:read') }
34
+
35
+ it_behaves_like "fetches a token"
36
+ end
37
+ context "without scope", vcr: { cassette_name: "tokenizer/current_without_scope" } do
38
+ let(:tokenizer) { ForgeAuth::Tokenizer.new(base_params) }
39
+
40
+ it_behaves_like "fetches a token"
41
+ end
42
+ end
43
+ context "with cache" do
44
+ shared_examples "fetches a token with cache" do
45
+ it "uses the cache" do
46
+ #first call - from remote
47
+ expect(tokenizer).to receive(:get_token_from_remote).and_call_original
48
+ token = tokenizer.get_token
49
+ test_token(token)
50
+
51
+ #second call - from cache
52
+ expect(tokenizer).to_not receive(:get_token_from_remote)
53
+ token = tokenizer.get_token
54
+ test_token(token)
55
+
56
+ #After cache expiration
57
+ RSpec::Mocks.space.proxy_for(tokenizer).reset
58
+ allow(Time).to receive(:now).and_wrap_original { |m| m.call + token.expires_in }
59
+ expect(tokenizer).to receive(:get_token_from_remote).and_call_original
60
+ token = tokenizer.get_token
61
+ test_token(token)
62
+ end
63
+ end
64
+
65
+ context "with scope", vcr: { cassette_name: "tokenizer/cached_current_with_scope" } do
66
+ let(:tokenizer) { ForgeAuth::Tokenizer.new base_params.merge(cache: test_cache, scope: 'data:read') }
67
+
68
+ it_behaves_like "fetches a token with cache"
69
+ end
70
+ context "without scope", vcr: { cassette_name: "tokenizer/cached_current_without_scope" } do
71
+ let(:tokenizer) { ForgeAuth::Tokenizer.new base_params.merge(cache: test_cache) }
72
+
73
+ it_behaves_like "fetches a token with cache"
74
+ end
75
+ end
76
+ context "when error is raised" do
77
+ let(:logger) { double("Logger") }
78
+ let(:tokenizer) { ForgeAuth::Tokenizer.new base_params.merge(logger: logger) }
79
+
80
+ it "logs the error" do
81
+ allow(tokenizer).to receive(:get_token_from_remote).and_raise "MAGA"
82
+ expect(logger).to receive(:info).with("[Tokenizer] - MAGA")
83
+ expect { tokenizer.get_token }.to raise_error "MAGA"
84
+ end
85
+ end
86
+ end
87
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: forge_auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nir Levi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday-detailed_logger
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.10'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-nav
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.0'
125
+ description: A simple Forge authentication client
126
+ email:
127
+ - nir.levi@autodesk.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - Gemfile
134
+ - fixtures/vcr_cassettes/tokenizer/cached_current_with_scope.yml
135
+ - fixtures/vcr_cassettes/tokenizer/cached_current_without_scope.yml
136
+ - fixtures/vcr_cassettes/tokenizer/current_with_scope.yml
137
+ - fixtures/vcr_cassettes/tokenizer/current_without_scope.yml
138
+ - forge_auth.gemspec
139
+ - lib/forge_auth.rb
140
+ - lib/forge_auth/token.rb
141
+ - lib/forge_auth/tokenizer.rb
142
+ - spec/spec_helper.rb
143
+ - spec/tokenizer_spec.rb
144
+ homepage: https://git.autodesk.com/BIM360/forge_auth
145
+ licenses: []
146
+ metadata: {}
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project: forge_auth
163
+ rubygems_version: 2.6.10
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: A simple Forge authentication client
167
+ test_files:
168
+ - spec/spec_helper.rb
169
+ - spec/tokenizer_spec.rb