Office365 standalone php app authorization

43
February 12, 2019, at 5:20 PM

I have a standalone PHP webapp that I am tasked with adding Office365 authorization to in order for only authorized users to access.

I have registered the application in the "Application Registration Portal" in our Office365 environment and received an Application ID. I set the Redirect URL to the application on my localhost: http://localhost/MyApp.

Within my initial page for the Webapp (login.php), I have the following redirect:

Location:https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id..... 

That piece works successfully as it will redirect the user to the Office365 login page, and after a user enters credentials, takes them to the index page (index.php).

In my index page, I have the following:

    <?php 
    $client_id = 'xxxx';   // application ID masked 
    $client_secret = 'xxxx';  //password/public key masked  
    $redirect_uri= "http://localhost/WebApp";
    $resource = "https://localhost/WebApp"; 
    $authorization_code = filter_input(INPUT_GET, 'code');          
    if(!$authorization_code){
        die('something went wrong!');
    }
    $url = 'https://login.microsoftonline.com/common/oauth2/v2.0/token';
    $data = array(
        'client_id' => $client_id,
        'code' => $authorization_code,
        'redirect_uri' => $redirect_uri,
        'resource' => $resource,
        'client_secret' => $client_secret
    );

    $options = array(
        'http' => array(
            'header'  => "Content-type: application/json\r\n",
            'method'  => 'POST',
            'content' => json_encode($data)
        )
    );
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
      //echo $authorization_code; 
    var_dump($result);
    ?>  

When I run this, I get the following error after the redirect:

Warning: file_get_contents(https://login.microsoftonline.com/common/oauth2/v2.0/token): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in C:\xampp\htdocs\MyApp\index.php on line 29

I also can navigate in the browser directly to the index.php page, which defeats the purpose of the authentication.

Any help is most appreciated!

READ ALSO
pdf to byte array conversion in php

pdf to byte array conversion in php

I need to convert Pdf file to byte array conversion in phpI am looking for like this result

52
Need help getting index or identifier to use it as an unique key from JSON object without converting it to an array

Need help getting index or identifier to use it as an unique key from JSON object without converting it to an array

i'm provided with a JSON object and i can output the values as i want to, but i also want to use the numbers (83 & 167 generated randomly) as shown in the code as an unique identifier, but i can't seem to get only the numbers, can someone point me in the right direction?

53
facebook chatbot send last news automatically

facebook chatbot send last news automatically

i make facebook chatbot with PHP but i want to send to all subscribe users the last news automatically every day (programming by specific time)

35
Hiding Stream Key from Source View and Web Console

Hiding Stream Key from Source View and Web Console

I have a live streaming site I'm currently working on and am running into an issue hiding the stream key fullyI've only thought of one option to get around this, but you're still able to see the stream key in view source and web console output:

40