diff --git a/app/models/user.rb b/app/models/user.rb
index 97c8b7767781e08d02385cc1a8f3b73b6c7b82e7..0b7266b7eee47105b9edd65fa93bd81db33a373d 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -22,6 +22,7 @@
 #  last_sign_in_ip               :string
 #  locked_at                     :datetime
 #  mobile_phone                  :string
+#  picture_url                   :string
 #  remember_created_at           :datetime
 #  reset_password_sent_at        :datetime
 #  reset_password_token          :string           indexed
@@ -53,7 +54,7 @@
 #  fk_rails_bd6f7212a9  (university_id => universities.id)
 #
 class User < ApplicationRecord
-  has_one_attached_deletable :picture  # In this order, "resize avatar" callback will be fired after the others.
+  include WithAvatar
   include WithUniversity
   include WithAuthentication
   include WithOmniauth
diff --git a/app/models/user/with_avatar.rb b/app/models/user/with_avatar.rb
new file mode 100644
index 0000000000000000000000000000000000000000..863b3d0a237145865bfcec2217b67d65d5f1cdec
--- /dev/null
+++ b/app/models/user/with_avatar.rb
@@ -0,0 +1,37 @@
+module User::WithAvatar
+  extend ActiveSupport::Concern
+
+  included do
+    has_one_attached_deletable :picture # Nota: user has a picture_url property for SSO mapping. If picture_url is set it will use the url to change the picture
+
+    before_save :update_picture, if: :will_save_change_to_picture_url?
+    after_save :update_picture_url
+
+    private
+
+    def update_picture
+      if picture_url.blank?
+        do_purge_picture
+      else
+        do_update_picture
+      end
+    end
+
+    def update_picture_url
+      if picture_url.present? && !picture.attached?
+        self.update_column(:picture_url, nil)
+      end
+    end
+
+    def do_purge_picture
+      self.picture.purge if self.picture.attached?
+    end
+
+    def do_update_picture
+      downloaded_image = open(picture_url)
+      content_type = downloaded_image.content_type
+      extension = content_type.split('/').last
+      self.picture.attach(io: downloaded_image, filename: "avatar.#{extension}")
+    end
+  end
+end
diff --git a/app/models/user/with_omniauth.rb b/app/models/user/with_omniauth.rb
index 64a2e5c72a7ddb55d996dd11420bd6422da49b48..64ba7ddc5433e77746467b4deb1b35c2d82f0089 100644
--- a/app/models/user/with_omniauth.rb
+++ b/app/models/user/with_omniauth.rb
@@ -34,7 +34,7 @@ module User::WithOmniauth
 
     def self.update_data_for_mapping_element(user, mapping_element, attributes)
       sso_key = mapping_element['sso_key']
-      return user if attributes[sso_key].blank? # if not provided by sso, just return
+      return user if attributes[sso_key].nil? # if not provided by sso, just return
       internal_key = mapping_element['internal_key']
       user = self.update_data_for_mapping_element_standard(user, mapping_element, self.get_provided_answer(attributes[sso_key]))
       user
diff --git a/db/migrate/20220505105709_add_picture_url_to_users.rb b/db/migrate/20220505105709_add_picture_url_to_users.rb
new file mode 100644
index 0000000000000000000000000000000000000000..9570a3173110bf0246236ad68a91b9e1d02a3508
--- /dev/null
+++ b/db/migrate/20220505105709_add_picture_url_to_users.rb
@@ -0,0 +1,5 @@
+class AddPictureUrlToUsers < ActiveRecord::Migration[6.1]
+  def change
+    add_column :users, :picture_url, :string
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index f5a8ea0a6798ca4cb2d4de9dd7a2a509c4170244..c6b36805ae7e9ffe57c5b0a30d7006dd7cd8319b 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2022_04_28_171541) do
+ActiveRecord::Schema.define(version: 2022_05_05_105709) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "pgcrypto"
@@ -782,6 +782,7 @@ ActiveRecord::Schema.define(version: 2022_04_28_171541) do
     t.datetime "direct_otp_sent_at"
     t.datetime "totp_timestamp"
     t.string "session_token"
+    t.string "picture_url"
     t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
     t.index ["email", "university_id"], name: "index_users_on_email_and_university_id", unique: true
     t.index ["encrypted_otp_secret_key"], name: "index_users_on_encrypted_otp_secret_key", unique: true