lib/jwt_keeper/controller.rb in jwt_keeper-3.3.0 vs lib/jwt_keeper/controller.rb in jwt_keeper-4.0.0
- old
+ new
@@ -27,28 +27,28 @@
def read_authentication_token
return nil unless request.headers['Authorization']
@authentication_token ||=
JWTKeeper::Token.find(
request.headers['Authorization'].split.last,
- cookies.signed['jwt_keeper']
+ defined?(cookies) && cookies.signed['jwt_keeper']
)
end
# Encodes and writes the token
# @param token [Token] The token to be written
# @return [Token] the token written to response
def write_authentication_token(token)
return clear_authentication_token if token.nil?
response.headers['Authorization'] = "Bearer #{token.to_jwt}"
- cookies.signed['jwt_keeper'] = token.to_cookie
+ defined?(cookies) && cookies.signed['jwt_keeper'] = token.to_cookie
@authentication_token = token
end
# delets the authentication token
# @return [void]
def clear_authentication_token
response.headers['Authorization'] = nil
- cookies.delete('jwt_keeper')
+ defined?(cookies) && cookies.delete('jwt_keeper')
@authentication_token = nil
end
# The default action for denying non-authenticated connections.
# You can override this method in your controllers