Class: RobustServerSocket::ClientToken
- Inherits:
-
Object
- Object
- RobustServerSocket::ClientToken
- Defined in:
- lib/robust_server_socket/client_token.rb
Constant Summary collapse
- TOKEN_REGEXP =
/\A(.+)_(\d{10,})\z/.freeze
- InvalidToken =
Class.new(StandardError)
Class Method Summary collapse
Instance Method Summary collapse
- #client ⇒ Object
- #decrypted_token ⇒ Object
-
#initialize(secure_token) ⇒ ClientToken
constructor
A new instance of ClientToken.
- #modules_checks ⇒ Object
- #modules_checks! ⇒ Object
- #valid? ⇒ Boolean
- #validate! ⇒ Object
- #validate_decrypted_token ⇒ Object
Constructor Details
#initialize(secure_token) ⇒ ClientToken
Returns a new instance of ClientToken.
13 14 15 16 |
# File 'lib/robust_server_socket/client_token.rb', line 13 def initialize(secure_token) @secure_token = validate_secure_token_input(secure_token) @client = nil end |
Class Method Details
.validate!(secure_token) ⇒ Object
7 8 9 10 11 |
# File 'lib/robust_server_socket/client_token.rb', line 7 def self.validate!(secure_token) new(secure_token).tap do |instance| instance.validate! end end |
Instance Method Details
#client ⇒ Object
37 38 39 40 41 42 |
# File 'lib/robust_server_socket/client_token.rb', line 37 def client @client ||= begin target = client_name.strip allowed_clients.detect { |allowed| allowed.eql?(target) } end end |
#decrypted_token ⇒ Object
44 45 46 |
# File 'lib/robust_server_socket/client_token.rb', line 44 def decrypted_token @decrypted_token ||= SecureToken::Decrypt.call(@secure_token) end |
#modules_checks ⇒ Object
29 30 31 |
# File 'lib/robust_server_socket/client_token.rb', line 29 def modules_checks true end |
#modules_checks! ⇒ Object
33 34 35 |
# File 'lib/robust_server_socket/client_token.rb', line 33 def modules_checks! true end |
#valid? ⇒ Boolean
23 24 25 26 27 |
# File 'lib/robust_server_socket/client_token.rb', line 23 def valid? validate_decrypted_token && modules_checks rescue StandardError false end |
#validate! ⇒ Object
18 19 20 21 |
# File 'lib/robust_server_socket/client_token.rb', line 18 def validate! raise InvalidToken unless validate_decrypted_token modules_checks! end |
#validate_decrypted_token ⇒ Object
48 49 50 |
# File 'lib/robust_server_socket/client_token.rb', line 48 def validate_decrypted_token !!decrypted_token end |