-
-
Save simplyb/7550368 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The idea here is that if any of the three tokens are not already | |
# set, then they should be generated. In order to generate one, it | |
# must be unique. | |
def generate_tokens! | |
[ :code, :access_token, :refresh_token ].each do |attr| | |
next if send(attr) | |
send "#{attr}=", tokenize(attr) | |
end | |
end | |
def tokenize(attr) | |
token = loop do | |
t = SecureRandom.hex(16) | |
break t unless self.class.exists?(attr => t) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment