Commit 5128a88

mo <mo@mokhan.ca>
2018-10-20 17:01:55
validate redirect_uri
1 parent eb546bd
Changed files (2)
app/controllers/clients_controller.rb
@@ -5,6 +5,12 @@ class ClientsController < ApplicationController
   def create
     @client = Client.create!(transform(secure_params))
     render status: :created, formats: :json
+  rescue ActiveRecord::RecordInvalid => error
+    json = {
+      error: :invalid_redirect_uri,
+      error_description: error.record.errors.full_messages.join(' ')
+    }
+    render json: json, status: :bad_request
   end
 
   private
app/models/client.rb
@@ -8,6 +8,7 @@ class Client < ApplicationRecord
   attribute :redirect_uris, :string, array: true
   enum token_endpoint_auth_method: { client_secret_none: 0, client_secret_post: 1, client_secret_basic: 2 }
 
+  validates :redirect_uris, presence: true, format: { with: URI_REGEX }
   validates :jwks_uri, format: { with: URI_REGEX }
   validates :logo_uri, format: { with: URI_REGEX }
   validates :name, presence: true