feat: Authenticate by SSO tokens (#1439)

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
Sojan Jose
2020-11-25 13:59:38 +05:30
committed by GitHub
parent cb2a528be6
commit a988724c91
10 changed files with 147 additions and 8 deletions

View File

@@ -0,0 +1,23 @@
module SsoAuthenticatable
extend ActiveSupport::Concern
def generate_sso_auth_token
token = SecureRandom.hex(32)
::Redis::Alfred.setex(sso_token_key(token), true, 5.minutes)
token
end
def invalidate_sso_auth_token(token)
::Redis::Alfred.delete(sso_token_key(token))
end
def valid_sso_auth_token?(token)
::Redis::Alfred.get(sso_token_key(token)).present?
end
private
def sso_token_key(token)
format(::Redis::RedisKeys::USER_SSO_AUTH_TOKEN, user_id: id, token: token)
end
end

View File

@@ -98,7 +98,7 @@ class Conversation < ApplicationRecord
end
def muted?
!Redis::Alfred.get(mute_key).nil?
Redis::Alfred.get(mute_key).present?
end
def lock!
@@ -287,7 +287,7 @@ class Conversation < ApplicationRecord
end
def mute_key
format('CONVERSATION::%<id>d::MUTED', id: id)
format(Redis::RedisKeys::CONVERSATION_MUTE_KEY, id: id)
end
def mute_period

View File

@@ -44,6 +44,7 @@ class User < ApplicationRecord
include Pubsubable
include Rails.application.routes.url_helpers
include Reportable
include SsoAuthenticatable
devise :database_authenticatable,
:registerable,