Module: JwtHelper
Instance Method Summary collapse
- #decode_without_verification(token) ⇒ Object
-
#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.
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.(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, = {}) payload = { iss: iss, } payload.merge! JWT.encode(payload, key.to_s) end |