Skip to content
Snippets Groups Projects
Commit be5b15a4 authored by Ankit Singh's avatar Ankit Singh
Browse files

commit for 2.0.17

parent 0227132d
No related branches found
No related tags found
No related merge requests found
logo.png 0 → 100644
logo.png

35.1 KiB

name: 'REST & JSON API Authentication' name: 'REST & JSON API Authentication'
type: module type: module
core_version_requirement: ^9.3 || ^10 core_version_requirement: ^9.3 || ^10 || ^11
description: 'Drupal API Authentication module secures unauthorized access to your Drupal site APIs using different API authentication methods.' description: 'Drupal API Authentication module secures unauthorized access to your Drupal site APIs using different API authentication methods.'
configure: rest_api_authentication.auth_settings configure: rest_api_authentication.auth_settings
...@@ -21,7 +21,7 @@ class AdvancedSettingsForm { ...@@ -21,7 +21,7 @@ class AdvancedSettingsForm {
* The modified form array with the advanced settings elements added. * The modified form array with the advanced settings elements added.
*/ */
public static function insertForm(array &$form, FormStateInterface $form_state) { public static function insertForm(array &$form, FormStateInterface $form_state) {
global $base_url; $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath();
$disabled = TRUE; $disabled = TRUE;
$form['advancedsettings'] = [ $form['advancedsettings'] = [
'#type' => 'details', '#type' => 'details',
......
...@@ -59,9 +59,8 @@ class ApiAuthenticationApiToken { ...@@ -59,9 +59,8 @@ class ApiAuthenticationApiToken {
$user = user_load_by_name($name); $user = user_load_by_name($name);
} }
$api_key = $creds[1]; $api_key = $creds[1];
if (empty($user)) { if (empty($user)) {
$api_error = [ return [
'status' => 'error', 'status' => 'error',
'http_code' => '404', 'http_code' => '404',
"error" => "USER_DOES_NOT_EXIST", "error" => "USER_DOES_NOT_EXIST",
......
...@@ -10,6 +10,7 @@ use Drupal\Core\Messenger\MessengerInterface; ...@@ -10,6 +10,7 @@ use Drupal\Core\Messenger\MessengerInterface;
use Drupal\rest_api_authentication\AdvancedSettingsForm; use Drupal\rest_api_authentication\AdvancedSettingsForm;
use Drupal\rest_api_authentication\CustomerSetupForm; use Drupal\rest_api_authentication\CustomerSetupForm;
use Drupal\rest_api_authentication\MiniorangeRestAPICustomer; use Drupal\rest_api_authentication\MiniorangeRestAPICustomer;
use Drupal\rest_api_authentication\MoHeadlessIntegration;
use Drupal\rest_api_authentication\RequestForDemoForm; use Drupal\rest_api_authentication\RequestForDemoForm;
use Drupal\rest_api_authentication\SetupAuthenticationForm; use Drupal\rest_api_authentication\SetupAuthenticationForm;
use Drupal\rest_api_authentication\UpgradePlansForm; use Drupal\rest_api_authentication\UpgradePlansForm;
...@@ -116,14 +117,15 @@ class MiniOrangeAPIAuth extends FormBase { ...@@ -116,14 +117,15 @@ class MiniOrangeAPIAuth extends FormBase {
// Builds and inserts the Advanced Settings form. // Builds and inserts the Advanced Settings form.
AdvancedSettingsForm::insertForm($form, $form_state); AdvancedSettingsForm::insertForm($form, $form_state);
// Builds and inserts the headless SSO form.
MoHeadlessIntegration::insertForm($form, $form_state);
// Builds and inserts the Request For Demo form. // Builds and inserts the Request For Demo form.
RequestForDemoForm::insertForm($form, $form_state); RequestForDemoForm::insertForm($form, $form_state);
// Builds and inserts the Upgrade Plans form. // Builds and inserts the Upgrade Plans form.
UpgradePlansForm::insertForm($form, $form_state); UpgradePlansForm::insertForm($form, $form_state);
// Builds and inserts the Register/Login form.
CustomerSetupForm::insertForm($form, $form_state);
$form['rest_api_authentication_background_end'] = [ $form['rest_api_authentication_background_end'] = [
'#markup' => '</div>', '#markup' => '</div>',
]; ];
...@@ -142,7 +144,7 @@ class MiniOrangeAPIAuth extends FormBase { ...@@ -142,7 +144,7 @@ class MiniOrangeAPIAuth extends FormBase {
* return nothing. * return nothing.
*/ */
public function restApiAuthenticationSaveBasicConfig(array &$form, FormStateInterface $form_state): void { public function restApiAuthenticationSaveBasicConfig(array &$form, FormStateInterface $form_state): void {
global $base_url; $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath();
$form_input = $form_state->getValues(); $form_input = $form_state->getValues();
$enable_authentication = $form_input['enable_authentication']; $enable_authentication = $form_input['enable_authentication'];
...@@ -164,7 +166,7 @@ class MiniOrangeAPIAuth extends FormBase { ...@@ -164,7 +166,7 @@ class MiniOrangeAPIAuth extends FormBase {
* return nothing. * return nothing.
*/ */
public function restApiAuthenticationGenerateApiToken(array &$form, FormStateInterface $form_state) { public function restApiAuthenticationGenerateApiToken(array &$form, FormStateInterface $form_state) {
global $base_url; $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath();
$api_key = Utilities::generateRandom(64); $api_key = Utilities::generateRandom(64);
$this->configFactory->getEditable('rest_api_authentication.settings') $this->configFactory->getEditable('rest_api_authentication.settings')
->set('api_token', $api_key) ->set('api_token', $api_key)
...@@ -178,7 +180,7 @@ class MiniOrangeAPIAuth extends FormBase { ...@@ -178,7 +180,7 @@ class MiniOrangeAPIAuth extends FormBase {
* {@inheritDoc} * {@inheritDoc}
*/ */
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
global $base_url; $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath();
$list_of_apis = $form['advancedsettings']['support_container_outline']['list_apis']['api_textarea']['#value']; $list_of_apis = $form['advancedsettings']['support_container_outline']['list_apis']['api_textarea']['#value'];
$api_access = $form['advancedsettings']['support_container_outline']['list_apis']['settings']['#value']; $api_access = $form['advancedsettings']['support_container_outline']['list_apis']['settings']['#value'];
$this->configFactory->getEditable('rest_api_authentication.settings') $this->configFactory->getEditable('rest_api_authentication.settings')
...@@ -193,7 +195,7 @@ class MiniOrangeAPIAuth extends FormBase { ...@@ -193,7 +195,7 @@ class MiniOrangeAPIAuth extends FormBase {
* Save the basic authentication method. * Save the basic authentication method.
*/ */
public function restApiAuthenticationSaveBasicAuthConf(array &$form, FormStateInterface $form_state) { public function restApiAuthenticationSaveBasicAuthConf(array &$form, FormStateInterface $form_state) {
global $base_url; $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath();
$this->configFactory->getEditable('rest_api_authentication.settings')->set('authentication_method', 0)->save(); $this->configFactory->getEditable('rest_api_authentication.settings')->set('authentication_method', 0)->save();
$this->messenger->addMessage($this->t('Configurations saved successfully.')); $this->messenger->addMessage($this->t('Configurations saved successfully.'));
$response = new RedirectResponse($base_url . "/admin/config/people/rest_api_authentication/auth_settings?tab=edit-api-auth"); $response = new RedirectResponse($base_url . "/admin/config/people/rest_api_authentication/auth_settings?tab=edit-api-auth");
...@@ -204,7 +206,7 @@ class MiniOrangeAPIAuth extends FormBase { ...@@ -204,7 +206,7 @@ class MiniOrangeAPIAuth extends FormBase {
* Send a request for Demo. * Send a request for Demo.
*/ */
public function savedDemoRequest(array &$form, FormStateInterface $form_state) { public function savedDemoRequest(array &$form, FormStateInterface $form_state) {
global $base_url; $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath();
$email = trim($form['demo']['container_outline']['rest_api_authentication_email_address']['#value']); $email = trim($form['demo']['container_outline']['rest_api_authentication_email_address']['#value']);
$phone = $form['demo']['container_outline']['rest_api_authentication_phone_number']['#value']; $phone = $form['demo']['container_outline']['rest_api_authentication_phone_number']['#value'];
$query = trim($form['demo']['container_outline']['rest_api_authentication_demo_query']['#value']); $query = trim($form['demo']['container_outline']['rest_api_authentication_demo_query']['#value']);
...@@ -212,61 +214,4 @@ class MiniOrangeAPIAuth extends FormBase { ...@@ -212,61 +214,4 @@ class MiniOrangeAPIAuth extends FormBase {
$response = new RedirectResponse($base_url . "/admin/config/people/rest_api_authentication/auth_settings?tab=edit-demo"); $response = new RedirectResponse($base_url . "/admin/config/people/rest_api_authentication/auth_settings?tab=edit-demo");
$response->send(); $response->send();
} }
/**
* Activating the module.
*/
public function activateModuleRequest(array &$form, FormStateInterface $form_state) {
global $base_url;
$username = $form['customersetup']['customer_setup_container_outline']['rest_api_authentication_user_email']['#value'];
$password = $form['customersetup']['customer_setup_container_outline']['rest_api_authentication_user_password']['#value'];
if (empty($username)||empty($password)) {
$this->messenger->addMessage($this->t('The <b><u>Email Address</u></b> and the <b><u>Password</u></b> fields are mandatory.'), 'error');
return;
}
if (!$this->emailValidator->isValid($username)) {
$this->messenger->addMessage($this->t('The email address <i> %username </i> does not seems to be valid.', ['%username' => $username]), 'error');
return;
}
$customer_config = new MiniorangeRestAPICustomer($username, $password);
$check_customer_response = json_decode($customer_config->checkCustomer());
if (isset($check_customer_response->status) && $check_customer_response->status == 'CUSTOMER_NOT_FOUND') {
$this->messenger->addMessage($this->t('Invalid credentials'), 'error');
$response = new RedirectResponse($base_url . "/admin/config/people/rest_api_authentication/auth_settings?tab=edit-customersetup");
$response->send();
return;
}
elseif (isset($check_customer_response->status) && $check_customer_response->status == 'CURL_ERROR') {
$this->messenger->addMessage($this->t('cURL is not enabled. Please enable cURL'), 'error');
}
else {
$customer_keys_response = json_decode($customer_config->getCustomerKeys());
// $customer_keys_response = json_decode($customer_config->getCustomerKeys()->getBody()->getContents());
if (json_last_error() == JSON_ERROR_NONE) {
$this->configFactory->getEditable('rest_api_authentication.settings')
->set('rest_api_authentication_customer_id', $customer_keys_response->id)
->set('rest_api_authentication_customer_admin_token', $customer_keys_response->token)
->set('rest_api_authentication_customer_admin_email', $username)
->set('rest_api_authentication_customer_api_key', $customer_keys_response->apiKey)
->set('rest_api_authentication_customer_password', $password)->save();
$current_status = 'PLUGIN_CONFIGURATION';
$this->configFactory->getEditable('rest_api_authentication.settings')->set('rest_api_authentication_status', $current_status)->save();
$this->messenger->addMessage($this->t('Successfully retrieved your account.'));
$response = new RedirectResponse($base_url . "/admin/config/people/rest_api_authentication/auth_settings?tab=edit-customersetup");
$response->send();
return;
}
else {
$this->messenger->addMessage($this->t('Invalid credentials'), 'error');
$response = new RedirectResponse($base_url . "/admin/config/people/rest_api_authentication/auth_settings?tab=edit-customersetup");
$response->send();
return;
}
}
$response = new RedirectResponse($base_url . "/admin/config/people/rest_api_authentication/auth_settings?tab=edit-customersetup");
$response->send();
}
} }
...@@ -113,7 +113,7 @@ class MiniornageAPIAuthnRequestSupport extends FormBase { ...@@ -113,7 +113,7 @@ class MiniornageAPIAuthnRequestSupport extends FormBase {
$email = $form_values['rest_api_authentication_support_email_address']; $email = $form_values['rest_api_authentication_support_email_address'];
$phone = $form_values['rest_api_authentication_support_phone_number']; $phone = $form_values['rest_api_authentication_support_phone_number'];
$query = $form_values['rest_api_authentication_support_query']; $query = $form_values['rest_api_authentication_support_query'];
$query_type = 'Support'; $query_type = 'demo';
$support = new MiniorangeApiAuthSupport($email, $phone, $query, $query_type); $support = new MiniorangeApiAuthSupport($email, $phone, $query, $query_type);
$support_response = $support->sendSupportQuery(); $support_response = $support->sendSupportQuery();
......
...@@ -8,7 +8,10 @@ use Drupal\Core\Ajax\ReplaceCommand; ...@@ -8,7 +8,10 @@ use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Drupal\Core\Url;
use Drupal\rest_api_authentication\MiniorangeApiAuthSupport; use Drupal\rest_api_authentication\MiniorangeApiAuthSupport;
use Drupal\user\Entity\User;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
...@@ -57,39 +60,96 @@ class MiniornageAPIAuthnRequestTrial extends FormBase { ...@@ -57,39 +60,96 @@ class MiniornageAPIAuthnRequestTrial extends FormBase {
'#weight' => -10, '#weight' => -10,
]; ];
$form['radio_option'] = [
'#type' => 'radios',
'#title' => $this->t('Which type of trial would you prefer?'),
'#options' => [
'option1' => $this->t('Sandbox'),
'option2' => $this->t('On-Premise'),
],
'#default_value' => ($form_state->getValue('radio_option')) ? $form_state->getValue('radio_option') : 'option1',
'#attributes' => array('class' => array('container-inline'),),
'#ajax' => [
'callback' => '::updateFormElements',
'wrapper' => 'additional-fields-wrapper',
],
];
$form['additional_fields_wrapper'] = [
'#type' => 'container',
'#attributes' => ['id' => 'additional-fields-wrapper'],
];
$form['rest_api_authentication_trial_email_address'] = [ $form['rest_api_authentication_trial_email_address'] = [
'#type' => 'email', '#type' => 'email',
'#title' => $this->t('Email'), '#title' => $this->t('Email'),
'#required' => TRUE,
'#attributes' => [ '#attributes' => [
'placeholder' => $this->t('Enter your email'), 'placeholder' => $this->t('Enter your email'),
'style' => 'width:99%;margin-bottom:1%;', 'style' => 'width:99%;margin-bottom:1%;',
], ],
'#states' => [
'visible' => [
':input[name="radio_option"]' => ['value' => 'option2'],
],
'required' => array(
':input[name="radio_option"]' => ['value' => 'option2'],),
],
]; ];
$form['rest_api_authentication_trial_description'] = [ $form['rest_api_authentication_trial_description'] = [
'#type' => 'textarea', '#type' => 'textarea',
'#rows' => 4, '#rows' => 4,
'#required' => TRUE,
'#title' => $this->t('Description'), '#title' => $this->t('Description'),
'#attributes' => [ '#attributes' => [
'placeholder' => $this->t('Describe your use case here!'), 'placeholder' => $this->t('Describe your use case here!'),
'style' => 'width:99%;', 'style' => 'width:99%;',
], ],
'#states' => [
'visible' => [
':input[name="radio_option"]' => ['value' => 'option2'],
],
'required' => array(
':input[name="radio_option"]' => ['value' => 'option2'],),
],
]; ];
$form['rest_api_authentication_trial_note'] = [ $form['rest_api_authentication_trial_note'] = [
'#markup' => $this->t('<div>If you have any questions or in case you need any sort of assistance in configuring our module according to your requirements, you can get in touch with us on <a href="mailto:drupalsupport@xecurify.com">drupalsupport@xecurify.com</a> and we will assist you further.</div>'), '#markup' => $this->t('<div>If you have any questions or in case you need any sort of assistance in configuring our module according to your requirements, you can get in touch with us on <a href="mailto:drupalsupport@xecurify.com">drupalsupport@xecurify.com</a> and we will assist you further.</div>'),
'#states' => [
'visible' => [
':input[name="radio_option"]' => ['value' => 'option2'],
],
],
];
$form['submit_button_option1'] = [
'#type' => 'submit',
'#value' => $this->t('Go to Sandbox'),
'#attributes' => [
'class' => ['option1-submit','use-ajax', 'button--primary'],
'formtarget' => '_blank'
],
'#prefix' => '<div class="option1-submit-wrapper">',
'#suffix' => '</div>',
'#states' => [
'visible' => [
':input[name="radio_option"]' => ['value' => 'option1'],],
],
'#submit' => ['::goToSandbox',],
]; ];
$form['actions'] = ['#type' => 'actions']; $form['submit_button_other_options'] = [
$form['actions']['send'] = [
'#type' => 'submit', '#type' => 'submit',
'#value' => $this->t('Submit'), '#value' => $this->t('Submit'),
'#attributes' => [ '#attributes' => [
'class' => [ 'class' => ['other-options-submit', 'use-ajax', 'button--primary'],
'use-ajax', ],
'button--primary', '#prefix' => '<div class="other-options-submit-wrapper">',
'#suffix' => '</div>',
'#states' => [
'visible' => [
':input[name="radio_option"]' => ['value' => 'option2'],
], ],
], ],
'#ajax' => [ '#ajax' => [
...@@ -102,6 +162,35 @@ class MiniornageAPIAuthnRequestTrial extends FormBase { ...@@ -102,6 +162,35 @@ class MiniornageAPIAuthnRequestTrial extends FormBase {
return $form; return $form;
} }
public static function getEmail(){
$user = \Drupal::currentUser()->getEmail();
$email = \Drupal::config('rest_api_authentication.settings')->get('rest_api_authentication_customer_admin_email');
$email = !empty($email) ? $email : $user;
$email = preg_match('/^(?!.*(?:noreply|no-reply)).*$/i', $email) ? $email : '';
return $email;
}
public function goToSandbox(array $form, FormStateInterface $form_state) {
$url = Url::fromUri('https://playground.miniorange.com/drupal.php',[
'query' => [
'email' => self::getEmail(),
'mo_module' => 'rest_api_authentication',
'drupal_version' => '10',
],
])->toString();
$response = new TrustedRedirectResponse($url);
$form_state->setResponse($response);
}
public function updateFormElements(array &$form, FormStateInterface $form_state) {
$selected_value = $form_state->getValue('radio_option');
if ($selected_value === 'option1') {
$form['actions']['send']['submit']['#value'] = t('Confirm Option 1');
}
elseif ($selected_value === 'option2') {
$form['actions']['send']['#value'] = t('Confirm Option 2');
}
return $form['additional_fields_wrapper'];
}
/** /**
* Process the 'modal_example_form' Form. * Process the 'modal_example_form' Form.
* *
...@@ -120,12 +209,10 @@ class MiniornageAPIAuthnRequestTrial extends FormBase { ...@@ -120,12 +209,10 @@ class MiniornageAPIAuthnRequestTrial extends FormBase {
// If there are any form errors, AJAX replace the form. // If there are any form errors, AJAX replace the form.
if ($form_state->hasAnyErrors()) { if ($form_state->hasAnyErrors()) {
$response->addCommand(new ReplaceCommand('#modal_example_form', $form)); $response->addCommand(new ReplaceCommand('#modal_example_form', $form));
} } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->messenger->addMessage($this->t('The email address <b><em>%email</em></b> is not valid.', ['%email' => $email]), 'error'); $this->messenger->addMessage($this->t('The email address <b><em>%email</em></b> is not valid.', ['%email' => $email]), 'error');
$response->addCommand(new ReplaceCommand('#modal_example_form', $form)); $response->addCommand(new ReplaceCommand('#modal_example_form', $form));
} } else {
else {
$query = $form_values['rest_api_authentication_trial_description']; $query = $form_values['rest_api_authentication_trial_description'];
$query_type = 'trial'; $query_type = 'trial';
...@@ -137,19 +224,19 @@ class MiniornageAPIAuthnRequestTrial extends FormBase { ...@@ -137,19 +224,19 @@ class MiniornageAPIAuthnRequestTrial extends FormBase {
'#markup' => $this->t('Your request for a trial module was sent successfully. Please allow us some time and we will send you the trial module as soon as possible.'), '#markup' => $this->t('Your request for a trial module was sent successfully. Please allow us some time and we will send you the trial module as soon as possible.'),
]; ];
$ajax_form = new OpenModalDialogCommand('Thank you!', $message, ['width' => '50%']); $ajax_form = new OpenModalDialogCommand('Thank you!', $message, ['width' => '50%']);
} } else {
else {
$error = [ $error = [
'#type' => 'item', '#type' => 'item',
'#markup' => $this->t('Error submitting the support query. Please send us your query at '#markup' => $this->t('Error submitting the support query. Please send us your query at
<a href="mailto:drupalsupport@xecurify.com"> <a href="mailto:drupalsupport@xecurify.com">
drupalsupport@xecurify.com</a>.'), drupalsupport@xecurify.com</a>.'),
]; ];
$ajax_form = new OpenModalDialogCommand('Error!', $error, ['width' => '50%']); $ajax_form = new OpenModalDialogCommand('Error!', $error, ['width' => '50%']);
} }
$response->addCommand($ajax_form); $response->addCommand($ajax_form);
} }
return $response; return $response;
} }
......
...@@ -64,7 +64,7 @@ class MiniorangeApiAuthSupport { ...@@ -64,7 +64,7 @@ class MiniorangeApiAuthSupport {
public function sendSupportQuery() { public function sendSupportQuery() {
$modules_info = \Drupal::service('extension.list.module')->getExtensionInfo('rest_api_authentication'); $modules_info = \Drupal::service('extension.list.module')->getExtensionInfo('rest_api_authentication');
$modules_version = $modules_info['version']; $modules_version = $modules_info['version'];
global $base_url; $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath();
if ($this->plan == 'demo') { if ($this->plan == 'demo') {
$url = MiniorangeApiAuthConstants::BASE_URL . '/moas/api/notify/send'; $url = MiniorangeApiAuthConstants::BASE_URL . '/moas/api/notify/send';
...@@ -173,7 +173,7 @@ class MiniorangeApiAuthSupport { ...@@ -173,7 +173,7 @@ class MiniorangeApiAuthSupport {
catch (\Exception $exception) { catch (\Exception $exception) {
$error = [ $error = [
'%method' => 'sendSupportQuery', '%method' => 'sendSupportQuery',
'%file' => 'miniorange_oauth_client_support.php', '%file' => 'MiniorangeApiAuthSupport.php',
'%error' => $exception->getMessage(), '%error' => $exception->getMessage(),
]; ];
\Drupal::logger('rest_api_authentication')->notice('%error', $error); \Drupal::logger('rest_api_authentication')->notice('%error', $error);
...@@ -182,7 +182,7 @@ class MiniorangeApiAuthSupport { ...@@ -182,7 +182,7 @@ class MiniorangeApiAuthSupport {
catch (GuzzleException $e) { catch (GuzzleException $e) {
$error = [ $error = [
'%method' => 'sendSupportQuery', '%method' => 'sendSupportQuery',
'%file' => 'miniorange_oauth_client_support.php', '%file' => 'MiniorangeApiAuthSupport.php',
'%error' => $e->getMessage(), '%error' => $e->getMessage(),
]; ];
\Drupal::logger('rest_api_authentication')->notice('%error', $error); \Drupal::logger('rest_api_authentication')->notice('%error', $error);
......
<?php
namespace Drupal\rest_api_authentication;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Markup;
use Drupal\rest_api_authentication\Utilities;
class MoHeadlessIntegration {
public static function insertForm(array &$form, FormStateInterface $form_state) {
$form['markup_library_1'] = [
'#attached' => [
'library' => [
"rest_api_authentication/rest_api_authentication.style_settings",
],
],
];
$form['headless_sso_details'] = [
'#type' => 'details',
'#title' => t('Headless SSO'),
'#open' => TRUE,
'#group' => 'verticaltabs',
];
self::headlessSSOFieldset($form,$form_state);
return $form;
}
private static function headlessSSOFieldset(array &$form, FormStateInterface $form_state) {
$base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath();
$form['headless_sso_details']['headless_sso'] = [
'#markup' => t('<b>Headless SSO (Single Sign On) </b><a href = ":upgradePlan" style="font-size: small" >PREMIUM</a><a style="float: right;" href=":guideUrl" target="_blank" class="button button--small" >setup guide</a>',
[
':guideUrl' => 'https://www.drupal.org/docs/contributed-modules/api-authentication',
':upgradePlan' => $base_url . '/admin/config/people/rest_api_authentication/auth_settings?tab=edit-upgrade-plans',
]),
];
$form ['headless_sso_details']['headless_sso']['sso_protocol'] = [
'#prefix' => t('<p style="font-size: small"> This section help you to setup the headless sso with the help of the <a href=":oauthClient" target="_blank">Drupal OAuth Client</a> or <a href=":saml" target="_blank">miniOrange SAML module</a>.</p> <hr>',
[
':oauthClient' => 'https://www.drupal.org/project/miniorange_oauth_client',
':saml' => 'https://www.drupal.org/project/miniorange_saml',
] ),
];
$form['headless_sso_details']['headless_sso']['headless_sso_table'] = [
'#type' => 'table',
'#responsive' => TRUE ,
'#attributes' => ['style' => 'border-collapse: separate;',],
];
$configurations = Utilities::getHeadlessTableAttr();
foreach ($configurations as $key => $value) {
$row = self::generateHeadlessSooTableRow($key, $value);
$form['headless_sso_details']['headless_sso']['headless_sso_table'][$key] = $row;
}
$form['headless_sso_details']['headless_sso']['save_button'] = [
'#type' => 'submit',
'#button_type' => 'primary',
'#value' => 'Save Settings',
'#disabled' => true,
];
}
private static function generateHeadlessSooTableRow(string $key, string $value) {
$config = \Drupal::config('rest_api_authentication');
$row[$key.$value] = [
'#markup' => '<div class="container-inline" ><strong>'.$value.'</strong>',
];
$base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath();
if($key == 'module'){
$row[$key] = [
'#type' => 'radios',
'#title' => '',
'#options' => [0 => t('OAuth Client module'), 1 => t('SAML SP module')],
'#attributes' => [
'class' => ['container-inline'],
],
'#disabled' => true,
];
}else if($key == 'frontend_url'){
$row[$key] = [
'#type' => 'textfield',
'#description' => t('Enter the frontend URL where the user will be redirected after SSO.'),
'#attributes' => ['style' => 'width:50%'],
'#disabled' => true,
];
}else if( $key == 'get_token_url'){
$row[$key] = [
'#markup' => Markup::create('<span id = "'.$key.'">' . $base_url . '/get-token</span>&nbsp;
'),
];
}else {
$row[$key] = [
'#type' => 'radios',
'#title' => '',
'#states' => ['visible' => [':input[name = "module"]' => ['value' => 0 ], ],],
'#options' => [
0 => t('Send JWT created by the module'),
1 => t('send JWT received from the OAuth Server'),
],
'#attributes' => [
'class' => ['container-inline'],
],
'#disabled' => true,
];
}
return $row;
}
}
...@@ -21,7 +21,7 @@ class SetupAuthenticationForm { ...@@ -21,7 +21,7 @@ class SetupAuthenticationForm {
* The populated form array. * The populated form array.
*/ */
public static function insertForm(array &$form, FormStateInterface $form_state) { public static function insertForm(array &$form, FormStateInterface $form_state) {
global $base_url; $base_url = \Drupal::request()->getSchemeAndHttpHost().\Drupal::request()->getBasePath();
$form['markup_library_3'] = [ $form['markup_library_3'] = [
'#attached' => [ '#attached' => [
'library' => [ 'library' => [
......
...@@ -104,5 +104,9 @@ class Utilities { ...@@ -104,5 +104,9 @@ class Utilities {
} }
return empty($content) ? $currentTimeInMillis : $content; return empty($content) ? $currentTimeInMillis : $content;
} }
public static function getHeadlessTableAttr() {
return ['module' => 'Select Module', 'frontend_url' => 'Frontend redirect URL', 'get_token_url' => 'ID Token Endpoint ', 'send_jwt' => 'Select JWT type' ];
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment