Class: Foobara::Auth::CreateToken
- Defined in:
- foobara-auth-0.0.9/src/create_token.rb
Constant Summary
Constants included from TruncatedInspect
Instance Attribute Summary collapse
-
#build_password_params ⇒ Object
Returns the value of attribute build_password_params.
-
#hashed_secret ⇒ Object
Returns the value of attribute hashed_secret.
-
#token_id ⇒ Object
Returns the value of attribute token_id.
-
#token_record ⇒ Object
Returns the value of attribute token_record.
-
#token_secret ⇒ Object
Returns the value of attribute token_secret.
-
#token_string ⇒ Object
Returns the value of attribute token_string.
Attributes included from CommandPatternImplementation::Concerns::Subcommands
Attributes included from CommandPatternImplementation::Concerns::Runtime
Attributes included from CommandPatternImplementation::Concerns::Errors
Attributes included from CommandPatternImplementation::Concerns::Inputs
Instance Method Summary collapse
- #activate_token ⇒ Object
- #construct_token_string ⇒ Object
- #create_token_record ⇒ Object
- #execute ⇒ Object
- #generate_hashed_secret ⇒ Object
- #generate_token_id ⇒ Object
- #generate_token_secret ⇒ Object
- #needs_approval? ⇒ Boolean
- #other_params ⇒ Object
- #secret_bytes ⇒ Object
- #token_id_bytes ⇒ Object
- #token_string_and_record ⇒ Object
Methods inherited from Command
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Methods included from CommandPatternImplementation::Concerns::Reflection
Methods included from CommandPatternImplementation::Concerns::DomainMappers
#domain_map, #domain_map!, #run_mapped_subcommand!
Methods included from CommandPatternImplementation::Concerns::Subcommands
#run_subcommand!, #subcommand?
Methods included from CommandPatternImplementation::Concerns::Entities
Methods included from CommandPatternImplementation::Concerns::Transactions
#auto_detect_current_transactions, #commit_transaction, #open_transaction, #opened_transactions, #relevant_entity_classes, #rollback_transaction, #transactions
Methods included from CommandPatternImplementation::Concerns::StateMachine
Methods included from CommandPatternImplementation::Concerns::Runtime
#halt!, #run, #run!, #run_execute, #succeed, #success?, #validate, #validate_records
Methods included from CommandPatternImplementation::Concerns::Errors
Methods included from CommandPatternImplementation::Concerns::Inputs
#cast_and_validate_inputs, #initialize, #method_missing, #respond_to_missing?, #respond_to_missing_for_inputs?
Methods included from TruncatedInspect
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Foobara::CommandPatternImplementation::Concerns::Inputs
Instance Attribute Details
#build_password_params ⇒ Object
Returns the value of attribute build_password_params.
37 38 39 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 37 def build_password_params @build_password_params end |
#hashed_secret ⇒ Object
Returns the value of attribute hashed_secret.
37 38 39 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 37 def hashed_secret @hashed_secret end |
#token_id ⇒ Object
Returns the value of attribute token_id.
37 38 39 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 37 def token_id @token_id end |
#token_record ⇒ Object
Returns the value of attribute token_record.
37 38 39 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 37 def token_record @token_record end |
#token_secret ⇒ Object
Returns the value of attribute token_secret.
37 38 39 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 37 def token_secret @token_secret end |
#token_string ⇒ Object
Returns the value of attribute token_string.
37 38 39 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 37 def token_string @token_string end |
Instance Method Details
#activate_token ⇒ Object
87 88 89 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 87 def activate_token token_record.approve! end |
#construct_token_string ⇒ Object
91 92 93 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 91 def construct_token_string self.token_string = "#{token_id}_#{token_secret}" end |
#create_token_record ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 64 def create_token_record attributes = { hashed_secret:, id: token_id, token_parameters: build_password_params.merge(other_params), created_at: Time.now } if expires_at attributes[:expires_at] = expires_at end if token_group attributes[:token_group] = token_group end self.token_record = Types::Token.create(attributes) end |
#execute ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 23 def execute generate_token_secret generate_hashed_secret generate_token_id construct_token_string create_token_record unless needs_approval? activate_token end token_string_and_record end |
#generate_hashed_secret ⇒ Object
58 59 60 61 62 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 58 def generate_hashed_secret secret = run_subcommand!(BuildSecret, secret: token_secret) self.hashed_secret = secret.hashed_secret self.build_password_params = secret.parameters end |
#generate_token_id ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 39 def generate_token_id bytes = SecureRandom.random_bytes(token_id_bytes) begin token_id = Base64.strict_encode64(bytes) end while Types::Token.exists?(token_id) self.token_id = token_id end |
#generate_token_secret ⇒ Object
49 50 51 52 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 49 def generate_token_secret bytes = SecureRandom.random_bytes(secret_bytes) self.token_secret = Base64.strict_encode64(bytes) end |
#needs_approval? ⇒ Boolean
83 84 85 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 83 def needs_approval? needs_approval end |
#other_params ⇒ Object
102 103 104 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 102 def other_params { secret_bytes:, token_id_bytes: } end |
#secret_bytes ⇒ Object
54 55 56 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 54 def secret_bytes 32 end |
#token_id_bytes ⇒ Object
106 107 108 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 106 def token_id_bytes 6 end |
#token_string_and_record ⇒ Object
95 96 97 98 99 100 |
# File 'foobara-auth-0.0.9/src/create_token.rb', line 95 def token_string_and_record { token_string:, token_record: } end |