2017-08-30 00:49:07 +08:00
|
|
|
module ApiHelper
|
|
|
|
def generate_token(user_id)
|
2018-10-28 21:34:51 +08:00
|
|
|
Api::CoreJwt.encode(sub: user_id)
|
2017-08-30 00:49:07 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def generate_expired_token(user_id)
|
2018-10-28 21:34:51 +08:00
|
|
|
Api::CoreJwt.encode({ sub: user_id }, (Time.now.to_i - 300))
|
2017-08-30 00:49:07 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def decode_token(token)
|
2018-10-28 21:34:51 +08:00
|
|
|
Api::CoreJwt.decode(token)['sub'].to_i
|
2017-08-30 00:49:07 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def json
|
2018-07-31 19:40:27 +08:00
|
|
|
ActiveSupport::HashWithIndifferentAccess.new(JSON.parse(response.body))
|
2017-08-30 00:49:07 +08:00
|
|
|
end
|
|
|
|
end
|