Chatwoot/app/models/concerns/sso_authenticatable.rb
Sojan Jose a988724c91
feat: Authenticate by SSO tokens (#1439)
Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
2020-11-25 13:59:38 +05:30

23 lines
523 B
Ruby

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