Class: Monban::Domain::Auth::Decoder

Inherits:
Object
  • Object
show all
Includes:
Getto::InitializeWith, Claim
Defined in:
lib/monban/domain/auth.rb

Instance Method Summary collapse

Methods included from Claim

#authy_roles, #iss

Instance Method Details

#decode(token, type:, roles:) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/monban/domain/auth.rb', line 100

def decode(token, type:, roles:)
  case type
  when :full
    full_format ::JWT.decode(
      token,
      jwt_secret,
      true,

      algorithm: jwt_algorithm,

      verify_iss: true, iss: iss(type),
      verify_iat: true,
      verify_sub: true,

      verify_aud: !!roles, aud: ([*roles] + allow_full_access).map(&:to_s),
    )
  when :authy
    authy_format ::JWT.decode(
      token,
      jwt_secret,
      true,

      algorithm: jwt_algorithm,

      verify_iss: true, iss: iss(type),
      verify_iat: true,
      verify_sub: true,

      verify_aud: roles[:only_registered], aud: authy_roles.first,
    )
  when :reset
    reset_format ::JWT.decode(
      token,
      jwt_secret,
      true,

      algorithm: jwt_algorithm,

      verify_iss: true, iss: iss(type),
      verify_sub: true,
      verify_iat: true,
    )
  else
    raise SettingError, "decode: invalid type: #{type}"
  end
rescue ::JWT::DecodeError => e
  error! e.message
end