Commit 74c79123 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'ce-jej/group-saml-discovery-token' into 'master'

TokenAuthenticatable allows non-unique tokens

See merge request gitlab-org/gitlab-ce!22748
parents 9b1a112c 69b9a879
...@@ -10,6 +10,7 @@ module TokenAuthenticatable ...@@ -10,6 +10,7 @@ module TokenAuthenticatable
def add_authentication_token_field(token_field, options = {}) def add_authentication_token_field(token_field, options = {})
@token_fields = [] unless @token_fields @token_fields = [] unless @token_fields
unique = options.fetch(:unique, true)
if @token_fields.include?(token_field) if @token_fields.include?(token_field)
raise ArgumentError.new("#{token_field} already configured via add_authentication_token_field") raise ArgumentError.new("#{token_field} already configured via add_authentication_token_field")
...@@ -25,9 +26,11 @@ module TokenAuthenticatable ...@@ -25,9 +26,11 @@ module TokenAuthenticatable
TokenAuthenticatableStrategies::Insecure.new(self, token_field, options) TokenAuthenticatableStrategies::Insecure.new(self, token_field, options)
end end
if unique
define_singleton_method("find_by_#{token_field}") do |token| define_singleton_method("find_by_#{token_field}") do |token|
strategy.find_token_authenticatable(token) strategy.find_token_authenticatable(token)
end end
end
define_method(token_field) do define_method(token_field) do
strategy.get_token(self) strategy.get_token(self)
......
...@@ -43,10 +43,14 @@ module TokenAuthenticatableStrategies ...@@ -43,10 +43,14 @@ module TokenAuthenticatableStrategies
set_token(instance, new_token) set_token(instance, new_token)
end end
def unique
@options.fetch(:unique, true)
end
def generate_available_token def generate_available_token
loop do loop do
token = generate_token token = generate_token
break token unless find_token_authenticatable(token, true) break token unless unique && find_token_authenticatable(token, true)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment