| Conditions | 1 |
| Paths | 1 |
| Total Lines | 26 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 2 |
| Changes | 0 | ||
| 1 | <?php |
||
| 28 | public static function getTokenFromAuthorizationCode( |
||
| 29 | $clientId, |
||
| 30 | $clientSecret, |
||
| 31 | $authorizationCode, |
||
| 32 | $redirectUri, |
||
| 33 | $tokenEndPoint = 'https://login.microsoftonline.com/common/oauth2/token' |
||
| 34 | ) { |
||
| 35 | $postOptions = array( |
||
| 36 | 'http_errors' => false, |
||
| 37 | 'form_params' => array( |
||
| 38 | 'client_id' => $clientId, |
||
| 39 | 'resource' => 'https://outlook.office365.com', |
||
| 40 | 'client_secret' => $clientSecret, |
||
| 41 | 'code' => $authorizationCode, |
||
| 42 | 'redirect_uri' => $redirectUri, |
||
| 43 | 'grant_type' => 'authorization_code' |
||
| 44 | ) |
||
| 45 | ); |
||
| 46 | |||
| 47 | $client = new Client(); |
||
| 48 | $response = $client->request('POST', $tokenEndPoint, $postOptions); |
||
| 49 | $response = $response->getBody()->__toString(); |
||
| 50 | |||
| 51 | $response = json_decode($response); |
||
| 52 | |||
| 53 | return $response->access_token; |
||
| 54 | } |
||
| 56 |