You are here

rocket_chat_oauth_login.module in Rocket.Chat 7.2

Same filename and directory in other branches
  1. 7 modules/rocket_chat_oauth_login/rocket_chat_oauth_login.module

Code for the Rocket Chat oAuth Login feature.

File

modules/rocket_chat_oauth_login/rocket_chat_oauth_login.module
View source
<?php

/**
 * @file
 * Code for the Rocket Chat oAuth Login feature.
 */

/**
 * Implements hook_help().
 *
 * @param $path
 *    Path to render the help on.
 * @param $arg
 *    Arguments on this path.
 * @return string
 * @see \hook_help()
 */
function rocket_chat_oauth_login_help($path, $arg) {
  $output = "";
  switch ($path) {
    default:
      break;
    case 'admin/structure/oauth2-servers/manage/%':
      if ($arg[4] == "rocket_chat_oAuth_login") {
        $output .= <<<HTML
<div id="Rocketchat-logo">
<a href="//rocket.chat"><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
\t width="435.721px" height="85.242px" viewBox="62.402 -18.766 435.721 85.242"
\t enable-background="new 62.402 -18.766 435.721 85.242" xml:space="preserve">
<g>
\t<path fill="#04436A" d="M205.456,22.207c0,4.297-1.603,7.119-4.681,8.465l4.425,16.803c0.192,0.771-0.192,1.154-0.898,1.154h-6.67
\t\tc-0.641,0-0.961-0.32-1.09-0.898l-4.297-16.289h-4.425v16.162c0,0.642-0.384,1.025-1.026,1.025h-6.67
\t\tc-0.641,0-1.026-0.385-1.026-1.025V-1.651c0-0.641,0.385-1.026,1.026-1.026h16.097c6.028,0,9.235,3.207,9.235,9.235V22.207
\t\tL205.456,22.207z M194.169,22.976c1.667,0,2.565-0.898,2.565-2.565V8.354c0-1.667-0.898-2.564-2.565-2.564h-6.349v17.187
\t\tL194.169,22.976L194.169,22.976z"/>
\t<path fill="#04436A" d="M210.583,6.558c0-6.028,3.206-9.235,9.235-9.235h7.183c6.028,0,9.235,3.207,9.235,9.235v32.836
\t\tc0,6.027-3.207,9.234-9.235,9.234h-7.183c-6.029,0-9.235-3.207-9.235-9.234V6.558z M225.397,40.355
\t\tc1.667,0,2.565-0.834,2.565-2.565V8.162c0-1.667-0.898-2.565-2.565-2.565h-3.719c-1.667,0-2.565,0.898-2.565,2.565v29.629
\t\tc0,1.73,0.898,2.564,2.565,2.564H225.397L225.397,40.355z"/>
\t<path fill="#04436A" d="M268.362,13.484c0,0.642-0.385,1.026-1.025,1.026h-6.413c-0.706,0-1.026-0.384-1.026-1.026v-5.13
\t\tc0-1.667-0.897-2.564-2.564-2.564h-3.335c-1.731,0-2.565,0.897-2.565,2.564V37.6c0,1.731,0.897,2.563,2.565,2.563h3.335
\t\tc1.667,0,2.564-0.833,2.564-2.563v-5.132c0-0.642,0.32-1.026,1.026-1.026h6.413c0.643,0,1.025,0.384,1.025,1.026v6.927
\t\tc0,6.027-3.271,9.234-9.234,9.234h-7.183c-6.028,0-9.299-3.207-9.299-9.234V6.558c0-6.028,3.271-9.235,9.299-9.235h7.183
\t\tc5.964,0,9.234,3.207,9.234,9.235V13.484z"/>
\t<path fill="#04436A" d="M295.422,48.629c-0.771,0-1.218-0.32-1.476-0.961l-8.079-19.048l-2.374,4.554v14.172
\t\tc0,0.834-0.448,1.283-1.282,1.283h-6.157c-0.834,0-1.283-0.449-1.283-1.283v-48.74c0-0.833,0.449-1.283,1.283-1.283h6.157
\t\tc0.833,0,1.282,0.449,1.282,1.283v19.881l9.876-20.202c0.321-0.641,0.771-0.962,1.476-0.962h6.733c0.962,0,1.347,0.642,0.897,1.539
\t\tl-10.901,22.382l11.606,25.91c0.449,0.834,0.064,1.475-0.961,1.475H295.422z"/>
\t<path fill="#04436A" d="M333.45,4.763c0,0.641-0.257,1.09-1.026,1.09h-16.033v12.826h12.249c0.643,0,1.026,0.385,1.026,1.09v6.349
\t\tc0,0.706-0.385,1.091-1.026,1.091h-12.249v12.954h16.033c0.771,0,1.026,0.321,1.026,1.026v6.414c0,0.641-0.257,1.024-1.026,1.024
\t\th-23.6c-0.578,0-0.963-0.385-0.963-1.024V-1.651c0-0.641,0.385-1.026,0.963-1.026h23.6c0.771,0,1.026,0.385,1.026,1.026V4.763z"/>
\t<path fill="#04436A" d="M363.204-2.677c0.705,0,1.026,0.385,1.026,1.026v6.414c0,0.641-0.321,1.026-1.026,1.026h-7.439v41.814
\t\tc0,0.705-0.32,1.024-1.025,1.024h-6.67c-0.643,0-1.026-0.319-1.026-1.024V5.789h-7.438c-0.643,0-1.026-0.385-1.026-1.026v-6.414
\t\tc0-0.641,0.385-1.026,1.026-1.026H363.204z"/>
\t<path fill="#04436A" d="M363.585,41.445c0-0.834,0.449-1.282,1.283-1.282h5.836c0.834,0,1.282,0.448,1.282,1.282v5.899
\t\tc0,0.835-0.448,1.283-1.282,1.283h-5.836c-0.834,0-1.283-0.448-1.283-1.283V41.445z"/>
\t<path fill="#04436A" d="M404.114,13.484c0,0.642-0.386,1.026-1.026,1.026h-6.413c-0.705,0-1.025-0.384-1.025-1.026v-5.13
\t\tc0-1.667-0.897-2.564-2.564-2.564h-3.335c-1.732,0-2.565,0.897-2.565,2.564V37.6c0,1.731,0.897,2.563,2.565,2.563h3.335
\t\tc1.667,0,2.564-0.833,2.564-2.563v-5.132c0-0.642,0.32-1.026,1.025-1.026h6.413c0.643,0,1.026,0.384,1.026,1.026v6.927
\t\tc0,6.027-3.271,9.234-9.235,9.234h-7.183c-6.028,0-9.299-3.207-9.299-9.234V6.558c0-6.028,3.271-9.235,9.299-9.235h7.183
\t\tc5.965,0,9.235,3.207,9.235,9.235V13.484z"/>
\t<path fill="#04436A" d="M427.455-1.651c0-0.641,0.384-1.026,1.025-1.026h6.605c0.77,0,1.089,0.385,1.089,1.026v49.254
\t\tc0,0.641-0.32,1.024-1.089,1.024h-6.605c-0.643,0-1.025-0.385-1.025-1.024V27.209h-8.209v20.395c0,0.642-0.385,1.025-1.026,1.025
\t\th-6.604c-0.771,0-1.091-0.385-1.091-1.025V-1.651c0-0.641,0.32-1.026,1.091-1.026h6.604c0.643,0,1.026,0.385,1.026,1.026v20.394
\t\th8.209V-1.651L427.455-1.651z"/>
\t<path fill="#04436A" d="M465.419,48.629c-0.577,0-0.897-0.32-1.026-0.898l-1.795-9.362h-11.416l-1.73,9.362
\t\tc-0.129,0.578-0.449,0.898-1.026,0.898h-6.861c-0.705,0-1.026-0.385-0.835-1.09l10.646-49.318c0.129-0.641,0.513-0.898,1.09-0.898
\t\th8.915c0.577,0,0.962,0.257,1.09,0.898l10.646,49.318c0.129,0.705-0.128,1.09-0.897,1.09H465.419z M456.889,8.546l-4.104,22.382
\t\th8.209L456.889,8.546z"/>
\t<path fill="#04436A" d="M497.097-2.677c0.705,0,1.026,0.385,1.026,1.026v6.414c0,0.641-0.321,1.026-1.026,1.026h-7.438v41.814
\t\tc0,0.705-0.321,1.024-1.026,1.024h-6.67c-0.641,0-1.025-0.319-1.025-1.024V5.789h-7.438c-0.642,0-1.025-0.385-1.025-1.026v-6.414
\t\tc0-0.641,0.385-1.026,1.025-1.026H497.097z"/>
</g>
<path fill="#C1272D" d="M162.586,23.788c0-5.031-1.505-9.854-4.474-14.339c-2.666-4.025-6.401-7.588-11.1-10.591
\tc-9.074-5.796-21-8.989-33.579-8.989c-4.202,0-8.344,0.355-12.361,1.059c-2.492-2.333-5.41-4.432-8.497-6.091
\tc-16.494-7.994-30.172-0.188-30.172-0.188S75.12-4.904,73.052,4.253c-5.689,5.644-8.773,12.45-8.773,19.535
\tc0,0.022,0.001,0.045,0.001,0.068c0,0.022-0.001,0.044-0.001,0.068c0,7.085,3.083,13.891,8.773,19.534
\tc2.068,9.158-10.649,19.605-10.649,19.605s13.678,7.805,30.172-0.188c3.087-1.659,6.004-3.759,8.497-6.091
\tc4.018,0.703,8.159,1.058,12.361,1.058c12.58,0,24.505-3.191,33.579-8.987c4.699-3.003,8.434-6.565,11.1-10.592
\tc2.969-4.484,4.474-9.309,4.474-14.338c0-0.023-0.001-0.045-0.001-0.068S162.586,23.81,162.586,23.788z"/>
<path fill="#FFFFFF" d="M113.433-3.018c23.293,0,42.177,12.062,42.177,26.941c0,14.878-18.884,26.941-42.177,26.941
\tc-5.187,0-10.154-0.6-14.743-1.693c-4.664,5.61-14.924,13.411-24.891,10.89c3.242-3.482,8.045-9.366,7.017-19.058
\tc-5.974-4.648-9.56-10.597-9.56-17.08C71.255,9.043,90.139-3.018,113.433-3.018"/>
<g>
\t<g>
\t\t<circle fill="#C1272D" cx="113.433" cy="24.79" r="5.603"/>
\t</g>
\t<g>
\t\t<circle fill="#C1272D" cx="132.913" cy="24.79" r="5.603"/>
\t</g>
\t<g>
\t\t<circle fill="#C1272D" cx="93.952" cy="24.79" r="5.602"/>
\t</g>
</g>
<g>
\t<path fill="#CCCCCC" d="M113.433,47.319c-5.187,0-10.154-0.52-14.743-1.468c-4.118,4.294-12.6,10.066-21.39,9.854
\t\tc-1.158,1.755-2.417,3.19-3.501,4.355c9.967,2.521,20.227-5.279,24.891-10.89c4.589,1.094,9.557,1.693,14.743,1.693
\t\tc23.106,0,41.87-11.871,42.169-26.585C155.303,37.032,136.539,47.319,113.433,47.319z"/>
</g>
</svg>
</a>
</div>
HTML;
        $output .= '<h3>' . t('About') . '</h3>';
        $output .= '<p>' . t('The Node module manages the creation, editing, deletion, settings, and display of the main site content. Content items managed by the Node module are typically displayed as pages on your site, and include a title, some meta-data (author, creation time, content type, etc.), and optional fields containing text or other data (fields are managed by the <a href="@field">Field module</a>). For more information, see the online handbook entry for <a href="@node">Node module</a>.', array(
          '@node' => 'http://drupal.org/documentation/modules/node',
          '@field' => url('admin/help/field'),
        )) . '</p>';
        $output .= '<h3>' . t('Uses') . '</h3>';
        $output .= '<dl>';
        $output .= '<dt>' . t('Creating content') . '</dt>';
        $output .= '<dd>' . t('When new content is created, the Node module records basic information about the content, including the author, date of creation, and the <a href="@content-type">Content type</a>. It also manages the <em>publishing options</em>, which define whether or not the content is published, promoted to the front page of the site, and/or sticky at the top of content lists. Default settings can be configured for each <a href="@content-type">type of content</a> on your site.', array(
          '@content-type' => url('admin/structure/types'),
        )) . '</dd>';
        $output .= '<dt>' . t('Creating custom content types') . '</dt>';
        $output .= '<dd>' . t('The Node module gives users with the <em>Administer content types</em> permission the ability to <a href="@content-new">create new content types</a> in addition to the default ones already configured. Creating custom content types allows you the flexibility to add <a href="@field">fields</a> and configure default settings that suit the differing needs of various site content.', array(
          '@content-new' => url('admin/structure/types/add'),
          '@field' => url('admin/help/field'),
        )) . '</dd>';
        $output .= '<dt>' . t('Administering content') . '</dt>';
        $output .= '<dd>' . t('The <a href="@content">Content administration page</a> allows you to review and bulk manage your site content.', array(
          '@content' => url('admin/content'),
        )) . '</dd>';
        $output .= '<dt>' . t('Creating revisions') . '</dt>';
        $output .= '<dd>' . t('The Node module also enables you to create multiple versions of any content, and revert to older versions using the <em>Revision information</em> settings.') . '</dd>';
        $output .= '<dt>' . t('User permissions') . '</dt>';
        $output .= '<dd>' . t('The Node module makes a number of permissions available for each content type, which can be set by role on the <a href="@permissions">permissions page</a>.', array(
          '@permissions' => url('admin/people/permissions', array(
            'fragment' => 'module-node',
          )),
        )) . '</dd>';
        $output .= '</dl>';
      }
    case 'admin/help#rocket_chat_oAuth_login':
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('The Node module manages the creation, editing, deletion, settings, and display of the main site content. Content items managed by the Node module are typically displayed as pages on your site, and include a title, some meta-data (author, creation time, content type, etc.), and optional fields containing text or other data (fields are managed by the <a href="@field">Field module</a>). For more information, see the online handbook entry for <a href="@node">Node module</a>.', array(
        '@node' => 'http://drupal.org/documentation/modules/node',
        '@field' => url('admin/help/field'),
      )) . '</p>';
      $output .= '<h3>' . t('Uses') . '</h3>';
      $output .= '<dl>';
      $output .= '<dt>' . t('Creating content') . '</dt>';
      $output .= '<dd>' . t('When new content is created, the Node module records basic information about the content, including the author, date of creation, and the <a href="@content-type">Content type</a>. It also manages the <em>publishing options</em>, which define whether or not the content is published, promoted to the front page of the site, and/or sticky at the top of content lists. Default settings can be configured for each <a href="@content-type">type of content</a> on your site.', array(
        '@content-type' => url('admin/structure/types'),
      )) . '</dd>';
      $output .= '<dt>' . t('Creating custom content types') . '</dt>';
      $output .= '<dd>' . t('The Node module gives users with the <em>Administer content types</em> permission the ability to <a href="@content-new">create new content types</a> in addition to the default ones already configured. Creating custom content types allows you the flexibility to add <a href="@field">fields</a> and configure default settings that suit the differing needs of various site content.', array(
        '@content-new' => url('admin/structure/types/add'),
        '@field' => url('admin/help/field'),
      )) . '</dd>';
      $output .= '<dt>' . t('Administering content') . '</dt>';
      $output .= '<dd>' . t('The <a href="@content">Content administration page</a> allows you to review and bulk manage your site content.', array(
        '@content' => url('admin/content'),
      )) . '</dd>';
      $output .= '<dt>' . t('Creating revisions') . '</dt>';
      $output .= '<dd>' . t('The Node module also enables you to create multiple versions of any content, and revert to older versions using the <em>Revision information</em> settings.') . '</dd>';
      $output .= '<dt>' . t('User permissions') . '</dt>';
      $output .= '<dd>' . t('The Node module makes a number of permissions available for each content type, which can be set by role on the <a href="@permissions">permissions page</a>.', array(
        '@permissions' => url('admin/people/permissions', array(
          'fragment' => 'module-node',
        )),
      )) . '</dd>';
      $output .= '</dl>';
      break;
  }
  return $output;
}

/**
 * Implements hook_default_oauth2_server().
 */
function rocket_chat_oauth_login_default_oauth2_server() {
  $items = array();
  $items['rocket_chat_oAuth_login'] = entity_import('oauth2_server', '{
    "name" : "rocket_chat_oAuth_login",
    "label" : "Rocket.Chat+",
    "settings" : {
      "enforce_state" : true,
      "default_scope" : "",
      "allow_implicit" : 0,
      "use_openid_connect" : 1,
      "use_crypto_tokens" : 0,
      "grant_types" : {
        "authorization_code" : "authorization_code",
        "refresh_token" : "refresh_token",
        "client_credentials" : 0,
        "urn:ietf:params:oauth:grant-type:jwt-bearer" : 0,
        "password" : 0
      },
      "always_issue_new_refresh_token" : 1,
      "unset_refresh_token_after_use" : 1,
      "access_lifetime" : "3600",
      "id_lifetime" : "3600",
      "refresh_token_lifetime" : "1209600",
      "require_exact_redirect_uri" : 1
    },
    "rdf_mapping" : [],
    "scopes" : [
      {
        "name" : "openid",
        "description" : "Let Rocket.Chat+ know who you are on this Drupal",
        "rdf_mapping" : []
      },
      {
        "name" : "offline_access",
        "description" : "Can Rocket.Chat+ access the API when you\\u0027re not present.",
        "rdf_mapping" : []
      },
      {
        "name" : "email",
        "description" : "Let Rocket.Chat+ know your email address. (needed for account matching)",
        "rdf_mapping" : []
      },
      {
        "name" : "profile",
        "description" : "Let Rocket.Chat+ know your basic account information.",
        "rdf_mapping" : []
      }
    ]
  }');
  return $items;
}

Functions

Namesort descending Description
rocket_chat_oauth_login_default_oauth2_server Implements hook_default_oauth2_server().
rocket_chat_oauth_login_help Implements hook_help().