feat: Authenticate by SSO tokens (#1439)
Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
23
app/models/concerns/sso_authenticatable.rb
Normal file
23
app/models/concerns/sso_authenticatable.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -44,6 +44,7 @@ class User < ApplicationRecord
|
||||
include Pubsubable
|
||||
include Rails.application.routes.url_helpers
|
||||
include Reportable
|
||||
include SsoAuthenticatable
|
||||
|
||||
devise :database_authenticatable,
|
||||
:registerable,
|
||||
|
||||
Reference in New Issue
Block a user