1 # frozen_string_literal: true
4 class AuthDeletionsController < ApplicationController
7 skip_before_action :verify_authenticity_token
9 before_action :set_locale
11 authorize_resource :class => :auth_deletion
14 @auth_provider = params.expect(:provider)
15 @auth_uid, @time = Rails
17 .message_verifier(:social_login_deletion)
18 .verify(params.expect(:confirmation_code))
19 rescue ActiveSupport::MessageVerifier::InvalidSignature
24 if params.expect(:provider) == "facebook"
34 encoded_signature, payload = params.expect(:signed_request).split(".", 2)
35 signature = Base64.urlsafe_decode64(encoded_signature)
37 raise ActionController::BadRequest unless signature == OpenSSL::HMAC.digest("SHA256", Settings.facebook_auth_secret, payload)
39 data = JSON.parse(Base64.urlsafe_decode64(payload))
40 user = User.find_by!(:auth_provider => "facebook", :auth_uid => data["user_id"])
42 user.auth_provider = nil
46 @confirmation_code = Rails
48 .message_verifier(:social_login_deletion)
49 .generate([data["user_id"], Time.now.to_i])
51 render :formats => [:json]