From 663a6d5c33f458751258b4e3aceed111dbb77253 Mon Sep 17 00:00:00 2001 From: Bilal Date: Mon, 24 Aug 2020 14:33:59 +0300 Subject: [PATCH 1/3] add remember_me token --- app/controllers/api/user_token_controller.rb | 5 ++++- db/structure.sql | 17 +++-------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/user_token_controller.rb b/app/controllers/api/user_token_controller.rb index cae81f9..6d21b38 100644 --- a/app/controllers/api/user_token_controller.rb +++ b/app/controllers/api/user_token_controller.rb @@ -4,6 +4,7 @@ require './lib/knock_monkeypatch' class Api::UserTokenController < Knock::AuthTokenController include Oath::ControllerHelpers + include RememberMe::Controller skip_before_action :verify_authenticity_token before_action :sign_in_user @@ -46,6 +47,8 @@ class Api::UserTokenController < Knock::AuthTokenController private def sign_in_user - sign_in(entity) + if sign_in(entity) + remember_me(entity) + end end end diff --git a/db/structure.sql b/db/structure.sql index 6fa0d3d..9c06dc7 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -9,20 +9,6 @@ SET xmloption = content; SET client_min_messages = warning; SET row_security = off; --- --- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: - --- - -CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; - - --- --- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: - --- - -COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; - - -- -- Name: fuzzystrmatch; Type: EXTENSION; Schema: -; Owner: - -- @@ -1503,6 +1489,7 @@ CREATE TABLE public.settings ( -- CREATE SEQUENCE public.settings_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1538,6 +1525,7 @@ CREATE TABLE public.taggings ( -- CREATE SEQUENCE public.taggings_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE @@ -1568,6 +1556,7 @@ CREATE TABLE public.tags ( -- CREATE SEQUENCE public.tags_id_seq + AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE -- 2.47.3 From 01da597f3e17c519ffc403026994efb2ff63200d Mon Sep 17 00:00:00 2001 From: Bilal Date: Mon, 24 Aug 2020 14:35:54 +0300 Subject: [PATCH 2/3] modify specs --- spec/controllers/api/user_token_controller_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/controllers/api/user_token_controller_spec.rb b/spec/controllers/api/user_token_controller_spec.rb index cb01e35..5b88d36 100644 --- a/spec/controllers/api/user_token_controller_spec.rb +++ b/spec/controllers/api/user_token_controller_spec.rb @@ -13,6 +13,7 @@ RSpec.describe Api::UserTokenController, type: :request do expect(response).to be_successful expect(response.body).to match record_not_found expect(cookie_data).to eq nil + expect(rtfuser_cookie).to eq nil end it 'sends token and cookie if credentials are correct' do @@ -22,6 +23,7 @@ RSpec.describe Api::UserTokenController, type: :request do expect(response.body).not_to match record_not_found expect(response.body).to match token_response expect(cookie_data).not_to eq nil + expect(rtfuser_cookie).not_to eq nil end end @@ -60,4 +62,8 @@ RSpec.describe Api::UserTokenController, type: :request do def cookie_data cookies[:_easy_release_session] end + + def rtfuser_cookie + cookies[:_rtfuser] + end end -- 2.47.3 From 14445aeb141e5fb9a41dfcb1e0e33ead6af0fedc Mon Sep 17 00:00:00 2001 From: Bilal Date: Mon, 24 Aug 2020 16:42:47 +0300 Subject: [PATCH 3/3] do not use remember_me, set cookie expiration --- app/controllers/api/user_token_controller.rb | 4 +--- config/initializers/session_cookie.rb | 1 + spec/controllers/api/user_token_controller_spec.rb | 6 ------ 3 files changed, 2 insertions(+), 9 deletions(-) create mode 100644 config/initializers/session_cookie.rb diff --git a/app/controllers/api/user_token_controller.rb b/app/controllers/api/user_token_controller.rb index 6d21b38..2f64c9e 100644 --- a/app/controllers/api/user_token_controller.rb +++ b/app/controllers/api/user_token_controller.rb @@ -47,8 +47,6 @@ class Api::UserTokenController < Knock::AuthTokenController private def sign_in_user - if sign_in(entity) - remember_me(entity) - end + sign_in(entity) end end diff --git a/config/initializers/session_cookie.rb b/config/initializers/session_cookie.rb new file mode 100644 index 0000000..4caf103 --- /dev/null +++ b/config/initializers/session_cookie.rb @@ -0,0 +1 @@ +Rails.application.config.session_store :cookie_store, key: '_easy_release_session', expire_after: 1.month \ No newline at end of file diff --git a/spec/controllers/api/user_token_controller_spec.rb b/spec/controllers/api/user_token_controller_spec.rb index 5b88d36..cb01e35 100644 --- a/spec/controllers/api/user_token_controller_spec.rb +++ b/spec/controllers/api/user_token_controller_spec.rb @@ -13,7 +13,6 @@ RSpec.describe Api::UserTokenController, type: :request do expect(response).to be_successful expect(response.body).to match record_not_found expect(cookie_data).to eq nil - expect(rtfuser_cookie).to eq nil end it 'sends token and cookie if credentials are correct' do @@ -23,7 +22,6 @@ RSpec.describe Api::UserTokenController, type: :request do expect(response.body).not_to match record_not_found expect(response.body).to match token_response expect(cookie_data).not_to eq nil - expect(rtfuser_cookie).not_to eq nil end end @@ -62,8 +60,4 @@ RSpec.describe Api::UserTokenController, type: :request do def cookie_data cookies[:_easy_release_session] end - - def rtfuser_cookie - cookies[:_rtfuser] - end end -- 2.47.3