lib/osso/helpers/auth.rb in osso-0.0.3.8 vs lib/osso/helpers/auth.rb in osso-0.0.3.9
- old
+ new
@@ -13,16 +13,11 @@
redirect ENV['JWT_URL']
end
def enterprise_authorized?(_domain)
- payload, _args = JWT.decode(
- token,
- ENV['JWT_HMAC_SECRET'],
- true,
- { algorithm: 'HS256' },
- )
+ payload, _args = decode(token)
@current_scope = payload['scope']
true
rescue JWT::DecodeError
@@ -34,16 +29,11 @@
redirect ENV['JWT_URL']
end
def admin_authorized?
- payload, _args = JWT.decode(
- token,
- ENV['JWT_HMAC_SECRET'],
- true,
- { algorithm: 'HS256' },
- )
+ payload, _args = decode(token)
if payload['scope'] == 'admin'
@current_scope = :admin
return true
end
@@ -63,9 +53,18 @@
session['admin_token'] = request['admin_token']
return if request.post?
redirect request.path
+ end
+
+ def decode(token)
+ JWT.decode(
+ token,
+ ENV['JWT_HMAC_SECRET'],
+ true,
+ { algorithm: 'HS256' },
+ )
end
end
end
end