lib/rails/auth/credentials.rb in rails-auth-1.0.0 vs lib/rails/auth/credentials.rb in rails-auth-1.1.0
- old
+ new
@@ -23,10 +23,17 @@
# @param [Object] :credential object to add to the environment
#
def add_credential(env, type, credential)
credentials = env[CREDENTIALS_ENV_KEY] ||= {}
+ # Adding a credential is idempotent, so attempting to reregister
+ # the same credential should be harmless
+ return env if credentials.key?(type) && credentials[type] == credential
+
+ # raise if we already have a cred, but it didn't short-circuit as
+ # being == to the one supplied
raise ArgumentError, "credential #{type} already added to request" if credentials.key?(type)
+
credentials[type] = credential
env
end
end