diaspora/app/models/o_auth_application.rb
theworldbright 3cfbcbce8f Implement authorization endpoint (part 1)
The user can now authenticate with the authorization
server's authorization endpoint and receive a fake
id token.
2016-01-04 16:49:49 +09:00

43 lines
971 B
Ruby

class OAuthApplication < ActiveRecord::Base
belongs_to :user
has_many :authorizations
validates :client_id, presence: true, uniqueness: true
validates :client_secret, presence: true
serialize :redirect_uris, JSON
before_validation :setup, on: :create
def setup
self.client_id = SecureRandom.hex(16)
self.client_secret = SecureRandom.hex(32)
end
class << self
def available_response_types
["id_token"]
end
def register!(registrarHash)
registrarHash.validate!
buildClientApplication(registrarHash)
end
def buildClientApplication(registrarHash)
client = OAuthApplication.create!
client.attributes = filterNilValues(registrarHash)
client.save!
client
end
def filterNilValues(registrarHash)
{
name: registrarHash.client_name,
redirect_uris: registrarHash.redirect_uris
}.delete_if do |key, value|
value.nil?
end
end
end
end