Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/google-site-kit/includes/Core/Util/Scopes.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/**
3
+
* Class Google\Site_Kit\Core\Util\Scopes
4
+
*
5
+
* @package Google\Site_Kit\Core\Util
6
+
* @copyright 2021 Google LLC
7
+
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
8
+
* @link https://sitekit.withgoogle.com
9
+
*/
10
+
11
+
namespace Google\Site_Kit\Core\Util;
12
+
13
+
/**
14
+
* Utility class for handling generic OAuth scope functions.
15
+
*
16
+
* @since 1.9.0
17
+
* @access private
18
+
* @ignore
19
+
*/
20
+
class Scopes {
21
+
22
+
/**
23
+
* Mapping of requested scope to satisfying scopes.
24
+
*
25
+
* @since 1.9.0
26
+
*
27
+
* @var array
28
+
*/
29
+
protected static $map = array(
30
+
'https://www.googleapis.com/auth/adsense.readonly' => array(
31
+
'https://www.googleapis.com/auth/adsense',
32
+
),
33
+
'https://www.googleapis.com/auth/analytics.readonly' => array(
34
+
'requires_all' => true,
35
+
'https://www.googleapis.com/auth/analytics',
36
+
'https://www.googleapis.com/auth/analytics.edit',
37
+
),
38
+
'https://www.googleapis.com/auth/tagmanager.readonly' => array(
39
+
'https://www.googleapis.com/auth/tagmanager.edit.containers',
40
+
),
41
+
'https://www.googleapis.com/auth/webmasters.readonly' => array(
42
+
'https://www.googleapis.com/auth/webmasters',
43
+
),
44
+
);
45
+
46
+
/**
47
+
* Tests if the given scope is satisfied by the given list of granted scopes.
48
+
*
49
+
* @since 1.9.0
50
+
*
51
+
* @param string $scope OAuth scope to test for.
52
+
* @param string[] $granted_scopes Available OAuth scopes to test the individual scope against.
53
+
* @return bool True if the given scope is satisfied, otherwise false.
54
+
*/
55
+
public static function is_satisfied_by( $scope, array $granted_scopes ) {
56
+
if ( in_array( $scope, $granted_scopes, true ) ) {
57
+
return true;
58
+
}
59
+
60
+
if ( empty( self::$map[ $scope ] ) ) {
61
+
return false;
62
+
}
63
+
64
+
$satisfying_scopes = array_filter( self::$map[ $scope ], 'is_string' );
65
+
66
+
if ( ! empty( self::$map[ $scope ]['requires_all'] ) ) {
67
+
// Return true if all satisfying scopes are present, otherwise false.
68
+
return ! array_diff( $satisfying_scopes, $granted_scopes );
69
+
}
70
+
71
+
// Return true if any of the scopes are present, otherwise false.
72
+
return (bool) array_intersect( $satisfying_scopes, $granted_scopes );
73
+
}
74
+
75
+
/**
76
+
* Tests if all the given scopes are satisfied by the list of granted scopes.
77
+
*
78
+
* @since 1.9.0
79
+
*
80
+
* @param string[] $scopes OAuth scopes to test.
81
+
* @param string[] $granted_scopes OAuth scopes to test $scopes against.
82
+
* @return bool True if all given scopes are satisfied, otherwise false.
83
+
*/
84
+
public static function are_satisfied_by( array $scopes, array $granted_scopes ) {
85
+
foreach ( $scopes as $scope ) {
86
+
if ( ! self::is_satisfied_by( $scope, $granted_scopes ) ) {
87
+
return false;
88
+
}
89
+
}
90
+
91
+
return true;
92
+
}
93
+
}
94
+