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
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
9 10 11 |
# File 'lib/robust_server_socket/client_token.rb', line 9 def self.validate!(secure_token) new(secure_token).tap(&:validate!) end |
Instance Method Details
#client ⇒ Object
38 39 40 41 42 43 |
# File 'lib/robust_server_socket/client_token.rb', line 38 def client @client ||= begin target = client_name.strip allowed_clients.detect { |allowed| allowed.eql?(target) } end end |
#decrypted_token ⇒ Object
45 46 47 |
# File 'lib/robust_server_socket/client_token.rb', line 45 def decrypted_token @decrypted_token ||= SecureToken::Decrypt.call(@secure_token) end |
#modules_checks ⇒ Object
30 31 32 |
# File 'lib/robust_server_socket/client_token.rb', line 30 def modules_checks true end |
#modules_checks! ⇒ Object
34 35 36 |
# File 'lib/robust_server_socket/client_token.rb', line 34 def modules_checks! true end |
#valid? ⇒ Boolean
24 25 26 27 28 |
# File 'lib/robust_server_socket/client_token.rb', line 24 def valid? modules_checks rescue StandardError false end |
#validate! ⇒ Object
18 19 20 21 22 |
# File 'lib/robust_server_socket/client_token.rb', line 18 def validate! modules_checks! rescue SecureToken::InvalidToken => e raise InvalidToken, e. end |