PluginProbe ʕ •ᴥ•ʔ
Presto Player / trunk
Presto Player vtrunk
4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.4 4.2.3 4.2.2 4.2.0 4.2.1 trunk 1.10.0 1.10.1 1.10.2 1.11.0 1.12.0 1.13.0 1.14.0 1.14.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.13 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3-beta1 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.0-beta1 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1.0 3.1.1 3.1.2 3.1.3 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4
presto-player / inc / Services / OAuth / Constants.php
presto-player / inc / Services / OAuth Last commit date
Authentication 1 week ago Consent 1 week ago Endpoints 1 week ago Helpers 1 week ago PKCE 1 week ago Storage 1 week ago Bootstrap.php 1 week ago Constants.php 1 week ago Module.php 1 week ago
Constants.php
147 lines
1 <?php
2 /**
3 * OAuth-related constants.
4 *
5 * @package PrestoPlayer
6 * @subpackage Services\OAuth
7 */
8
9 namespace PrestoPlayer\Services\OAuth;
10
11 /**
12 * Central place for OAuth scopes, TTLs and REST path fragments.
13 */
14 class Constants {
15
16 /**
17 * Read-only abilities scope.
18 *
19 * @var string
20 */
21 public const SCOPE_READ = 'presto:read';
22
23 /**
24 * Create / update abilities scope.
25 *
26 * @var string
27 */
28 public const SCOPE_WRITE = 'presto:write';
29
30 /**
31 * Delete (destructive) abilities scope.
32 *
33 * @var string
34 */
35 public const SCOPE_DESTRUCTIVE = 'presto:destructive';
36
37 /**
38 * Settings / license / admin operations scope.
39 *
40 * @var string
41 */
42 public const SCOPE_ADMIN = 'presto:admin';
43
44 /**
45 * Access token lifetime in seconds (1 hour).
46 *
47 * @var int
48 */
49 public const ACCESS_TOKEN_TTL = 3600;
50
51 /**
52 * Refresh token lifetime in seconds (30 days).
53 *
54 * @var int
55 */
56 public const REFRESH_TOKEN_TTL = 2592000;
57
58 /**
59 * Absolute refresh-token lifetime in seconds (90 days). A rotation chain is
60 * refused once it passes this cap measured from the original authorization,
61 * so a client that keeps refreshing can't hold a grant forever.
62 *
63 * @var int
64 */
65 public const REFRESH_TOKEN_ABSOLUTE_TTL = 7776000;
66
67 /**
68 * Authorization code lifetime in seconds (10 minutes).
69 *
70 * @var int
71 */
72 public const AUTH_CODE_TTL = 600;
73
74 /**
75 * REST namespace shared by every Presto Player route.
76 *
77 * @var string
78 */
79 public const REST_NAMESPACE = 'presto-player/v1';
80
81 /**
82 * Base path segment under the namespace for OAuth endpoints.
83 *
84 * @var string
85 */
86 public const OAUTH_BASE = 'oauth';
87
88 /**
89 * Site-relative path for the browser-facing consent screen. Served outside
90 * the REST stack (via parse_request) so WordPress core's REST cookie-nonce
91 * check can't log the user out on GET or 403 the consent POST.
92 *
93 * @var string
94 */
95 public const AUTHORIZE_PATH = '/presto-player/oauth/authorize';
96
97 /**
98 * The WordPress capability a user must have to grant the given OAuth scope.
99 *
100 * Read/write map to edit_posts; the privileged destructive/admin scopes
101 * require manage_options, so an Editor can't consent a client into deleting
102 * content or changing settings.
103 *
104 * @param string $scope Scope identifier.
105 * @return string Capability name.
106 */
107 public static function capabilityForScope( $scope ) {
108 switch ( $scope ) {
109 case self::SCOPE_ADMIN:
110 case self::SCOPE_DESTRUCTIVE:
111 return 'manage_options';
112 default:
113 return 'edit_posts';
114 }
115 }
116
117 /**
118 * Resolve the full list of allowed OAuth scopes.
119 *
120 * Pro (or third parties) can append their own identifiers via the
121 * `presto_player_oauth_scopes` filter. The four built-in scopes are always
122 * present in the return value regardless of filter mutations.
123 *
124 * @return array<int, string>
125 */
126 public static function allowedScopes() {
127 $default = array(
128 self::SCOPE_READ,
129 self::SCOPE_WRITE,
130 self::SCOPE_DESTRUCTIVE,
131 self::SCOPE_ADMIN,
132 );
133
134 /**
135 * Filters the list of allowed OAuth scope identifiers.
136 *
137 * @param array<int, string> $scopes Default scope identifiers.
138 */
139 $filtered = apply_filters( 'presto_player_oauth_scopes', $default );
140 if ( ! is_array( $filtered ) ) {
141 $filtered = array();
142 }
143
144 return array_values( array_unique( array_merge( $default, array_filter( array_map( 'strval', $filtered ) ) ) ) );
145 }
146 }
147