PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.9.2
Jetpack – WP Security, Backup, Speed, & Growth v6.9.2
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / sal / class.json-api-token.php

class.json-api-token.php in Jetpack – WP Security, Backup, Speed, & Growth 6.9.2, at sal/class.json-api-token.php

61 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * So that we have a real class instead of just passing around an array
5 */
6 class SAL_Token {
7
8 public $blog_id;
9 public $user_id;
10 public $scope;
11 public $client_id;
12 public $external_user_id;
13 public $external_user_code;
14 public $auth_type;
15
16 function __construct( $blog_id, $user_id, $scope, $client_id, $external_user_id, $external_user_code, $auth_type ) {
17 $this->blog_id = $blog_id; // if blog_id is set and scope is not global, limit to that blog
18 $this->user_id = $user_id;
19 $this->client_id = $client_id;
20 $this->scope = $scope;
21 $this->external_user_id = $external_user_id;
22 $this->external_user_code = $external_user_code;
23 $this->auth_type = $auth_type;
24 }
25
26 public function is_global() {
27 return $scope === 'global';
28 }
29
30 static function for_anonymous_user() {
31 return new SAL_Token(
32 null,
33 get_current_user_id(),
34 null, // there's only ever one scope in our current API implementation, auth or global
35 null,
36 null,
37 null,
38 null
39 );
40 }
41
42 static function from_rest_token( $token ) {
43 $user_id = isset( $token['user_id'] ) ? $token['user_id'] : get_current_user_id();
44 $scope = isset( $token['scope'] ) ? $token['scope'][0] : null;
45 $client_id = isset( $token['client_id'] ) ? $token['client_id'] : null;
46 $external_user_id = isset( $token['external_user_id'] ) ? $token['external_user_id'] : null;
47 $external_user_code = isset( $token['external_user_code'] ) ? $token['external_user_code'] : null;
48 $auth = isset( $token['auth'] ) ? $token['auth'] : null;
49
50 return new SAL_Token(
51 $token['blog_id'],
52 $user_id,
53 $scope, // there's only ever one scope in our current API implementation, auth or global
54 $client_id,
55 $external_user_id,
56 $external_user_code,
57 $auth
58 );
59 }
60 }
61