Class: Foobara::Auth::CreateToken
- Inherits:
-
Command
- Object
- Command
- Foobara::Auth::CreateToken
show all
- Defined in:
- foobara-auth-0.1.1/src/create_token.rb
Constant Summary
TruncatedInspect::MAX_LENGTH
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Command
install!
#inspect, truncating
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Instance Attribute Details
#build_password_params ⇒ Object
Returns the value of attribute build_password_params.
37
38
39
|
# File '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 '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 '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 '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 '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 'src/create_token.rb', line 37
def token_string
@token_string
end
|
Instance Method Details
#activate_token ⇒ Object
87
88
89
|
# File 'src/create_token.rb', line 87
def activate_token
token_record.approve!
end
|
#construct_token_string ⇒ Object
91
92
93
|
# File '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 '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 '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 '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 '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 '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 'src/create_token.rb', line 83
def needs_approval?
needs_approval
end
|
#other_params ⇒ Object
102
103
104
|
# File 'src/create_token.rb', line 102
def other_params
{ secret_bytes:, token_id_bytes: }
end
|
#secret_bytes ⇒ Object
54
55
56
|
# File 'src/create_token.rb', line 54
def secret_bytes
32
end
|
#token_id_bytes ⇒ Object
106
107
108
|
# File 'src/create_token.rb', line 106
def token_id_bytes
6
end
|
#token_string_and_record ⇒ Object
95
96
97
98
99
100
|
# File 'src/create_token.rb', line 95
def token_string_and_record
{
token_string:,
token_record:
}
end
|