Module: JwtHelper

Extended by:
JwtHelper
Included in:
JwtHelper
Defined in:
app/models/concerns/jwt_helper.rb

Instance Method Summary collapse

Instance Method Details

#decode_without_verification(token) ⇒ Object



21
22
23
24
25
26
27
28
# File 'app/models/concerns/jwt_helper.rb', line 21

def decode_without_verification(token)
  begin
    payload, _ = JWT.decode(token, nil, false, verify_expiration: false)
    payload
  rescue => e
    puts nil, e.full_message(highlight: true, order: :top)
  end
end

#generate_jwt_token(iss, key, options = {}) ⇒ Object

模型需要定义属性 iss(issuer) 比如鉴权唯一标识 id, AppID key 比如 password_digest, AppSecret sub: ‘auth’ exp: auth_token_expired_at, should be int algorithm: 默认HS256



11
12
13
14
15
16
17
18
19
# File 'app/models/concerns/jwt_helper.rb', line 11

def generate_jwt_token(iss, key, options = {})
  payload = {
    iss: iss,
  }

  payload.merge! options

  JWT.encode(payload, key.to_s)
end