Skip to content

Commit 8fcf9d4

Browse files
DrRaiderarnaudbesnier
authored andcommitted
fix(auth): support multi-instances and remove auth's redirection (#407)
1 parent 39d9f5b commit 8fcf9d4

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
forest_liana (6.0.0-beta.3)
4+
forest_liana (6.0.0.pre.beta.3)
55
arel-helpers
66
base32
77
bcrypt

app/controllers/forest_liana/authentication_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def start_authentication
4646
{ 'renderingId' => rendering_id },
4747
)
4848

49-
redirect_to(result['authorization_url'])
49+
render json: { authorizationUrl: result['authorization_url']}, status: 200
5050
rescue => error
5151
render json: { errors: [{ status: 500, detail: error.message }] },
5252
status: :internal_server_error, serializer: nil

app/services/forest_liana/oidc_client_manager.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ def self.get_client_for_callback_url(callback_url)
88
if client_data.nil?
99
configuration = ForestLiana::OidcConfigurationRetriever.retrieve()
1010

11-
client_credentials = ForestLiana::OidcDynamicClientRegistrator.register({
12-
token_endpoint_auth_method: 'none',
13-
redirect_uris: [callback_url],
14-
registration_endpoint: configuration['registration_endpoint']
15-
})
11+
if ForestLiana.forest_client_id.nil?
12+
client_credentials = ForestLiana::OidcDynamicClientRegistrator.register({
13+
token_endpoint_auth_method: 'none',
14+
redirect_uris: [callback_url],
15+
registration_endpoint: configuration['registration_endpoint']
16+
})
17+
else
18+
client_credentials['client_id'] = ForestLiana.forest_client_id
19+
end
1620

1721
client_data = { :client_id => client_credentials['client_id'], :issuer => configuration['issuer'] }
1822
Rails.cache.write(callback_url, client_data)

lib/forest_liana.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module UserSpace
1616

1717
mattr_accessor :env_secret
1818
mattr_accessor :auth_secret
19+
mattr_accessor :forest_client_id
1920
mattr_accessor :application_url
2021
mattr_accessor :integrations
2122
mattr_accessor :apimap

spec/requests/authentications_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@
3333
}
3434
end
3535

36-
it "should respond with a 302 code" do
37-
expect(response).to have_http_status(302)
36+
it "should respond with a 200 code" do
37+
expect(response).to have_http_status(200)
3838
end
3939

4040
it "should return a valid authentication url" do
41-
expect(response.headers['Location']).to eq('https://api.forestadmin.com/oidc/auth?client_id=random_id&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fforest%2Fauthentication%2Fcallback&response_type=code&scope=openid%20email%20profile&state=%7B%22renderingId%22%3D%3E42%7D')
41+
body = JSON.parse(response.body, :symbolize_names => true)
42+
expect(body[:authorizationUrl]).to eq('https://api.forestadmin.com/oidc/auth?client_id=random_id&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fforest%2Fauthentication%2Fcallback&response_type=code&scope=openid%20email%20profile&state=%7B%22renderingId%22%3D%3E42%7D')
4243
end
4344
end
4445

test/services/forest_liana/resources_getter_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ class ResourcesGetterTest < ActiveSupport::TestCase
119119
records = getter.records
120120
count = getter.count
121121

122-
assert records.count == 1
123-
assert count = 1
122+
assert records.count == 2
123+
assert count = 2
124124
assert records.first.id == 4
125125
assert records.first.name == 'Oak'
126126
assert records.first.owner.name == 'Arnaud Besnier'

0 commit comments

Comments
 (0)