dev/core#2141 - Schema - Add OAuthClient and OAuthSysToken
[civicrm-core.git] / ext / oauth-client / CRM / OAuth / BAO / OAuthSysToken.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_OAuth_BAO_OAuthSysToken extends CRM_OAuth_DAO_OAuthSysToken {
18
19 private static $returnFields = ['id', 'client_id', 'expires'];
20
21 /**
22 * Create a new OAuthSysToken based on array-data
23 *
24 * @param array $params key-value pairs
25 * @return CRM_OAuth_DAO_OAuthSysToken|NULL
26 *
27 * public static function create($params) {
28 * $className = 'CRM_OAuth_DAO_OAuthSysToken';
29 * $entityName = 'OAuthSysToken';
30 * $hook = empty($params['id']) ? 'create' : 'edit';
31 *
32 * CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params);
33 * $instance = new $className();
34 * $instance->copyValues($params);
35 * $instance->save();
36 * CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance);
37 *
38 * return $instance;
39 * } */
40
41 /**
42 * Redact the content of a token.
43 *
44 * This is useful for processes which must internally use the entire token
45 * record -- but then report on their progress to a permissioned party.
46 *
47 * @param array $tokenRecord
48 * @return array
49 */
50 public static function redact($tokenRecord) {
51 if (!\CRM_Core_Permission::check('manage OAuth client secrets')) {
52 return \CRM_Utils_Array::subset($tokenRecord, self::$returnFields);
53 }
54 else {
55 return $tokenRecord;
56 }
57 }
58
59 }