Passed
Push — master ( 14fbd7...a7a005 )
by
unknown
55s queued 15s
created
src/User/Activity.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -14,60 +14,60 @@
 block discarded – undo
14 14
  */
15 15
 final class Activity
16 16
 {
17
-    /**
18
-     * activity id on the provider side, usually given as integer
19
-     *
20
-     * @var string
21
-     */
22
-    public $id = null;
17
+	/**
18
+	 * activity id on the provider side, usually given as integer
19
+	 *
20
+	 * @var string
21
+	 */
22
+	public $id = null;
23 23
 
24
-    /**
25
-     * activity date of creation
26
-     *
27
-     * @var string
28
-     */
29
-    public $date = null;
24
+	/**
25
+	 * activity date of creation
26
+	 *
27
+	 * @var string
28
+	 */
29
+	public $date = null;
30 30
 
31
-    /**
32
-     * activity content as a string
33
-     *
34
-     * @var string
35
-     */
36
-    public $text = null;
31
+	/**
32
+	 * activity content as a string
33
+	 *
34
+	 * @var string
35
+	 */
36
+	public $text = null;
37 37
 
38
-    /**
39
-     * user who created the activity
40
-     *
41
-     * @var object
42
-     */
43
-    public $user = null;
38
+	/**
39
+	 * user who created the activity
40
+	 *
41
+	 * @var object
42
+	 */
43
+	public $user = null;
44 44
 
45
-    /**
46
-     *
47
-     */
48
-    public function __construct()
49
-    {
50
-        $this->user = new \stdClass();
45
+	/**
46
+	 *
47
+	 */
48
+	public function __construct()
49
+	{
50
+		$this->user = new \stdClass();
51 51
 
52
-        // typically, we should have a few information about the user who created the event from social apis
53
-        $this->user->identifier = null;
54
-        $this->user->displayName = null;
55
-        $this->user->profileURL = null;
56
-        $this->user->photoURL = null;
57
-    }
52
+		// typically, we should have a few information about the user who created the event from social apis
53
+		$this->user->identifier = null;
54
+		$this->user->displayName = null;
55
+		$this->user->profileURL = null;
56
+		$this->user->photoURL = null;
57
+	}
58 58
 
59
-    /**
60
-     * Prevent the providers adapters from adding new fields.
61
-     *
62
-     * @throws UnexpectedValueException
63
-     * @var string $name
64
-     *
65
-     * @var mixed $value
66
-     *
67
-     */
68
-    public function __set($name, $value)
69
-    {
70
-        // phpcs:ignore
71
-        throw new UnexpectedValueException(sprintf('Adding new property "%s\' to %s is not allowed.', $name, __CLASS__));
72
-    }
59
+	/**
60
+	 * Prevent the providers adapters from adding new fields.
61
+	 *
62
+	 * @throws UnexpectedValueException
63
+	 * @var string $name
64
+	 *
65
+	 * @var mixed $value
66
+	 *
67
+	 */
68
+	public function __set($name, $value)
69
+	{
70
+		// phpcs:ignore
71
+		throw new UnexpectedValueException(sprintf('Adding new property "%s\' to %s is not allowed.', $name, __CLASS__));
72
+	}
73 73
 }
Please login to merge, or discard this patch.
src/User/Contact.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -14,65 +14,65 @@
 block discarded – undo
14 14
  */
15 15
 final class Contact
16 16
 {
17
-    /**
18
-     * The Unique contact user ID
19
-     *
20
-     * @var string
21
-     */
22
-    public $identifier = null;
17
+	/**
18
+	 * The Unique contact user ID
19
+	 *
20
+	 * @var string
21
+	 */
22
+	public $identifier = null;
23 23
 
24
-    /**
25
-     * User website, blog, web page
26
-     *
27
-     * @var string
28
-     */
29
-    public $webSiteURL = null;
24
+	/**
25
+	 * User website, blog, web page
26
+	 *
27
+	 * @var string
28
+	 */
29
+	public $webSiteURL = null;
30 30
 
31
-    /**
32
-     * URL link to profile page on the IDp web site
33
-     *
34
-     * @var string
35
-     */
36
-    public $profileURL = null;
31
+	/**
32
+	 * URL link to profile page on the IDp web site
33
+	 *
34
+	 * @var string
35
+	 */
36
+	public $profileURL = null;
37 37
 
38
-    /**
39
-     * URL link to user photo or avatar
40
-     *
41
-     * @var string
42
-     */
43
-    public $photoURL = null;
38
+	/**
39
+	 * URL link to user photo or avatar
40
+	 *
41
+	 * @var string
42
+	 */
43
+	public $photoURL = null;
44 44
 
45
-    /**
46
-     * User displayName provided by the IDp or a concatenation of first and last name
47
-     *
48
-     * @var string
49
-     */
50
-    public $displayName = null;
45
+	/**
46
+	 * User displayName provided by the IDp or a concatenation of first and last name
47
+	 *
48
+	 * @var string
49
+	 */
50
+	public $displayName = null;
51 51
 
52
-    /**
53
-     * A short about_me
54
-     *
55
-     * @var string
56
-     */
57
-    public $description = null;
52
+	/**
53
+	 * A short about_me
54
+	 *
55
+	 * @var string
56
+	 */
57
+	public $description = null;
58 58
 
59
-    /**
60
-     * User email. Not all of IDp grant access to the user email
61
-     *
62
-     * @var string
63
-     */
64
-    public $email = null;
59
+	/**
60
+	 * User email. Not all of IDp grant access to the user email
61
+	 *
62
+	 * @var string
63
+	 */
64
+	public $email = null;
65 65
 
66
-    /**
67
-     * Prevent the providers adapters from adding new fields.
68
-     *
69
-     * @param string $name
70
-     * @param mixed $value
71
-     *
72
-     * @throws UnexpectedValueException
73
-     */
74
-    public function __set($name, $value)
75
-    {
76
-        throw new UnexpectedValueException(sprintf('Adding new property "%s" to %s is not allowed.', $name, __CLASS__));
77
-    }
66
+	/**
67
+	 * Prevent the providers adapters from adding new fields.
68
+	 *
69
+	 * @param string $name
70
+	 * @param mixed $value
71
+	 *
72
+	 * @throws UnexpectedValueException
73
+	 */
74
+	public function __set($name, $value)
75
+	{
76
+		throw new UnexpectedValueException(sprintf('Adding new property "%s" to %s is not allowed.', $name, __CLASS__));
77
+	}
78 78
 }
Please login to merge, or discard this patch.
src/Storage/Session.php 2 patches
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -14,117 +14,117 @@
 block discarded – undo
14 14
  */
15 15
 class Session implements StorageInterface
16 16
 {
17
-    /**
18
-     * Namespace
19
-     *
20
-     * @var string
21
-     */
22
-    protected $storeNamespace = 'HYBRIDAUTH::STORAGE';
23
-
24
-    /**
25
-     * Key prefix
26
-     *
27
-     * @var string
28
-     */
29
-    protected $keyPrefix = '';
30
-
31
-    /**
32
-     * Initiate a new session
33
-     *
34
-     * @throws RuntimeException
35
-     */
36
-    public function __construct()
37
-    {
38
-        if (session_id()) {
39
-            return;
40
-        }
41
-
42
-        if (headers_sent()) {
43
-            // phpcs:ignore
44
-            throw new RuntimeException('HTTP headers already sent to browser and Hybridauth won\'t be able to start/resume PHP session. To resolve this, session_start() must be called before outputing any data.');
45
-        }
46
-
47
-        if (!session_start()) {
48
-            throw new RuntimeException('PHP session failed to start.');
49
-        }
50
-    }
51
-
52
-    /**
53
-     * {@inheritdoc}
54
-     */
55
-    public function get($key)
56
-    {
57
-        $key = $this->keyPrefix . strtolower($key);
58
-
59
-        if (isset($_SESSION[$this->storeNamespace], $_SESSION[$this->storeNamespace][$key])) {
60
-            $value = $_SESSION[$this->storeNamespace][$key];
61
-
62
-            if (is_array($value) && array_key_exists('lateObject', $value)) {
63
-                $value = unserialize($value['lateObject']);
64
-            }
65
-
66
-            return $value;
67
-        }
68
-
69
-        return null;
70
-    }
71
-
72
-    /**
73
-     * {@inheritdoc}
74
-     */
75
-    public function set($key, $value)
76
-    {
77
-        $key = $this->keyPrefix . strtolower($key);
78
-
79
-        if (is_object($value)) {
80
-            // We encapsulate as our classes may be defined after session is initialized.
81
-            $value = ['lateObject' => serialize($value)];
82
-        }
83
-
84
-        $_SESSION[$this->storeNamespace][$key] = $value;
85
-    }
86
-
87
-    /**
88
-     * {@inheritdoc}
89
-     */
90
-    public function clear()
91
-    {
92
-        $_SESSION[$this->storeNamespace] = [];
93
-    }
94
-
95
-    /**
96
-     * {@inheritdoc}
97
-     */
98
-    public function delete($key)
99
-    {
100
-        $key = $this->keyPrefix . strtolower($key);
101
-
102
-        if (isset($_SESSION[$this->storeNamespace], $_SESSION[$this->storeNamespace][$key])) {
103
-            $tmp = $_SESSION[$this->storeNamespace];
104
-
105
-            unset($tmp[$key]);
106
-
107
-            $_SESSION[$this->storeNamespace] = $tmp;
108
-        }
109
-    }
110
-
111
-    /**
112
-     * {@inheritdoc}
113
-     */
114
-    public function deleteMatch($key)
115
-    {
116
-        $key = $this->keyPrefix . strtolower($key);
117
-
118
-        if (isset($_SESSION[$this->storeNamespace]) && count($_SESSION[$this->storeNamespace])) {
119
-            $tmp = $_SESSION[$this->storeNamespace];
120
-
121
-            foreach ($tmp as $k => $v) {
122
-                if (strstr($k, $key)) {
123
-                    unset($tmp[$k]);
124
-                }
125
-            }
126
-
127
-            $_SESSION[$this->storeNamespace] = $tmp;
128
-        }
129
-    }
17
+	/**
18
+	 * Namespace
19
+	 *
20
+	 * @var string
21
+	 */
22
+	protected $storeNamespace = 'HYBRIDAUTH::STORAGE';
23
+
24
+	/**
25
+	 * Key prefix
26
+	 *
27
+	 * @var string
28
+	 */
29
+	protected $keyPrefix = '';
30
+
31
+	/**
32
+	 * Initiate a new session
33
+	 *
34
+	 * @throws RuntimeException
35
+	 */
36
+	public function __construct()
37
+	{
38
+		if (session_id()) {
39
+			return;
40
+		}
41
+
42
+		if (headers_sent()) {
43
+			// phpcs:ignore
44
+			throw new RuntimeException('HTTP headers already sent to browser and Hybridauth won\'t be able to start/resume PHP session. To resolve this, session_start() must be called before outputing any data.');
45
+		}
46
+
47
+		if (!session_start()) {
48
+			throw new RuntimeException('PHP session failed to start.');
49
+		}
50
+	}
51
+
52
+	/**
53
+	 * {@inheritdoc}
54
+	 */
55
+	public function get($key)
56
+	{
57
+		$key = $this->keyPrefix . strtolower($key);
58
+
59
+		if (isset($_SESSION[$this->storeNamespace], $_SESSION[$this->storeNamespace][$key])) {
60
+			$value = $_SESSION[$this->storeNamespace][$key];
61
+
62
+			if (is_array($value) && array_key_exists('lateObject', $value)) {
63
+				$value = unserialize($value['lateObject']);
64
+			}
65
+
66
+			return $value;
67
+		}
68
+
69
+		return null;
70
+	}
71
+
72
+	/**
73
+	 * {@inheritdoc}
74
+	 */
75
+	public function set($key, $value)
76
+	{
77
+		$key = $this->keyPrefix . strtolower($key);
78
+
79
+		if (is_object($value)) {
80
+			// We encapsulate as our classes may be defined after session is initialized.
81
+			$value = ['lateObject' => serialize($value)];
82
+		}
83
+
84
+		$_SESSION[$this->storeNamespace][$key] = $value;
85
+	}
86
+
87
+	/**
88
+	 * {@inheritdoc}
89
+	 */
90
+	public function clear()
91
+	{
92
+		$_SESSION[$this->storeNamespace] = [];
93
+	}
94
+
95
+	/**
96
+	 * {@inheritdoc}
97
+	 */
98
+	public function delete($key)
99
+	{
100
+		$key = $this->keyPrefix . strtolower($key);
101
+
102
+		if (isset($_SESSION[$this->storeNamespace], $_SESSION[$this->storeNamespace][$key])) {
103
+			$tmp = $_SESSION[$this->storeNamespace];
104
+
105
+			unset($tmp[$key]);
106
+
107
+			$_SESSION[$this->storeNamespace] = $tmp;
108
+		}
109
+	}
110
+
111
+	/**
112
+	 * {@inheritdoc}
113
+	 */
114
+	public function deleteMatch($key)
115
+	{
116
+		$key = $this->keyPrefix . strtolower($key);
117
+
118
+		if (isset($_SESSION[$this->storeNamespace]) && count($_SESSION[$this->storeNamespace])) {
119
+			$tmp = $_SESSION[$this->storeNamespace];
120
+
121
+			foreach ($tmp as $k => $v) {
122
+				if (strstr($k, $key)) {
123
+					unset($tmp[$k]);
124
+				}
125
+			}
126
+
127
+			$_SESSION[$this->storeNamespace] = $tmp;
128
+		}
129
+	}
130 130
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
             throw new RuntimeException('HTTP headers already sent to browser and Hybridauth won\'t be able to start/resume PHP session. To resolve this, session_start() must be called before outputing any data.');
45 45
         }
46 46
 
47
-        if (!session_start()) {
47
+        if ( ! session_start()) {
48 48
             throw new RuntimeException('PHP session failed to start.');
49 49
         }
50 50
     }
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public function get($key)
56 56
     {
57
-        $key = $this->keyPrefix . strtolower($key);
57
+        $key = $this->keyPrefix.strtolower($key);
58 58
 
59 59
         if (isset($_SESSION[$this->storeNamespace], $_SESSION[$this->storeNamespace][$key])) {
60 60
             $value = $_SESSION[$this->storeNamespace][$key];
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      */
75 75
     public function set($key, $value)
76 76
     {
77
-        $key = $this->keyPrefix . strtolower($key);
77
+        $key = $this->keyPrefix.strtolower($key);
78 78
 
79 79
         if (is_object($value)) {
80 80
             // We encapsulate as our classes may be defined after session is initialized.
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
      */
98 98
     public function delete($key)
99 99
     {
100
-        $key = $this->keyPrefix . strtolower($key);
100
+        $key = $this->keyPrefix.strtolower($key);
101 101
 
102 102
         if (isset($_SESSION[$this->storeNamespace], $_SESSION[$this->storeNamespace][$key])) {
103 103
             $tmp = $_SESSION[$this->storeNamespace];
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      */
114 114
     public function deleteMatch($key)
115 115
     {
116
-        $key = $this->keyPrefix . strtolower($key);
116
+        $key = $this->keyPrefix.strtolower($key);
117 117
 
118 118
         if (isset($_SESSION[$this->storeNamespace]) && count($_SESSION[$this->storeNamespace])) {
119 119
             $tmp = $_SESSION[$this->storeNamespace];
Please login to merge, or discard this patch.
src/Provider/Medium.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -17,72 +17,72 @@
 block discarded – undo
17 17
  */
18 18
 class Medium extends OAuth2
19 19
 {
20
-    /**
21
-     * {@inheritdoc}
22
-     */
23
-    protected $scope = 'basicProfile';
20
+	/**
21
+	 * {@inheritdoc}
22
+	 */
23
+	protected $scope = 'basicProfile';
24 24
 
25
-    /**
26
-     * {@inheritdoc}
27
-     */
28
-    protected $apiBaseUrl = 'https://api.medium.com/v1/';
25
+	/**
26
+	 * {@inheritdoc}
27
+	 */
28
+	protected $apiBaseUrl = 'https://api.medium.com/v1/';
29 29
 
30
-    /**
31
-     * {@inheritdoc}
32
-     */
33
-    protected $authorizeUrl = 'https://medium.com/m/oauth/authorize';
30
+	/**
31
+	 * {@inheritdoc}
32
+	 */
33
+	protected $authorizeUrl = 'https://medium.com/m/oauth/authorize';
34 34
 
35
-    /**
36
-     * {@inheritdoc}
37
-     */
38
-    protected $accessTokenUrl = 'https://api.medium.com/v1/tokens';
35
+	/**
36
+	 * {@inheritdoc}
37
+	 */
38
+	protected $accessTokenUrl = 'https://api.medium.com/v1/tokens';
39 39
 
40
-    /**
41
-     * {@inheritdoc}
42
-     */
43
-    protected $apiDocumentation = 'https://github.com/Medium/medium-api-docs';
40
+	/**
41
+	 * {@inheritdoc}
42
+	 */
43
+	protected $apiDocumentation = 'https://github.com/Medium/medium-api-docs';
44 44
 
45
-    /**
46
-     * {@inheritdoc}
47
-     */
48
-    protected function initialize()
49
-    {
50
-        parent::initialize();
45
+	/**
46
+	 * {@inheritdoc}
47
+	 */
48
+	protected function initialize()
49
+	{
50
+		parent::initialize();
51 51
 
52
-        if ($this->isRefreshTokenAvailable()) {
53
-            $this->tokenRefreshParameters += [
54
-                'client_id' => $this->clientId,
55
-                'client_secret' => $this->clientSecret,
56
-            ];
57
-        }
58
-    }
52
+		if ($this->isRefreshTokenAvailable()) {
53
+			$this->tokenRefreshParameters += [
54
+				'client_id' => $this->clientId,
55
+				'client_secret' => $this->clientSecret,
56
+			];
57
+		}
58
+	}
59 59
 
60
-    /**
61
-     * {@inheritdoc}
62
-     *
63
-     * See: https://github.com/Medium/medium-api-docs#getting-the-authenticated-users-details
64
-     */
65
-    public function getUserProfile()
66
-    {
67
-        $response = $this->apiRequest('me');
60
+	/**
61
+	 * {@inheritdoc}
62
+	 *
63
+	 * See: https://github.com/Medium/medium-api-docs#getting-the-authenticated-users-details
64
+	 */
65
+	public function getUserProfile()
66
+	{
67
+		$response = $this->apiRequest('me');
68 68
 
69
-        $data = new Data\Collection($response);
69
+		$data = new Data\Collection($response);
70 70
 
71
-        $userProfile = new User\Profile();
72
-        $data = $data->filter('data');
71
+		$userProfile = new User\Profile();
72
+		$data = $data->filter('data');
73 73
 
74
-        $full_name = explode(' ', $data->get('name'));
75
-        if (count($full_name) < 2) {
76
-            $full_name[1] = '';
77
-        }
74
+		$full_name = explode(' ', $data->get('name'));
75
+		if (count($full_name) < 2) {
76
+			$full_name[1] = '';
77
+		}
78 78
 
79
-        $userProfile->identifier = $data->get('id');
80
-        $userProfile->displayName = $data->get('username');
81
-        $userProfile->profileURL = $data->get('imageUrl');
82
-        $userProfile->firstName = $full_name[0];
83
-        $userProfile->lastName = $full_name[1];
84
-        $userProfile->profileURL = $data->get('url');
79
+		$userProfile->identifier = $data->get('id');
80
+		$userProfile->displayName = $data->get('username');
81
+		$userProfile->profileURL = $data->get('imageUrl');
82
+		$userProfile->firstName = $full_name[0];
83
+		$userProfile->lastName = $full_name[1];
84
+		$userProfile->profileURL = $data->get('url');
85 85
 
86
-        return $userProfile;
87
-    }
86
+		return $userProfile;
87
+	}
88 88
 }
Please login to merge, or discard this patch.
src/Provider/Instagram.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     {
63 63
         $collection = parent::validateAccessTokenExchange($response);
64 64
 
65
-        if (!$collection->exists('expires_in')) {
65
+        if ( ! $collection->exists('expires_in')) {
66 66
             // Instagram tokens always expire in an hour, but this is implicit not explicit
67 67
 
68 68
             $expires_in = 60 * 60;
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public function maintainToken()
93 93
     {
94
-        if (!$this->isConnected()) {
94
+        if ( ! $this->isConnected()) {
95 95
             return;
96 96
         }
97 97
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         $exchange_by_expiry_days = $this->config->get('exchange_by_expiry_days') ?: 45;
100 100
         if ($exchange_by_expiry_days !== null) {
101 101
             $projected_timestamp = time() + 60 * 60 * 24 * $exchange_by_expiry_days;
102
-            if (!$this->hasAccessTokenExpired() && $this->hasAccessTokenExpired($projected_timestamp)) {
102
+            if ( ! $this->hasAccessTokenExpired() && $this->hasAccessTokenExpired($projected_timestamp)) {
103 103
                 $this->exchangeAccessToken();
104 104
             }
105 105
         }
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
         ]);
145 145
 
146 146
         $data = new Collection($response);
147
-        if (!$data->exists('id')) {
147
+        if ( ! $data->exists('id')) {
148 148
             throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
149 149
         }
150 150
 
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
         $response = $this->apiRequest('me/media', 'GET', $params);
201 201
 
202 202
         $data = new Collection($response);
203
-        if (!$data->exists('data')) {
203
+        if ( ! $data->exists('data')) {
204 204
             throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
205 205
         }
206 206
 
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
         ]);
241 241
 
242 242
         $data = new Collection($response);
243
-        if (!$data->exists('id')) {
243
+        if ( ! $data->exists('id')) {
244 244
             throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
245 245
         }
246 246
 
Please login to merge, or discard this patch.
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -17,240 +17,240 @@
 block discarded – undo
17 17
  */
18 18
 class Instagram extends OAuth2
19 19
 {
20
-    /**
21
-     * {@inheritdoc}
22
-     */
23
-    protected $scope = 'user_profile,user_media';
24
-
25
-    /**
26
-     * {@inheritdoc}
27
-     */
28
-    protected $apiBaseUrl = 'https://graph.instagram.com';
29
-
30
-    /**
31
-     * {@inheritdoc}
32
-     */
33
-    protected $authorizeUrl = 'https://api.instagram.com/oauth/authorize';
34
-
35
-    /**
36
-     * {@inheritdoc}
37
-     */
38
-    protected $accessTokenUrl = 'https://api.instagram.com/oauth/access_token';
39
-
40
-    /**
41
-     * {@inheritdoc}
42
-     */
43
-    protected $apiDocumentation = 'https://developers.facebook.com/docs/instagram-basic-display-api';
44
-
45
-    /**
46
-     * {@inheritdoc}
47
-     */
48
-    protected function initialize()
49
-    {
50
-        parent::initialize();
51
-
52
-        // The Instagram API requires an access_token from authenticated users
53
-        // for each endpoint.
54
-        $accessToken = $this->getStoredData($this->accessTokenName);
55
-        $this->apiRequestParameters[$this->accessTokenName] = $accessToken;
56
-    }
57
-
58
-    /**
59
-     * {@inheritdoc}
60
-     */
61
-    protected function validateAccessTokenExchange($response)
62
-    {
63
-        $collection = parent::validateAccessTokenExchange($response);
64
-
65
-        if (!$collection->exists('expires_in')) {
66
-            // Instagram tokens always expire in an hour, but this is implicit not explicit
67
-
68
-            $expires_in = 60 * 60;
69
-
70
-            $expires_at = time() + $expires_in;
71
-
72
-            $this->storeData('expires_in', $expires_in);
73
-            $this->storeData('expires_at', $expires_at);
74
-        }
75
-
76
-        return $collection;
77
-    }
78
-
79
-    /**
80
-     * {@inheritdoc}
81
-     */
82
-    public function maintainToken()
83
-    {
84
-        if (!$this->isConnected()) {
85
-            return;
86
-        }
87
-
88
-        // Handle token exchange prior to the standard handler for an API request
89
-        $exchange_by_expiry_days = $this->config->get('exchange_by_expiry_days') ?: 45;
90
-        if ($exchange_by_expiry_days !== null) {
91
-            $projected_timestamp = time() + 60 * 60 * 24 * $exchange_by_expiry_days;
92
-            if (!$this->hasAccessTokenExpired() && $this->hasAccessTokenExpired($projected_timestamp)) {
93
-                $this->exchangeAccessToken();
94
-            }
95
-        }
96
-    }
97
-
98
-    /**
99
-     * Exchange the Access Token with one that expires further in the future.
100
-     *
101
-     * @return string Raw Provider API response
102
-     * @throws \Hybridauth\Exception\HttpClientFailureException
103
-     * @throws \Hybridauth\Exception\HttpRequestFailedException
104
-     * @throws InvalidAccessTokenException
105
-     */
106
-    public function exchangeAccessToken()
107
-    {
108
-        if ($this->getStoredData('expires_in') >= 5000000) {
109
-            /*
20
+	/**
21
+	 * {@inheritdoc}
22
+	 */
23
+	protected $scope = 'user_profile,user_media';
24
+
25
+	/**
26
+	 * {@inheritdoc}
27
+	 */
28
+	protected $apiBaseUrl = 'https://graph.instagram.com';
29
+
30
+	/**
31
+	 * {@inheritdoc}
32
+	 */
33
+	protected $authorizeUrl = 'https://api.instagram.com/oauth/authorize';
34
+
35
+	/**
36
+	 * {@inheritdoc}
37
+	 */
38
+	protected $accessTokenUrl = 'https://api.instagram.com/oauth/access_token';
39
+
40
+	/**
41
+	 * {@inheritdoc}
42
+	 */
43
+	protected $apiDocumentation = 'https://developers.facebook.com/docs/instagram-basic-display-api';
44
+
45
+	/**
46
+	 * {@inheritdoc}
47
+	 */
48
+	protected function initialize()
49
+	{
50
+		parent::initialize();
51
+
52
+		// The Instagram API requires an access_token from authenticated users
53
+		// for each endpoint.
54
+		$accessToken = $this->getStoredData($this->accessTokenName);
55
+		$this->apiRequestParameters[$this->accessTokenName] = $accessToken;
56
+	}
57
+
58
+	/**
59
+	 * {@inheritdoc}
60
+	 */
61
+	protected function validateAccessTokenExchange($response)
62
+	{
63
+		$collection = parent::validateAccessTokenExchange($response);
64
+
65
+		if (!$collection->exists('expires_in')) {
66
+			// Instagram tokens always expire in an hour, but this is implicit not explicit
67
+
68
+			$expires_in = 60 * 60;
69
+
70
+			$expires_at = time() + $expires_in;
71
+
72
+			$this->storeData('expires_in', $expires_in);
73
+			$this->storeData('expires_at', $expires_at);
74
+		}
75
+
76
+		return $collection;
77
+	}
78
+
79
+	/**
80
+	 * {@inheritdoc}
81
+	 */
82
+	public function maintainToken()
83
+	{
84
+		if (!$this->isConnected()) {
85
+			return;
86
+		}
87
+
88
+		// Handle token exchange prior to the standard handler for an API request
89
+		$exchange_by_expiry_days = $this->config->get('exchange_by_expiry_days') ?: 45;
90
+		if ($exchange_by_expiry_days !== null) {
91
+			$projected_timestamp = time() + 60 * 60 * 24 * $exchange_by_expiry_days;
92
+			if (!$this->hasAccessTokenExpired() && $this->hasAccessTokenExpired($projected_timestamp)) {
93
+				$this->exchangeAccessToken();
94
+			}
95
+		}
96
+	}
97
+
98
+	/**
99
+	 * Exchange the Access Token with one that expires further in the future.
100
+	 *
101
+	 * @return string Raw Provider API response
102
+	 * @throws \Hybridauth\Exception\HttpClientFailureException
103
+	 * @throws \Hybridauth\Exception\HttpRequestFailedException
104
+	 * @throws InvalidAccessTokenException
105
+	 */
106
+	public function exchangeAccessToken()
107
+	{
108
+		if ($this->getStoredData('expires_in') >= 5000000) {
109
+			/*
110 110
             Refresh a long-lived token (needed on Instagram, but not Facebook).
111 111
             It's not an oAuth style refresh using a refresh token.
112 112
             Actually it's really just another exchange, and invalidates the old token.
113 113
             Facebook/Instagram documentation is not very helpful at explaining that!
114 114
             */
115
-            $exchangeTokenParameters = [
116
-                'grant_type'        => 'ig_refresh_token',
117
-                'client_secret'     => $this->clientSecret,
118
-                'access_token'      => $this->getStoredData('access_token'),
119
-            ];
120
-            $url = 'https://graph.instagram.com/refresh_access_token';
121
-        } else {
122
-            // Exchange short-lived to long-lived
123
-            $exchangeTokenParameters = [
124
-                'grant_type'        => 'ig_exchange_token',
125
-                'client_secret'     => $this->clientSecret,
126
-                'access_token'      => $this->getStoredData('access_token'),
127
-            ];
128
-            $url = 'https://graph.instagram.com/access_token';
129
-        }
130
-
131
-        $response = $this->httpClient->request(
132
-            $url,
133
-            'GET',
134
-            $exchangeTokenParameters
135
-        );
136
-
137
-        $this->validateApiResponse('Unable to exchange the access token');
138
-
139
-        $this->validateAccessTokenExchange($response);
140
-
141
-        return $response;
142
-    }
143
-
144
-    /**
145
-     * {@inheritdoc}
146
-     */
147
-    public function getUserProfile()
148
-    {
149
-        $response = $this->apiRequest('me', 'GET', [
150
-            'fields' => 'id,username,account_type,media_count',
151
-        ]);
152
-
153
-        $data = new Collection($response);
154
-        if (!$data->exists('id')) {
155
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
156
-        }
157
-
158
-        $userProfile = new User\Profile();
159
-        $userProfile->identifier = $data->get('id');
160
-        $userProfile->displayName = $data->get('username');
161
-        $userProfile->profileURL = "https://instagram.com/{$userProfile->displayName}";
162
-        $userProfile->data = [
163
-            'account_type' => $data->get('account_type'),
164
-            'media_count' => $data->get('media_count'),
165
-        ];
166
-
167
-        return $userProfile;
168
-    }
169
-
170
-    /**
171
-     * Fetch user medias.
172
-     *
173
-     * @param int $limit Number of elements per page.
174
-     * @param string $pageId Current pager ID.
175
-     * @param array|null $fields Fields to fetch per media.
176
-     *
177
-     * @return \Hybridauth\Data\Collection
178
-     *
179
-     * @throws \Hybridauth\Exception\HttpClientFailureException
180
-     * @throws \Hybridauth\Exception\HttpRequestFailedException
181
-     * @throws \Hybridauth\Exception\InvalidAccessTokenException
182
-     * @throws \Hybridauth\Exception\UnexpectedApiResponseException
183
-     */
184
-    public function getUserMedia($limit = 12, $pageId = null, array $fields = null)
185
-    {
186
-        if (empty($fields)) {
187
-            $fields = [
188
-                'id',
189
-                'caption',
190
-                'media_type',
191
-                'media_url',
192
-                'thumbnail_url',
193
-                'permalink',
194
-                'timestamp',
195
-                'username',
196
-            ];
197
-        }
198
-
199
-        $params = [
200
-            'fields' => implode(',', $fields),
201
-            'limit' => $limit,
202
-        ];
203
-        if ($pageId !== null) {
204
-            $params['after'] = $pageId;
205
-        }
206
-
207
-        $response = $this->apiRequest('me/media', 'GET', $params);
208
-
209
-        $data = new Collection($response);
210
-        if (!$data->exists('data')) {
211
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
212
-        }
213
-
214
-        return $data;
215
-    }
216
-
217
-    /**
218
-     * Fetches a single user's media.
219
-     *
220
-     * @param string $mediaId Media ID.
221
-     * @param array|null $fields Fields to fetch per media.
222
-     *
223
-     * @return \Hybridauth\Data\Collection
224
-     *
225
-     * @throws \Hybridauth\Exception\HttpClientFailureException
226
-     * @throws \Hybridauth\Exception\HttpRequestFailedException
227
-     * @throws \Hybridauth\Exception\InvalidAccessTokenException
228
-     * @throws \Hybridauth\Exception\UnexpectedApiResponseException
229
-     */
230
-    public function getMedia($mediaId, array $fields = null)
231
-    {
232
-        if (empty($fields)) {
233
-            $fields = [
234
-                'id',
235
-                'caption',
236
-                'media_type',
237
-                'media_url',
238
-                'thumbnail_url',
239
-                'permalink',
240
-                'timestamp',
241
-                'username',
242
-            ];
243
-        }
244
-
245
-        $response = $this->apiRequest($mediaId, 'GET', [
246
-            'fields' => implode(',', $fields),
247
-        ]);
248
-
249
-        $data = new Collection($response);
250
-        if (!$data->exists('id')) {
251
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
252
-        }
253
-
254
-        return $data;
255
-    }
115
+			$exchangeTokenParameters = [
116
+				'grant_type'        => 'ig_refresh_token',
117
+				'client_secret'     => $this->clientSecret,
118
+				'access_token'      => $this->getStoredData('access_token'),
119
+			];
120
+			$url = 'https://graph.instagram.com/refresh_access_token';
121
+		} else {
122
+			// Exchange short-lived to long-lived
123
+			$exchangeTokenParameters = [
124
+				'grant_type'        => 'ig_exchange_token',
125
+				'client_secret'     => $this->clientSecret,
126
+				'access_token'      => $this->getStoredData('access_token'),
127
+			];
128
+			$url = 'https://graph.instagram.com/access_token';
129
+		}
130
+
131
+		$response = $this->httpClient->request(
132
+			$url,
133
+			'GET',
134
+			$exchangeTokenParameters
135
+		);
136
+
137
+		$this->validateApiResponse('Unable to exchange the access token');
138
+
139
+		$this->validateAccessTokenExchange($response);
140
+
141
+		return $response;
142
+	}
143
+
144
+	/**
145
+	 * {@inheritdoc}
146
+	 */
147
+	public function getUserProfile()
148
+	{
149
+		$response = $this->apiRequest('me', 'GET', [
150
+			'fields' => 'id,username,account_type,media_count',
151
+		]);
152
+
153
+		$data = new Collection($response);
154
+		if (!$data->exists('id')) {
155
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
156
+		}
157
+
158
+		$userProfile = new User\Profile();
159
+		$userProfile->identifier = $data->get('id');
160
+		$userProfile->displayName = $data->get('username');
161
+		$userProfile->profileURL = "https://instagram.com/{$userProfile->displayName}";
162
+		$userProfile->data = [
163
+			'account_type' => $data->get('account_type'),
164
+			'media_count' => $data->get('media_count'),
165
+		];
166
+
167
+		return $userProfile;
168
+	}
169
+
170
+	/**
171
+	 * Fetch user medias.
172
+	 *
173
+	 * @param int $limit Number of elements per page.
174
+	 * @param string $pageId Current pager ID.
175
+	 * @param array|null $fields Fields to fetch per media.
176
+	 *
177
+	 * @return \Hybridauth\Data\Collection
178
+	 *
179
+	 * @throws \Hybridauth\Exception\HttpClientFailureException
180
+	 * @throws \Hybridauth\Exception\HttpRequestFailedException
181
+	 * @throws \Hybridauth\Exception\InvalidAccessTokenException
182
+	 * @throws \Hybridauth\Exception\UnexpectedApiResponseException
183
+	 */
184
+	public function getUserMedia($limit = 12, $pageId = null, array $fields = null)
185
+	{
186
+		if (empty($fields)) {
187
+			$fields = [
188
+				'id',
189
+				'caption',
190
+				'media_type',
191
+				'media_url',
192
+				'thumbnail_url',
193
+				'permalink',
194
+				'timestamp',
195
+				'username',
196
+			];
197
+		}
198
+
199
+		$params = [
200
+			'fields' => implode(',', $fields),
201
+			'limit' => $limit,
202
+		];
203
+		if ($pageId !== null) {
204
+			$params['after'] = $pageId;
205
+		}
206
+
207
+		$response = $this->apiRequest('me/media', 'GET', $params);
208
+
209
+		$data = new Collection($response);
210
+		if (!$data->exists('data')) {
211
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
212
+		}
213
+
214
+		return $data;
215
+	}
216
+
217
+	/**
218
+	 * Fetches a single user's media.
219
+	 *
220
+	 * @param string $mediaId Media ID.
221
+	 * @param array|null $fields Fields to fetch per media.
222
+	 *
223
+	 * @return \Hybridauth\Data\Collection
224
+	 *
225
+	 * @throws \Hybridauth\Exception\HttpClientFailureException
226
+	 * @throws \Hybridauth\Exception\HttpRequestFailedException
227
+	 * @throws \Hybridauth\Exception\InvalidAccessTokenException
228
+	 * @throws \Hybridauth\Exception\UnexpectedApiResponseException
229
+	 */
230
+	public function getMedia($mediaId, array $fields = null)
231
+	{
232
+		if (empty($fields)) {
233
+			$fields = [
234
+				'id',
235
+				'caption',
236
+				'media_type',
237
+				'media_url',
238
+				'thumbnail_url',
239
+				'permalink',
240
+				'timestamp',
241
+				'username',
242
+			];
243
+		}
244
+
245
+		$response = $this->apiRequest($mediaId, 'GET', [
246
+			'fields' => implode(',', $fields),
247
+		]);
248
+
249
+		$data = new Collection($response);
250
+		if (!$data->exists('id')) {
251
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
252
+		}
253
+
254
+		return $data;
255
+	}
256 256
 }
Please login to merge, or discard this patch.
src/Adapter/AdapterInterface.php 1 patch
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -16,140 +16,140 @@
 block discarded – undo
16 16
  */
17 17
 interface AdapterInterface
18 18
 {
19
-    /**
20
-     * Initiate the appropriate protocol and process/automate the authentication or authorization flow.
21
-     *
22
-     * @return bool|null
23
-     */
24
-    public function authenticate();
25
-
26
-    /**
27
-     * Returns TRUE if the user is connected
28
-     *
29
-     * @return bool
30
-     */
31
-    public function isConnected();
32
-
33
-    /**
34
-     * Clear all access token in storage
35
-     */
36
-    public function disconnect();
37
-
38
-    /**
39
-     * Retrieve the connected user profile
40
-     *
41
-     * @return \Hybridauth\User\Profile
42
-     */
43
-    public function getUserProfile();
44
-
45
-    /**
46
-     * Retrieve the connected user contacts list
47
-     *
48
-     * @return \Hybridauth\User\Contact[]
49
-     */
50
-    public function getUserContacts();
51
-
52
-    /**
53
-     * Retrieve the connected user pages|companies|groups list
54
-     *
55
-     * @return array
56
-     */
57
-    public function getUserPages();
58
-
59
-    /**
60
-     * Retrieve the user activity stream
61
-     *
62
-     * @param string $stream
63
-     *
64
-     * @return \Hybridauth\User\Activity[]
65
-     */
66
-    public function getUserActivity($stream);
67
-
68
-    /**
69
-     * Post a status on user wall|timeline|blog|website|etc.
70
-     *
71
-     * @param string|array $status
72
-     *
73
-     * @return mixed API response
74
-     */
75
-    public function setUserStatus($status);
76
-
77
-    /**
78
-     * Post a status on page|company|group wall.
79
-     *
80
-     * @param string|array $status
81
-     * @param string $pageId
82
-     *
83
-     * @return mixed API response
84
-     */
85
-    public function setPageStatus($status, $pageId);
86
-
87
-    /**
88
-     * Send a signed request to provider API
89
-     *
90
-     * @param string $url
91
-     * @param string $method
92
-     * @param array $parameters
93
-     * @param array $headers
94
-     * @param bool $multipart
95
-     *
96
-     * @return mixed
97
-     */
98
-    public function apiRequest($url, $method = 'GET', $parameters = [], $headers = [], $multipart = false);
99
-
100
-    /**
101
-     * Do whatever may be necessary to make sure tokens do not expire.
102
-     * Intended to be be called frequently, e.g. via Cron.
103
-     */
104
-    public function maintainToken();
105
-
106
-    /**
107
-     * Return oauth access tokens.
108
-     *
109
-     * @return array
110
-     */
111
-    public function getAccessToken();
112
-
113
-    /**
114
-     * Set oauth access tokens.
115
-     *
116
-     * @param array $tokens
117
-     */
118
-    public function setAccessToken($tokens = []);
119
-
120
-    /**
121
-     * Set http client instance.
122
-     *
123
-     * @param HttpClientInterface $httpClient
124
-     */
125
-    public function setHttpClient(HttpClientInterface $httpClient = null);
126
-
127
-    /**
128
-     * Return http client instance.
129
-     */
130
-    public function getHttpClient();
131
-
132
-    /**
133
-     * Set storage instance.
134
-     *
135
-     * @param StorageInterface $storage
136
-     */
137
-    public function setStorage(StorageInterface $storage = null);
138
-
139
-    /**
140
-     * Return storage instance.
141
-     */
142
-    public function getStorage();
143
-
144
-    /**
145
-     * Set Logger instance.
146
-     *
147
-     * @param LoggerInterface $logger
148
-     */
149
-    public function setLogger(LoggerInterface $logger = null);
150
-
151
-    /**
152
-     * Return logger instance.
153
-     */
154
-    public function getLogger();
19
+	/**
20
+	 * Initiate the appropriate protocol and process/automate the authentication or authorization flow.
21
+	 *
22
+	 * @return bool|null
23
+	 */
24
+	public function authenticate();
25
+
26
+	/**
27
+	 * Returns TRUE if the user is connected
28
+	 *
29
+	 * @return bool
30
+	 */
31
+	public function isConnected();
32
+
33
+	/**
34
+	 * Clear all access token in storage
35
+	 */
36
+	public function disconnect();
37
+
38
+	/**
39
+	 * Retrieve the connected user profile
40
+	 *
41
+	 * @return \Hybridauth\User\Profile
42
+	 */
43
+	public function getUserProfile();
44
+
45
+	/**
46
+	 * Retrieve the connected user contacts list
47
+	 *
48
+	 * @return \Hybridauth\User\Contact[]
49
+	 */
50
+	public function getUserContacts();
51
+
52
+	/**
53
+	 * Retrieve the connected user pages|companies|groups list
54
+	 *
55
+	 * @return array
56
+	 */
57
+	public function getUserPages();
58
+
59
+	/**
60
+	 * Retrieve the user activity stream
61
+	 *
62
+	 * @param string $stream
63
+	 *
64
+	 * @return \Hybridauth\User\Activity[]
65
+	 */
66
+	public function getUserActivity($stream);
67
+
68
+	/**
69
+	 * Post a status on user wall|timeline|blog|website|etc.
70
+	 *
71
+	 * @param string|array $status
72
+	 *
73
+	 * @return mixed API response
74
+	 */
75
+	public function setUserStatus($status);
76
+
77
+	/**
78
+	 * Post a status on page|company|group wall.
79
+	 *
80
+	 * @param string|array $status
81
+	 * @param string $pageId
82
+	 *
83
+	 * @return mixed API response
84
+	 */
85
+	public function setPageStatus($status, $pageId);
86
+
87
+	/**
88
+	 * Send a signed request to provider API
89
+	 *
90
+	 * @param string $url
91
+	 * @param string $method
92
+	 * @param array $parameters
93
+	 * @param array $headers
94
+	 * @param bool $multipart
95
+	 *
96
+	 * @return mixed
97
+	 */
98
+	public function apiRequest($url, $method = 'GET', $parameters = [], $headers = [], $multipart = false);
99
+
100
+	/**
101
+	 * Do whatever may be necessary to make sure tokens do not expire.
102
+	 * Intended to be be called frequently, e.g. via Cron.
103
+	 */
104
+	public function maintainToken();
105
+
106
+	/**
107
+	 * Return oauth access tokens.
108
+	 *
109
+	 * @return array
110
+	 */
111
+	public function getAccessToken();
112
+
113
+	/**
114
+	 * Set oauth access tokens.
115
+	 *
116
+	 * @param array $tokens
117
+	 */
118
+	public function setAccessToken($tokens = []);
119
+
120
+	/**
121
+	 * Set http client instance.
122
+	 *
123
+	 * @param HttpClientInterface $httpClient
124
+	 */
125
+	public function setHttpClient(HttpClientInterface $httpClient = null);
126
+
127
+	/**
128
+	 * Return http client instance.
129
+	 */
130
+	public function getHttpClient();
131
+
132
+	/**
133
+	 * Set storage instance.
134
+	 *
135
+	 * @param StorageInterface $storage
136
+	 */
137
+	public function setStorage(StorageInterface $storage = null);
138
+
139
+	/**
140
+	 * Return storage instance.
141
+	 */
142
+	public function getStorage();
143
+
144
+	/**
145
+	 * Set Logger instance.
146
+	 *
147
+	 * @param LoggerInterface $logger
148
+	 */
149
+	public function setLogger(LoggerInterface $logger = null);
150
+
151
+	/**
152
+	 * Return logger instance.
153
+	 */
154
+	public function getLogger();
155 155
 }
Please login to merge, or discard this patch.
src/Provider/MicrosoftGraph.php 2 patches
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -43,127 +43,127 @@
 block discarded – undo
43 43
  */
44 44
 class MicrosoftGraph extends OAuth2
45 45
 {
46
-    /**
47
-     * {@inheritdoc}
48
-     */
49
-    protected $scope = 'openid user.read contacts.read';
50
-
51
-    /**
52
-     * {@inheritdoc}
53
-     */
54
-    protected $apiBaseUrl = 'https://graph.microsoft.com/v1.0/';
55
-
56
-    /**
57
-     * {@inheritdoc}
58
-     */
59
-    protected $authorizeUrl = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize';
60
-
61
-    /**
62
-     * {@inheritdoc}
63
-     */
64
-    protected $accessTokenUrl = 'https://login.microsoftonline.com/common/oauth2/v2.0/token';
65
-
66
-    /**
67
-     * {@inheritdoc}
68
-     */
69
-    protected $apiDocumentation = 'https://developer.microsoft.com/en-us/graph/docs/concepts/php';
70
-
71
-    /**
72
-     * {@inheritdoc}
73
-     */
74
-    protected function initialize()
75
-    {
76
-        parent::initialize();
77
-
78
-        $tenant = $this->config->get('tenant');
79
-        if (!empty($tenant)) {
80
-            $adjustedEndpoints = [
81
-                'authorize_url' => str_replace('/common/', '/' . $tenant . '/', $this->authorizeUrl),
82
-                'access_token_url' => str_replace('/common/', '/' . $tenant . '/', $this->accessTokenUrl),
83
-            ];
84
-
85
-            $this->setApiEndpoints($adjustedEndpoints);
86
-        }
87
-    }
88
-
89
-    /**
90
-     * {@inheritdoc}
91
-     */
92
-    public function getUserProfile()
93
-    {
94
-        $response = $this->apiRequest('me');
95
-
96
-        $data = new Data\Collection($response);
97
-
98
-        if (!$data->exists('id')) {
99
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
100
-        }
101
-
102
-        $userProfile = new User\Profile();
103
-
104
-        $userProfile->identifier = $data->get('id');
105
-        $userProfile->displayName = $data->get('displayName');
106
-        $userProfile->firstName = $data->get('givenName');
107
-        $userProfile->lastName = $data->get('surname');
108
-        $userProfile->language = $data->get('preferredLanguage');
109
-
110
-        $userProfile->phone = $data->get('mobilePhone');
111
-        if (empty($userProfile->phone)) {
112
-            $businessPhones = $data->get('businessPhones');
113
-            if (isset($businessPhones[0])) {
114
-                $userProfile->phone = $businessPhones[0];
115
-            }
116
-        }
117
-
118
-        $userProfile->email = $data->get('mail');
119
-        if (empty($userProfile->email)) {
120
-            $email = $data->get('userPrincipalName');
121
-            if (strpos($email, '@') !== false) {
122
-                $userProfile->email = $email;
123
-            }
124
-        }
125
-
126
-        return $userProfile;
127
-    }
128
-
129
-    /**
130
-     * {@inheritdoc}
131
-     */
132
-    public function getUserContacts()
133
-    {
134
-        $apiUrl = 'me/contacts?$top=50';
135
-        $contacts = [];
136
-
137
-        do {
138
-            $response = $this->apiRequest($apiUrl);
139
-            $data = new Data\Collection($response);
140
-            if (!$data->exists('value')) {
141
-                throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
142
-            }
143
-            foreach ($data->filter('value')->toArray() as $entry) {
144
-                $entry = new Data\Collection($entry);
145
-                $userContact = new User\Contact();
146
-                $userContact->identifier = $entry->get('id');
147
-                $userContact->displayName = $entry->get('displayName');
148
-                $emailAddresses = $entry->get('emailAddresses');
149
-                if (!empty($emailAddresses)) {
150
-                    $userContact->email = $emailAddresses[0]->address;
151
-                }
152
-                // only add to collection if we have usefull data
153
-                if (!empty($userContact->displayName) || !empty($userContact->email)) {
154
-                    $contacts[] = $userContact;
155
-                }
156
-            }
157
-
158
-            if ($data->exists('@odata.nextLink')) {
159
-                $apiUrl = $data->get('@odata.nextLink');
160
-
161
-                $pagedList = true;
162
-            } else {
163
-                $pagedList = false;
164
-            }
165
-        } while ($pagedList);
166
-
167
-        return $contacts;
168
-    }
46
+	/**
47
+	 * {@inheritdoc}
48
+	 */
49
+	protected $scope = 'openid user.read contacts.read';
50
+
51
+	/**
52
+	 * {@inheritdoc}
53
+	 */
54
+	protected $apiBaseUrl = 'https://graph.microsoft.com/v1.0/';
55
+
56
+	/**
57
+	 * {@inheritdoc}
58
+	 */
59
+	protected $authorizeUrl = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize';
60
+
61
+	/**
62
+	 * {@inheritdoc}
63
+	 */
64
+	protected $accessTokenUrl = 'https://login.microsoftonline.com/common/oauth2/v2.0/token';
65
+
66
+	/**
67
+	 * {@inheritdoc}
68
+	 */
69
+	protected $apiDocumentation = 'https://developer.microsoft.com/en-us/graph/docs/concepts/php';
70
+
71
+	/**
72
+	 * {@inheritdoc}
73
+	 */
74
+	protected function initialize()
75
+	{
76
+		parent::initialize();
77
+
78
+		$tenant = $this->config->get('tenant');
79
+		if (!empty($tenant)) {
80
+			$adjustedEndpoints = [
81
+				'authorize_url' => str_replace('/common/', '/' . $tenant . '/', $this->authorizeUrl),
82
+				'access_token_url' => str_replace('/common/', '/' . $tenant . '/', $this->accessTokenUrl),
83
+			];
84
+
85
+			$this->setApiEndpoints($adjustedEndpoints);
86
+		}
87
+	}
88
+
89
+	/**
90
+	 * {@inheritdoc}
91
+	 */
92
+	public function getUserProfile()
93
+	{
94
+		$response = $this->apiRequest('me');
95
+
96
+		$data = new Data\Collection($response);
97
+
98
+		if (!$data->exists('id')) {
99
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
100
+		}
101
+
102
+		$userProfile = new User\Profile();
103
+
104
+		$userProfile->identifier = $data->get('id');
105
+		$userProfile->displayName = $data->get('displayName');
106
+		$userProfile->firstName = $data->get('givenName');
107
+		$userProfile->lastName = $data->get('surname');
108
+		$userProfile->language = $data->get('preferredLanguage');
109
+
110
+		$userProfile->phone = $data->get('mobilePhone');
111
+		if (empty($userProfile->phone)) {
112
+			$businessPhones = $data->get('businessPhones');
113
+			if (isset($businessPhones[0])) {
114
+				$userProfile->phone = $businessPhones[0];
115
+			}
116
+		}
117
+
118
+		$userProfile->email = $data->get('mail');
119
+		if (empty($userProfile->email)) {
120
+			$email = $data->get('userPrincipalName');
121
+			if (strpos($email, '@') !== false) {
122
+				$userProfile->email = $email;
123
+			}
124
+		}
125
+
126
+		return $userProfile;
127
+	}
128
+
129
+	/**
130
+	 * {@inheritdoc}
131
+	 */
132
+	public function getUserContacts()
133
+	{
134
+		$apiUrl = 'me/contacts?$top=50';
135
+		$contacts = [];
136
+
137
+		do {
138
+			$response = $this->apiRequest($apiUrl);
139
+			$data = new Data\Collection($response);
140
+			if (!$data->exists('value')) {
141
+				throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
142
+			}
143
+			foreach ($data->filter('value')->toArray() as $entry) {
144
+				$entry = new Data\Collection($entry);
145
+				$userContact = new User\Contact();
146
+				$userContact->identifier = $entry->get('id');
147
+				$userContact->displayName = $entry->get('displayName');
148
+				$emailAddresses = $entry->get('emailAddresses');
149
+				if (!empty($emailAddresses)) {
150
+					$userContact->email = $emailAddresses[0]->address;
151
+				}
152
+				// only add to collection if we have usefull data
153
+				if (!empty($userContact->displayName) || !empty($userContact->email)) {
154
+					$contacts[] = $userContact;
155
+				}
156
+			}
157
+
158
+			if ($data->exists('@odata.nextLink')) {
159
+				$apiUrl = $data->get('@odata.nextLink');
160
+
161
+				$pagedList = true;
162
+			} else {
163
+				$pagedList = false;
164
+			}
165
+		} while ($pagedList);
166
+
167
+		return $contacts;
168
+	}
169 169
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -76,10 +76,10 @@  discard block
 block discarded – undo
76 76
         parent::initialize();
77 77
 
78 78
         $tenant = $this->config->get('tenant');
79
-        if (!empty($tenant)) {
79
+        if ( ! empty($tenant)) {
80 80
             $adjustedEndpoints = [
81
-                'authorize_url' => str_replace('/common/', '/' . $tenant . '/', $this->authorizeUrl),
82
-                'access_token_url' => str_replace('/common/', '/' . $tenant . '/', $this->accessTokenUrl),
81
+                'authorize_url' => str_replace('/common/', '/'.$tenant.'/', $this->authorizeUrl),
82
+                'access_token_url' => str_replace('/common/', '/'.$tenant.'/', $this->accessTokenUrl),
83 83
             ];
84 84
 
85 85
             $this->setApiEndpoints($adjustedEndpoints);
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 
96 96
         $data = new Data\Collection($response);
97 97
 
98
-        if (!$data->exists('id')) {
98
+        if ( ! $data->exists('id')) {
99 99
             throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
100 100
         }
101 101
 
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
         do {
138 138
             $response = $this->apiRequest($apiUrl);
139 139
             $data = new Data\Collection($response);
140
-            if (!$data->exists('value')) {
140
+            if ( ! $data->exists('value')) {
141 141
                 throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
142 142
             }
143 143
             foreach ($data->filter('value')->toArray() as $entry) {
@@ -146,11 +146,11 @@  discard block
 block discarded – undo
146 146
                 $userContact->identifier = $entry->get('id');
147 147
                 $userContact->displayName = $entry->get('displayName');
148 148
                 $emailAddresses = $entry->get('emailAddresses');
149
-                if (!empty($emailAddresses)) {
149
+                if ( ! empty($emailAddresses)) {
150 150
                     $userContact->email = $emailAddresses[0]->address;
151 151
                 }
152 152
                 // only add to collection if we have usefull data
153
-                if (!empty($userContact->displayName) || !empty($userContact->email)) {
153
+                if ( ! empty($userContact->displayName) || ! empty($userContact->email)) {
154 154
                     $contacts[] = $userContact;
155 155
                 }
156 156
             }
Please login to merge, or discard this patch.
src/Provider/WeChat.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 
116 116
         $data = new Data\Collection($response);
117 117
 
118
-        if (!$data->exists('openid')) {
118
+        if ( ! $data->exists('openid')) {
119 119
             throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
120 120
         }
121 121
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
         $userProfile->region = $data->get('province');
129 129
         $userProfile->country = $data->get('country');
130 130
         $genders = ['', 'male', 'female'];
131
-        $userProfile->gender = $genders[(int)$data->get('sex')];
131
+        $userProfile->gender = $genders[(int) $data->get('sex')];
132 132
 
133 133
         return $userProfile;
134 134
     }
Please login to merge, or discard this patch.
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -17,121 +17,121 @@
 block discarded – undo
17 17
  */
18 18
 class WeChat extends OAuth2
19 19
 {
20
-    /**
21
-     * {@inheritdoc}
22
-     */
23
-    protected $scope = 'snsapi_login,snsapi_userinfo,scope.userInfo';
24
-
25
-    /**
26
-     * {@inheritdoc}
27
-     */
28
-    protected $apiBaseUrl = 'https://api.wechat.com/sns/';
29
-
30
-    /**
31
-     * {@inheritdoc}
32
-     */
33
-    protected $authorizeUrl = 'https://open.weixin.qq.com/connect/qrconnect';
34
-
35
-    /**
36
-     * {@inheritdoc}
37
-     */
38
-    protected $accessTokenUrl = 'https://api.wechat.com/sns/oauth2/access_token';
39
-
40
-    /**
41
-     * Refresh Token Endpoint
42
-     * @var string
43
-     */
44
-    protected $tokenRefreshUrl = 'https://api.wechat.com/sns/oauth2/refresh_token';
45
-
46
-    /**
47
-     * {@ịnheritdoc}
48
-     */
49
-    protected $accessTokenInfoUrl = 'https://api.wechat.com/sns/auth';
50
-
51
-    /**
52
-     * {@inheritdoc}
53
-     */
54
-    protected $tokenExchangeMethod = 'GET';
55
-
56
-    /**
57
-     * {@inheritdoc}
58
-     */
59
-    protected $tokenRefreshMethod = 'GET';
60
-
61
-    /**
62
-     * {@inheritdoc}
63
-     */
64
-    protected $apiDocumentation = ''; // Not available
65
-
66
-    /**
67
-     * {@inheritdoc}
68
-     */
69
-    protected function initialize()
70
-    {
71
-        parent::initialize();
72
-
73
-        $this->AuthorizeUrlParameters += [
74
-            'appid' => $this->clientId
75
-        ];
76
-        unset($this->AuthorizeUrlParameters['client_id']);
77
-
78
-        $this->tokenExchangeParameters += [
79
-            'appid' => $this->clientId,
80
-            'secret' => $this->clientSecret
81
-        ];
82
-        unset($this->tokenExchangeParameters['client_id']);
83
-        unset($this->tokenExchangeParameters['client_secret']);
84
-
85
-        if ($this->isRefreshTokenAvailable()) {
86
-            $this->tokenRefreshParameters += [
87
-                'appid' => $this->clientId,
88
-            ];
89
-        }
90
-
91
-        $this->apiRequestParameters = [
92
-            'appid' => $this->clientId,
93
-            'secret' => $this->clientSecret
94
-        ];
95
-    }
96
-
97
-    /**
98
-     * {@inheritdoc}
99
-     */
100
-    protected function validateAccessTokenExchange($response)
101
-    {
102
-        $collection = parent::validateAccessTokenExchange($response);
103
-
104
-        $this->storeData('openid', $collection->get('openid'));
105
-        $this->storeData('access_token', $collection->get('access_token'));
106
-    }
107
-
108
-    /**
109
-     * {@inheritdoc}
110
-     */
111
-    public function getUserProfile()
112
-    {
113
-        $openid = $this->getStoredData('openid');
114
-        $access_token = $this->getStoredData('access_token');
115
-
116
-        $response = $this->apiRequest('userinfo', 'GET', ['openid' => $openid, 'access_token' => $access_token]);
117
-
118
-        $data = new Data\Collection($response);
119
-
120
-        if (!$data->exists('openid')) {
121
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
122
-        }
123
-
124
-        $userProfile = new User\Profile();
125
-
126
-        $userProfile->identifier = $data->get('openid');
127
-        $userProfile->displayName = $data->get('nickname');
128
-        $userProfile->photoURL = $data->get('headimgurl');
129
-        $userProfile->city = $data->get('city');
130
-        $userProfile->region = $data->get('province');
131
-        $userProfile->country = $data->get('country');
132
-        $genders = ['', 'male', 'female'];
133
-        $userProfile->gender = $genders[(int)$data->get('sex')];
134
-
135
-        return $userProfile;
136
-    }
20
+	/**
21
+	 * {@inheritdoc}
22
+	 */
23
+	protected $scope = 'snsapi_login,snsapi_userinfo,scope.userInfo';
24
+
25
+	/**
26
+	 * {@inheritdoc}
27
+	 */
28
+	protected $apiBaseUrl = 'https://api.wechat.com/sns/';
29
+
30
+	/**
31
+	 * {@inheritdoc}
32
+	 */
33
+	protected $authorizeUrl = 'https://open.weixin.qq.com/connect/qrconnect';
34
+
35
+	/**
36
+	 * {@inheritdoc}
37
+	 */
38
+	protected $accessTokenUrl = 'https://api.wechat.com/sns/oauth2/access_token';
39
+
40
+	/**
41
+	 * Refresh Token Endpoint
42
+	 * @var string
43
+	 */
44
+	protected $tokenRefreshUrl = 'https://api.wechat.com/sns/oauth2/refresh_token';
45
+
46
+	/**
47
+	 * {@ịnheritdoc}
48
+	 */
49
+	protected $accessTokenInfoUrl = 'https://api.wechat.com/sns/auth';
50
+
51
+	/**
52
+	 * {@inheritdoc}
53
+	 */
54
+	protected $tokenExchangeMethod = 'GET';
55
+
56
+	/**
57
+	 * {@inheritdoc}
58
+	 */
59
+	protected $tokenRefreshMethod = 'GET';
60
+
61
+	/**
62
+	 * {@inheritdoc}
63
+	 */
64
+	protected $apiDocumentation = ''; // Not available
65
+
66
+	/**
67
+	 * {@inheritdoc}
68
+	 */
69
+	protected function initialize()
70
+	{
71
+		parent::initialize();
72
+
73
+		$this->AuthorizeUrlParameters += [
74
+			'appid' => $this->clientId
75
+		];
76
+		unset($this->AuthorizeUrlParameters['client_id']);
77
+
78
+		$this->tokenExchangeParameters += [
79
+			'appid' => $this->clientId,
80
+			'secret' => $this->clientSecret
81
+		];
82
+		unset($this->tokenExchangeParameters['client_id']);
83
+		unset($this->tokenExchangeParameters['client_secret']);
84
+
85
+		if ($this->isRefreshTokenAvailable()) {
86
+			$this->tokenRefreshParameters += [
87
+				'appid' => $this->clientId,
88
+			];
89
+		}
90
+
91
+		$this->apiRequestParameters = [
92
+			'appid' => $this->clientId,
93
+			'secret' => $this->clientSecret
94
+		];
95
+	}
96
+
97
+	/**
98
+	 * {@inheritdoc}
99
+	 */
100
+	protected function validateAccessTokenExchange($response)
101
+	{
102
+		$collection = parent::validateAccessTokenExchange($response);
103
+
104
+		$this->storeData('openid', $collection->get('openid'));
105
+		$this->storeData('access_token', $collection->get('access_token'));
106
+	}
107
+
108
+	/**
109
+	 * {@inheritdoc}
110
+	 */
111
+	public function getUserProfile()
112
+	{
113
+		$openid = $this->getStoredData('openid');
114
+		$access_token = $this->getStoredData('access_token');
115
+
116
+		$response = $this->apiRequest('userinfo', 'GET', ['openid' => $openid, 'access_token' => $access_token]);
117
+
118
+		$data = new Data\Collection($response);
119
+
120
+		if (!$data->exists('openid')) {
121
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
122
+		}
123
+
124
+		$userProfile = new User\Profile();
125
+
126
+		$userProfile->identifier = $data->get('openid');
127
+		$userProfile->displayName = $data->get('nickname');
128
+		$userProfile->photoURL = $data->get('headimgurl');
129
+		$userProfile->city = $data->get('city');
130
+		$userProfile->region = $data->get('province');
131
+		$userProfile->country = $data->get('country');
132
+		$genders = ['', 'male', 'female'];
133
+		$userProfile->gender = $genders[(int)$data->get('sex')];
134
+
135
+		return $userProfile;
136
+	}
137 137
 }
Please login to merge, or discard this patch.
src/Provider/Telegram.php 2 patches
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -44,143 +44,143 @@  discard block
 block discarded – undo
44 44
  */
45 45
 class Telegram extends AbstractAdapter implements AdapterInterface
46 46
 {
47
-    protected $botId = '';
48
-
49
-    protected $botSecret = '';
50
-
51
-    protected $callbackUrl = '';
52
-
53
-    /**
54
-     * IPD API Documentation
55
-     *
56
-     * OPTIONAL.
57
-     *
58
-     * @var string
59
-     */
60
-    protected $apiDocumentation = 'https://core.telegram.org/bots';
61
-
62
-    /**
63
-     * {@inheritdoc}
64
-     */
65
-    protected function configure()
66
-    {
67
-        $this->botId = $this->config->filter('keys')->get('id');
68
-        $this->botSecret = $this->config->filter('keys')->get('secret');
69
-        $this->callbackUrl = $this->config->get('callback');
70
-
71
-        if (!$this->botId || !$this->botSecret) {
72
-            throw new InvalidApplicationCredentialsException(
73
-                'Your application id is required in order to connect to ' . $this->providerId
74
-            );
75
-        }
76
-    }
77
-
78
-    /**
79
-     * {@inheritdoc}
80
-     */
81
-    protected function initialize()
82
-    {
83
-    }
84
-
85
-    /**
86
-     * {@inheritdoc}
87
-     */
88
-    public function authenticate()
89
-    {
90
-        $this->logger->info(sprintf('%s::authenticate()', get_class($this)));
91
-        if (!filter_input(INPUT_GET, 'hash')) {
92
-            $this->authenticateBegin();
93
-        } else {
94
-            $this->authenticateCheckError();
95
-            $this->authenticateFinish();
96
-        }
97
-        return null;
98
-    }
99
-
100
-    /**
101
-     * {@inheritdoc}
102
-     */
103
-    public function isConnected()
104
-    {
105
-        $authData = $this->getStoredData('auth_data');
106
-        return !empty($authData);
107
-    }
108
-
109
-    /**
110
-     * {@inheritdoc}
111
-     */
112
-    public function getUserProfile()
113
-    {
114
-        $data = new Collection($this->getStoredData('auth_data'));
115
-
116
-        if (!$data->exists('id')) {
117
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
118
-        }
119
-
120
-        $userProfile = new Profile();
121
-
122
-        $userProfile->identifier = $data->get('id');
123
-        $userProfile->firstName = $data->get('first_name');
124
-        $userProfile->lastName = $data->get('last_name');
125
-        $userProfile->displayName = $data->get('username');
126
-        $userProfile->photoURL = $data->get('photo_url');
127
-        $username = $data->get('username');
128
-        if (!empty($username)) {
129
-            // Only some accounts have usernames.
130
-            $userProfile->profileURL = "https://t.me/{$username}";
131
-        }
132
-
133
-        return $userProfile;
134
-    }
135
-
136
-    /**
137
-     * See: https://telegram.im/widget-login.php
138
-     * See: https://gist.github.com/anonymous/6516521b1fb3b464534fbc30ea3573c2
139
-     */
140
-    protected function authenticateCheckError()
141
-    {
142
-        $auth_data = $this->parseAuthData();
143
-
144
-        $check_hash = $auth_data['hash'];
145
-        unset($auth_data['hash']);
146
-        $data_check_arr = [];
147
-
148
-        foreach ($auth_data as $key => $value) {
149
-            if (!empty($value)) {
150
-                $data_check_arr[] = $key . '=' . $value;
151
-            }
152
-        }
153
-        sort($data_check_arr);
154
-
155
-        $data_check_string = implode("\n", $data_check_arr);
156
-        $secret_key = hash('sha256', $this->botSecret, true);
157
-        $hash = hash_hmac('sha256', $data_check_string, $secret_key);
158
-
159
-        if (strcmp($hash, $check_hash) !== 0) {
160
-            throw new InvalidAuthorizationCodeException(
161
-                sprintf('Provider returned an error: %s', 'Data is NOT from Telegram')
162
-            );
163
-        }
164
-
165
-        if ((time() - $auth_data['auth_date']) > 86400) {
166
-            throw new InvalidAuthorizationCodeException(
167
-                sprintf('Provider returned an error: %s', 'Data is outdated')
168
-            );
169
-        }
170
-    }
171
-
172
-    /**
173
-     * See: https://telegram.im/widget-login.php
174
-     */
175
-    protected function authenticateBegin()
176
-    {
177
-        $this->logger->debug(sprintf('%s::authenticateBegin(), redirecting user to:', get_class($this)));
178
-
179
-        $nonce = $this->config->get('nonce');
180
-        $nonce_code = empty($nonce) ? '' : "nonce=\"{$nonce}\"";
181
-
182
-        exit(
183
-            <<<HTML
47
+	protected $botId = '';
48
+
49
+	protected $botSecret = '';
50
+
51
+	protected $callbackUrl = '';
52
+
53
+	/**
54
+	 * IPD API Documentation
55
+	 *
56
+	 * OPTIONAL.
57
+	 *
58
+	 * @var string
59
+	 */
60
+	protected $apiDocumentation = 'https://core.telegram.org/bots';
61
+
62
+	/**
63
+	 * {@inheritdoc}
64
+	 */
65
+	protected function configure()
66
+	{
67
+		$this->botId = $this->config->filter('keys')->get('id');
68
+		$this->botSecret = $this->config->filter('keys')->get('secret');
69
+		$this->callbackUrl = $this->config->get('callback');
70
+
71
+		if (!$this->botId || !$this->botSecret) {
72
+			throw new InvalidApplicationCredentialsException(
73
+				'Your application id is required in order to connect to ' . $this->providerId
74
+			);
75
+		}
76
+	}
77
+
78
+	/**
79
+	 * {@inheritdoc}
80
+	 */
81
+	protected function initialize()
82
+	{
83
+	}
84
+
85
+	/**
86
+	 * {@inheritdoc}
87
+	 */
88
+	public function authenticate()
89
+	{
90
+		$this->logger->info(sprintf('%s::authenticate()', get_class($this)));
91
+		if (!filter_input(INPUT_GET, 'hash')) {
92
+			$this->authenticateBegin();
93
+		} else {
94
+			$this->authenticateCheckError();
95
+			$this->authenticateFinish();
96
+		}
97
+		return null;
98
+	}
99
+
100
+	/**
101
+	 * {@inheritdoc}
102
+	 */
103
+	public function isConnected()
104
+	{
105
+		$authData = $this->getStoredData('auth_data');
106
+		return !empty($authData);
107
+	}
108
+
109
+	/**
110
+	 * {@inheritdoc}
111
+	 */
112
+	public function getUserProfile()
113
+	{
114
+		$data = new Collection($this->getStoredData('auth_data'));
115
+
116
+		if (!$data->exists('id')) {
117
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
118
+		}
119
+
120
+		$userProfile = new Profile();
121
+
122
+		$userProfile->identifier = $data->get('id');
123
+		$userProfile->firstName = $data->get('first_name');
124
+		$userProfile->lastName = $data->get('last_name');
125
+		$userProfile->displayName = $data->get('username');
126
+		$userProfile->photoURL = $data->get('photo_url');
127
+		$username = $data->get('username');
128
+		if (!empty($username)) {
129
+			// Only some accounts have usernames.
130
+			$userProfile->profileURL = "https://t.me/{$username}";
131
+		}
132
+
133
+		return $userProfile;
134
+	}
135
+
136
+	/**
137
+	 * See: https://telegram.im/widget-login.php
138
+	 * See: https://gist.github.com/anonymous/6516521b1fb3b464534fbc30ea3573c2
139
+	 */
140
+	protected function authenticateCheckError()
141
+	{
142
+		$auth_data = $this->parseAuthData();
143
+
144
+		$check_hash = $auth_data['hash'];
145
+		unset($auth_data['hash']);
146
+		$data_check_arr = [];
147
+
148
+		foreach ($auth_data as $key => $value) {
149
+			if (!empty($value)) {
150
+				$data_check_arr[] = $key . '=' . $value;
151
+			}
152
+		}
153
+		sort($data_check_arr);
154
+
155
+		$data_check_string = implode("\n", $data_check_arr);
156
+		$secret_key = hash('sha256', $this->botSecret, true);
157
+		$hash = hash_hmac('sha256', $data_check_string, $secret_key);
158
+
159
+		if (strcmp($hash, $check_hash) !== 0) {
160
+			throw new InvalidAuthorizationCodeException(
161
+				sprintf('Provider returned an error: %s', 'Data is NOT from Telegram')
162
+			);
163
+		}
164
+
165
+		if ((time() - $auth_data['auth_date']) > 86400) {
166
+			throw new InvalidAuthorizationCodeException(
167
+				sprintf('Provider returned an error: %s', 'Data is outdated')
168
+			);
169
+		}
170
+	}
171
+
172
+	/**
173
+	 * See: https://telegram.im/widget-login.php
174
+	 */
175
+	protected function authenticateBegin()
176
+	{
177
+		$this->logger->debug(sprintf('%s::authenticateBegin(), redirecting user to:', get_class($this)));
178
+
179
+		$nonce = $this->config->get('nonce');
180
+		$nonce_code = empty($nonce) ? '' : "nonce=\"{$nonce}\"";
181
+
182
+		exit(
183
+			<<<HTML
184 184
 <center>
185 185
     <script async src="https://telegram.org/js/telegram-widget.js?7"
186 186
             {$nonce_code}
@@ -191,31 +191,31 @@  discard block
 block discarded – undo
191 191
     </script>
192 192
 </center>
193 193
 HTML
194
-        );
195
-    }
196
-
197
-    protected function authenticateFinish()
198
-    {
199
-        $this->logger->debug(
200
-            sprintf('%s::authenticateFinish(), callback url:', get_class($this)),
201
-            [Util::getCurrentUrl(true)]
202
-        );
203
-
204
-        $this->storeData('auth_data', $this->parseAuthData());
205
-
206
-        $this->initialize();
207
-    }
208
-
209
-    protected function parseAuthData()
210
-    {
211
-        return [
212
-            'id' => filter_input(INPUT_GET, 'id'),
213
-            'first_name' => filter_input(INPUT_GET, 'first_name'),
214
-            'last_name' => filter_input(INPUT_GET, 'last_name'),
215
-            'username' => filter_input(INPUT_GET, 'username'),
216
-            'photo_url' => filter_input(INPUT_GET, 'photo_url'),
217
-            'auth_date' => filter_input(INPUT_GET, 'auth_date'),
218
-            'hash' => filter_input(INPUT_GET, 'hash'),
219
-        ];
220
-    }
194
+		);
195
+	}
196
+
197
+	protected function authenticateFinish()
198
+	{
199
+		$this->logger->debug(
200
+			sprintf('%s::authenticateFinish(), callback url:', get_class($this)),
201
+			[Util::getCurrentUrl(true)]
202
+		);
203
+
204
+		$this->storeData('auth_data', $this->parseAuthData());
205
+
206
+		$this->initialize();
207
+	}
208
+
209
+	protected function parseAuthData()
210
+	{
211
+		return [
212
+			'id' => filter_input(INPUT_GET, 'id'),
213
+			'first_name' => filter_input(INPUT_GET, 'first_name'),
214
+			'last_name' => filter_input(INPUT_GET, 'last_name'),
215
+			'username' => filter_input(INPUT_GET, 'username'),
216
+			'photo_url' => filter_input(INPUT_GET, 'photo_url'),
217
+			'auth_date' => filter_input(INPUT_GET, 'auth_date'),
218
+			'hash' => filter_input(INPUT_GET, 'hash'),
219
+		];
220
+	}
221 221
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
         $this->botSecret = $this->config->filter('keys')->get('secret');
69 69
         $this->callbackUrl = $this->config->get('callback');
70 70
 
71
-        if (!$this->botId || !$this->botSecret) {
71
+        if ( ! $this->botId || ! $this->botSecret) {
72 72
             throw new InvalidApplicationCredentialsException(
73
-                'Your application id is required in order to connect to ' . $this->providerId
73
+                'Your application id is required in order to connect to '.$this->providerId
74 74
             );
75 75
         }
76 76
     }
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
     public function authenticate()
89 89
     {
90 90
         $this->logger->info(sprintf('%s::authenticate()', get_class($this)));
91
-        if (!filter_input(INPUT_GET, 'hash')) {
91
+        if ( ! filter_input(INPUT_GET, 'hash')) {
92 92
             $this->authenticateBegin();
93 93
         } else {
94 94
             $this->authenticateCheckError();
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
     public function isConnected()
104 104
     {
105 105
         $authData = $this->getStoredData('auth_data');
106
-        return !empty($authData);
106
+        return ! empty($authData);
107 107
     }
108 108
 
109 109
     /**
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
     {
114 114
         $data = new Collection($this->getStoredData('auth_data'));
115 115
 
116
-        if (!$data->exists('id')) {
116
+        if ( ! $data->exists('id')) {
117 117
             throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
118 118
         }
119 119
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
         $userProfile->displayName = $data->get('username');
126 126
         $userProfile->photoURL = $data->get('photo_url');
127 127
         $username = $data->get('username');
128
-        if (!empty($username)) {
128
+        if ( ! empty($username)) {
129 129
             // Only some accounts have usernames.
130 130
             $userProfile->profileURL = "https://t.me/{$username}";
131 131
         }
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
         $data_check_arr = [];
147 147
 
148 148
         foreach ($auth_data as $key => $value) {
149
-            if (!empty($value)) {
150
-                $data_check_arr[] = $key . '=' . $value;
149
+            if ( ! empty($value)) {
150
+                $data_check_arr[] = $key.'='.$value;
151 151
             }
152 152
         }
153 153
         sort($data_check_arr);
Please login to merge, or discard this patch.