95 {
97 "authwindowslive oauth: Using this verification code [".
$state[
'authwindowslive:verification_code'].
"]"
98 );
99
100
101
102
103 $postData =
'client_id=' . urlencode($this->key)
104 . '&client_secret=' . urlencode($this->secret)
105 . '&scope=' . urlencode('https://graph.microsoft.com/user.read')
106 . '&grant_type=authorization_code'
107 .
'&redirect_uri=' . urlencode(
SimpleSAML\Module::getModuleUrl(
'authwindowslive') .
'/linkback.php')
108 .
'&code=' . urlencode(
$state[
'authwindowslive:verification_code']);
109
111 'http' => array(
112 'method' => 'POST',
113 'header' => 'Content-type: application/x-www-form-urlencoded',
115 ),
116 );
117
119
121
122
123 if (!array_key_exists(
'access_token',
$response)) {
124 throw new Exception(
126 "\r\nNo access_token returned - cannot proceed\r\n" . implode(
', ',
$response[
'error_codes'])
127 );
128 }
129
131 "authwindowslive: Got an access token from the OAuth service provider [".
$response[
'access_token'].
"]"
132 );
133
134
135 $opts = array('http' => array('header' => "Accept: application/json\r\nAuthorization: Bearer ".
138 $userdata = json_decode(
$data,
true);
139
140
141 if (!array_key_exists('@odata.context', $userdata) || array_key_exists('error', $userdata)) {
142 throw new Exception(
143 'Unable to retrieve userdata from Microsoft Graph ['.$userdata['error']['code'].'] '.
144 $userdata['error']['message']
145 );
146 }
149 'https://graph.microsoft.com!'.(!empty($userdata['id']) ? $userdata['id'] : 'unknown')
150 );
151 foreach ($userdata as
$key => $value) {
152 if (is_string($value)) {
154 }
155 }
156
157
159
161 }
static fetch($url, $context=array(), $getHeaders=false)
Helper function to retrieve a file or URL with proxy support, also supporting proxy basic authorizati...
if(array_key_exists('yes', $_REQUEST)) $attributes
if($session===NULL) $postData