forge_auth 0.0.2 → 0.0.3
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/fixtures/vcr_cassettes/tokenizer/invalid_client_id.yml +37 -0
- data/fixtures/vcr_cassettes/tokenizer/invalid_client_secret.yml +37 -0
- data/forge_auth.gemspec +1 -1
- data/lib/forge_auth.rb +2 -1
- data/lib/forge_auth/invalid_credentials_error.rb +4 -0
- data/lib/forge_auth/tokenizer.rb +11 -4
- data/spec/tokenizer_spec.rb +15 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1494abffde1497552453b684f4196918bf29aff5
|
4
|
+
data.tar.gz: 75644aa28ace3793b135c7f32595df71b718d35c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ddb3fff97198c4c39ae089b97abe28e28c3334cc0c10e27072d66bb08117c6a5c24bb017090bf8841a796da60d26b94115dc25fd976ff1383bab573b678fe16
|
7
|
+
data.tar.gz: 384dbeeeb2262153c08d45cfb144029d85cf7f1c6436ee100cc9c409672522201a69a59731737ded0be0bde0cba40530d8fb021ac13aa5925651f54ee6bac335
|
@@ -0,0 +1,37 @@
|
|
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=Marcos_mom&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: 403
|
21
|
+
message: Unauthorized
|
22
|
+
headers:
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
Date:
|
26
|
+
- Wed, 20 Dec 2017 10:10:26 GMT
|
27
|
+
Content-Length:
|
28
|
+
- '212'
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
body:
|
32
|
+
encoding: UTF-8
|
33
|
+
string: '{ "developerMessage":"The client_id specified does not have access
|
34
|
+
to the api product","userMessage":"","errorCode":"AUTH-001","more info":"http://developer-dev.api.autodesk.com/documentation/v1/errors/AUTH-001"}'
|
35
|
+
http_version:
|
36
|
+
recorded_at: Wed, 20 Dec 2017 10:10:20 GMT
|
37
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,37 @@
|
|
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=Marcos_mom&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: 401
|
21
|
+
message: Unauthorized
|
22
|
+
headers:
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
Date:
|
26
|
+
- Wed, 20 Dec 2017 10:10:26 GMT
|
27
|
+
Content-Length:
|
28
|
+
- '207'
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
body:
|
32
|
+
encoding: UTF-8
|
33
|
+
string: '{"developerMessage":"The client_id (application key)/client_secret
|
34
|
+
are not valid","userMessage":"","errorCode":"AUTH-003","more info":"http://developer-dev.api.autodesk.com/documentation/v1/errors/AUTH-003"}'
|
35
|
+
http_version:
|
36
|
+
recorded_at: Wed, 20 Dec 2017 10:10:21 GMT
|
37
|
+
recorded_with: VCR 3.0.3
|
data/forge_auth.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "forge_auth"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.3"
|
7
7
|
s.authors = ["Nir Levi"]
|
8
8
|
s.email = ["nir.levi@autodesk.com"]
|
9
9
|
s.homepage = "https://git.autodesk.com/BIM360/forge_auth"
|
data/lib/forge_auth.rb
CHANGED
data/lib/forge_auth/tokenizer.rb
CHANGED
@@ -3,7 +3,7 @@ require "faraday/detailed_logger"
|
|
3
3
|
require "faraday_middleware"
|
4
4
|
|
5
5
|
module ForgeAuth
|
6
|
-
class Tokenizer
|
6
|
+
class Tokenizer
|
7
7
|
def initialize(auth_host:, auth_path:, client_id:, client_secret:, grant_type: "client_credentials", cache: nil, scope: nil, logger: nil)
|
8
8
|
@auth_host = auth_host
|
9
9
|
@auth_path = auth_path
|
@@ -68,9 +68,16 @@ module ForgeAuth
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def get_token_from_remote
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
response = connection.post(@auth_path, @params)
|
72
|
+
if response.status == 200
|
73
|
+
raw_token_data = response.body
|
74
|
+
raw_token_data = Hash[raw_token_data.map { |(k, v)| [k.to_sym, v] }]
|
75
|
+
ForgeAuth::Token.new(**raw_token_data)
|
76
|
+
elsif [401, 403].include?(response.status)
|
77
|
+
err_msg = "Invalid credentials! \n#{response.body}"
|
78
|
+
@logger.info "[Tokenizer] - #{err_msg}" if @logger
|
79
|
+
raise ForgeAuth::InvalidCredentialsError, err_msg
|
80
|
+
end
|
74
81
|
end
|
75
82
|
end
|
76
83
|
end
|
data/spec/tokenizer_spec.rb
CHANGED
@@ -73,6 +73,21 @@ describe ForgeAuth::Tokenizer do
|
|
73
73
|
it_behaves_like "fetches a token with cache"
|
74
74
|
end
|
75
75
|
end
|
76
|
+
context "with wrong credentials" do
|
77
|
+
shared_examples "raises error" do
|
78
|
+
it "raises InvalidCredentialsError" do
|
79
|
+
expect { tokenizer.get_token }.to raise_error ForgeAuth::InvalidCredentialsError, /Invalid credentials/
|
80
|
+
end
|
81
|
+
end
|
82
|
+
context "with invalid client id", vcr: { cassette_name: "tokenizer/invalid_client_id" } do
|
83
|
+
let(:tokenizer) { ForgeAuth::Tokenizer.new base_params.merge(client_id: "Marcos_mom") }
|
84
|
+
it_behaves_like "raises error"
|
85
|
+
end
|
86
|
+
context "with invalid client secret", vcr: { cassette_name: "tokenizer/invalid_client_secret" } do
|
87
|
+
let(:tokenizer) { ForgeAuth::Tokenizer.new base_params.merge(client_secret: "Marcos_mom") }
|
88
|
+
it_behaves_like "raises error"
|
89
|
+
end
|
90
|
+
end
|
76
91
|
context "when error is raised" do
|
77
92
|
let(:logger) { double("Logger") }
|
78
93
|
let(:tokenizer) { ForgeAuth::Tokenizer.new base_params.merge(logger: logger) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forge_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nir Levi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -135,8 +135,11 @@ files:
|
|
135
135
|
- fixtures/vcr_cassettes/tokenizer/cached_current_without_scope.yml
|
136
136
|
- fixtures/vcr_cassettes/tokenizer/current_with_scope.yml
|
137
137
|
- fixtures/vcr_cassettes/tokenizer/current_without_scope.yml
|
138
|
+
- fixtures/vcr_cassettes/tokenizer/invalid_client_id.yml
|
139
|
+
- fixtures/vcr_cassettes/tokenizer/invalid_client_secret.yml
|
138
140
|
- forge_auth.gemspec
|
139
141
|
- lib/forge_auth.rb
|
142
|
+
- lib/forge_auth/invalid_credentials_error.rb
|
140
143
|
- lib/forge_auth/token.rb
|
141
144
|
- lib/forge_auth/tokenizer.rb
|
142
145
|
- spec/spec_helper.rb
|