PluginProbe ʕ •ᴥ•ʔ
PowerBI Embed Reports / 1.2.4
PowerBI Embed Reports v1.2.4
trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4
embed-power-bi-reports / API / Azure.php
embed-power-bi-reports / API Last commit date
Authorization.php 2 weeks ago Azure.php 2 weeks ago CustomerEPBR.php 2 weeks ago
Azure.php
164 lines
1 <?php
2 /**
3 * Handles Token Authorization.
4 *
5 * @package embed-outlook-teams-calendar-events/API
6 */
7
8 namespace MoEmbedPowerBI\API;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 /**
15 * Class to handle token authorization and API endpoints' requests.
16 */
17 class Azure {
18
19 /**
20 * Holds the Azure class instance.
21 *
22 * @var Azure
23 */
24 private static $obj;
25
26 /**
27 * Holds the Azure class endpoints.
28 *
29 * @var Azure
30 */
31 private $endpoints;
32
33 /**
34 * Holds the Azure class config.
35 *
36 * @var Azure
37 */
38 private $config;
39
40 /**
41 * Holds the Azure class scope.
42 *
43 * @var Azure
44 */
45 private $scope = 'https://graph.microsoft.com/.default';
46
47 /**
48 * Holds the Azure class handler.
49 *
50 * @var Azure
51 */
52 private $handler;
53
54 /**
55 * Holds the Azure class access token.
56 *
57 * @var string|false
58 */
59 private $access_token = false;
60
61 /**
62 * Holds the Azure class arguments.
63 *
64 * @var array
65 */
66 private $args = array();
67
68 /**
69 * Constructor of the class.
70 *
71 * @param array $config Holds the configurations array.
72 */
73 private function __construct( $config ) {
74 $this->config = $config;
75 $this->handler = Authorization::get_controller();
76 }
77
78 /**
79 * Object instance(Azure) getter method.
80 *
81 * @param array $config Holds the array of configurations.
82 * @return Azure
83 */
84 public static function get_client( $config ) {
85 if ( ! isset( self::$obj ) ) {
86 self::$obj = new Azure( $config );
87 self::$obj->set_endpoints();
88 }
89 return self::$obj;
90 }
91
92 /**
93 * Holds the Azure class endpoints.
94 *
95 * @return void
96 */
97 private function set_endpoints() {
98 $this->endpoints['authorize'] = 'https://login.microsoftonline.com/' . $this->config['tenant_id'] . '/oauth2/v2.0/authorize';
99 $this->endpoints['token'] = 'https://login.microsoftonline.com/' . $this->config['tenant_id'] . '/oauth2/v2.0/token';
100 $this->endpoints['users'] = 'https://graph.microsoft.com/beta/users/';
101 }
102
103 /**
104 * Getter method for the Azure class endpoints.
105 *
106 * @param string $endpoint Holds the endpoint name which you want.
107 * @return array
108 */
109 public function get_endpoints( $endpoint ) {
110 if ( 'token' === $endpoint ) {
111 return $this->endpoints['token'];}
112 if ( 'authorize' === $endpoint ) {
113 return $this->endpoints['authorize'];}
114 if ( 'users' === $endpoint ) {
115 return $this->endpoints['users'];}
116 }
117
118 /**
119 * Method to get the specific user detail.
120 *
121 * @return array
122 */
123 public function mo_epbr_get_specific_user_detail() {
124 $this->access_token = $this->handler->mo_epbr_get_access_token( $this->endpoints, $this->config, $this->scope );
125
126 $args = array(
127 'Authorization' => 'Bearer ' . $this->access_token,
128 );
129 $user_info_url = $this->endpoints['users'] . $this->config['upn_id'];
130 $users = $this->handler->mo_epbr_get_request( $user_info_url, $args );
131 if ( ! is_array( $users ) || count( $users ) <= 0 ) {
132 wp_die( esc_html( 'Unknown error occurred. Please try again later.' ) );
133 }
134 return $users;
135 }
136
137 /**
138 * Method to get the specific user detail.
139 *
140 * @return array
141 */
142 public function mo_epbr_get_new_access_token() {
143 $access_token = $this->handler->mo_epbr_get_access_token( $this->endpoints, $this->config, $this->scope );
144 if ( ! isset( $access_token['error'] ) ) {
145 $this->access_token = $access_token;
146 $this->args = array(
147 'Authorization' => 'Bearer ' . $access_token,
148 );
149 return $access_token;
150 }
151 return false;
152 }
153
154 /**
155 * Holds the Azure class scope.
156 *
157 * @param string $scopes Hold the scope passed to be set.
158 * @return void
159 */
160 public function set_scope( $scopes ) {
161 $this->scope = $scopes;
162 }
163 }
164