You are here

public function MiniorangeCustomerSetup::send_otp_token in Google Authenticator / 2 Factor Authentication - 2FA 8.2

Same name and namespace in other branches
  1. 8 src/MiniorangeCustomerSetup.php \Drupal\miniorange_2fa\MiniorangeCustomerSetup::send_otp_token()

File

src/MiniorangeCustomerSetup.php, line 108
Contains miniOrange Customer class.

Class

MiniorangeCustomerSetup
@file This class represents configuration for customer.

Namespace

Drupal\miniorange_2fa

Code

public function send_otp_token($uKey, $authType, $customerKey, $api_Key) {
  if ($authType == AuthenticationType::$SMS_AND_EMAIL['code']) {
    $fields = array(
      'customerKey' => $customerKey,
      'email' => $uKey['email'],
      'authType' => $authType,
      'transactionName' => 'Drupal 2 Factor Authentication Plugin',
    );
  }
  else {
    if ($authType == 'OTP_OVER_SMS' || $authType == 'OTP_OVER_SMS_AND_EMAIL' || $authType == 'OTP_OVER_EMAIL' || $authType == 'PHONE_VERIFICATION') {
      if ($authType == 'OTP_OVER_SMS') {
        $authType = AuthenticationType::$SMS['code'];
      }
      elseif ($authType == 'PHONE_VERIFICATION') {
        $authType = AuthenticationType::$OTP_OVER_PHONE['code'];
      }
      elseif ($authType == 'OTP_OVER_SMS_AND_EMAIL') {
        $authType = AuthenticationType::$SMS_AND_EMAIL['code'];
      }
      elseif ($authType == 'OTP_OVER_EMAIL') {
        $authType = "OTP OVER EMAIL";
      }
      $phone = isset($uKey['phone']) ? $uKey['phone'] : '';
      $email = isset($uKey['email']) ? $uKey['email'] : '';
      if ($authType == AuthenticationType::$SMS_AND_EMAIL['code']) {
        $fields = array(
          'customerKey' => $customerKey,
          'phone' => $phone,
          'email' => $email,
          'authType' => $authType,
        );
      }
      elseif ($authType == 'OTP OVER EMAIL') {
        $fields = array(
          'customerKey' => $customerKey,
          'email' => $email,
          'authType' => $authType,
        );
      }
      else {
        $fields = array(
          'customerKey' => $customerKey,
          'phone' => $phone,
          'authType' => $authType,
        );
      }
    }
  }
  $url = MoAuthConstants::getBaseUrl() . MoAuthConstants::$AUTH_CHALLENGE_API;
  $json = json_encode($fields);
  return MoAuthUtilities::callService($customerKey, $api_Key, $url, $json);
}