Skip to content

Commit 033661f

Browse files
authored
fix(authentication): safari cannot login on remote lianas because of third party cookies (#435)
1 parent 1b6aa95 commit 033661f

File tree

2 files changed

+4
-34
lines changed

2 files changed

+4
-34
lines changed

app/controllers/forest_liana/authentication_controller.rb

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,12 @@ def authentication_callback
6161
callback_url,
6262
params,
6363
)
64-
65-
response.set_cookie(
66-
'forest_session_token',
67-
{
68-
value: token,
69-
httponly: true,
70-
secure: true,
71-
expires: ForestLiana::Token.expiration_in_days,
72-
same_site: :None,
73-
path: '/'
74-
},
75-
)
7664

7765
response_body = {
66+
token: token,
7867
tokenData: JWT.decode(token, ForestLiana.auth_secret, true, { algorithm: 'HS256' })[0]
7968
}
8069

81-
# The token is sent decoded, because we don't want to share the whole, signed token
82-
# that is used to authenticate people
83-
# but the token itself contains interesting values, such as its expiration date
84-
response_body[:token] = token if !ForestLiana.application_url.start_with?('https://')
85-
8670
render json: response_body, status: 200
8771

8872
rescue => error

spec/requests/authentications_spec.rb

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@
6060
end
6161

6262
it "should return a valid authentication token" do
63-
session_cookie = response.headers['set-cookie']
64-
expect(session_cookie).to match(/^forest_session_token=[^;]+; path=\/; expires=[^;]+; secure; HttpOnly; SameSite=None$/)
63+
body = JSON.parse(response.body, :symbolize_names => true);
6564

66-
token = session_cookie.match(/^forest_session_token=([^;]+);/)[1]
65+
token = body[:token]
6766
decoded = JWT.decode(token, ForestLiana.auth_secret, true, { algorithm: 'HS256' })[0]
6867

6968
expected_token_data = {
@@ -76,31 +75,18 @@
7675
}
7776

7877
expect(decoded).to include(expected_token_data)
79-
expect(JSON.parse(response.body, :symbolize_names => true)).to eq({ token: token, tokenData: decoded.deep_symbolize_keys! })
78+
expect(body).to eq({ token: token, tokenData: decoded.deep_symbolize_keys! })
8079
expect(response).to have_http_status(200)
8180
end
8281
end
8382

8483
describe "POST /authentication/logout" do
8584
before() do
86-
cookies['forest_session_token'] = {
87-
value: 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6NjY2LCJlbWFpbCI6ImFsaWNlQGZvcmVzdGFkbWluLmNvbSIsImZpcnN0X25hbWUiOiJBbGljZSIsImxhc3RfbmFtZSI6IkRvZSIsInRlYW0iOjEsInJlbmRlcmluZ19pZCI6IjQyIiwiZXhwIjoxNjA4MDQ5MTI2fQ.5xaMxjUjE3wKldBsj3wW0BP9GHnnMqQi2Kpde8cIHEw',
88-
path: '/',
89-
expires: Time.now.to_i + 14.days,
90-
secure: true,
91-
httponly: true
92-
}
9385
post ForestLiana::Engine.routes.url_helpers.authentication_logout_path, params: { :renderingId => 42 }, :headers => headers
94-
cookies.delete('forest_session_token')
9586
end
9687

9788
it "should respond with a 204 code" do
9889
expect(response).to have_http_status(204)
9990
end
100-
101-
it "should invalidate token from browser" do
102-
invalidated_session_cookie = response.headers['set-cookie']
103-
expect(invalidated_session_cookie).to match(/^forest_session_token=[^;]+; path=\/; expires=Thu, 01 Jan 1970 00:00:00 GMT; secure; HttpOnly; SameSite=None$/)
104-
end
10591
end
10692
end

0 commit comments

Comments
 (0)