Coder Social home page Coder Social logo

nixomose / php_office365_cleintcred Goto Github PK

View Code? Open in Web Editor NEW

This project forked from therealmarknelson/php_office365_cleintcred

0.0 2.0 0.0 13 KB

An example of how to implement Office 365 OAuth2 client flow in PHP

License: MIT License

ApacheConf 0.49% PHP 99.51%

php_office365_cleintcred's Introduction

Office 365 OAuth2 client credential flow Example in PHP

--

Description

This is a sample illustrating how to implement the client credential OAuth flow in PHP. The app allows an administrator to login and give consent. Once consent is given the logged in user can view inbox emails and upcoming calendar events of any user in the organization.

Requirements:

Composer and ramsey/uuid are not required. ramsey/uuid is used in the example to create version 4 (random) UUID objects. These random objects are used as the nonce for the api calls.

Running the Example

  1. Download or fork the sample project.

  2. Register the app in Azure Active Directory. The app should be registered as a web app with a Sign-on URL that matches the url of your development environment. IE: http://127.0.0.1/

  3. Set the Reply Url to the url of your development environment /get_consent. IE: http://127.0.0.1/get_consent.

  4. In the permissions to other applications section give the Office 365 Exchange Online application permission to "Read and write calendars in all mailboxes" and "Read mail in all mailboxes."

  5. Configure an X509 certificate for your app following the directions here.

  6. Extract the private key in RSA format from your certificate and save it to a PEM file. You can use openssl to do this: openssl pkcs12 -in <path to PFX file> -nodes -nocerts -passin pass:<cert password> | openssl rsa -out appcert.pem'

  7. Add the private key .PEM file to office365/certificates/

  8. Open the file index.php and set the Client Id, Secret, Thumbprint.

    1. Set the ClientId to the application Client id.
    2. Set the Secret to the secret key generated when you created the application.
    3. Set the Thumbprint to the thumbprint key you created when you configured the X509 certificate.
    4. Set the AuthorizationRedirectUrl to the Reply Url you set in the application. IE: http://127.0.0.1/get_consent
  9. If you named your private key .PEM file something other than appcert.PEM open the file office365/Office365.php and change the static variable $privateKeyFileName to the name of your certificate.

  10. Install Composer and ramsey/uuid. If you do not want to include Composer and ramsey/uuid in the project then go to the file office365/ApiResource.php and modify the method nonce() to return a custom nonce string. To install Composer and ramsey/uuid navigate to the root folder of the project. In your command prompt and run the following command to install Composer. curl -sS https://getcomposer.org/installer | php -- --install-dir=bin Once Composer is installed run the following command to include the ramsey/uuid project. composer require ramsey/uuid

  11. Start your development server and enter the url to the root url. IE: http://127.0.0.1/

  12. Click the link "Connect Me!" and login using an administrative account. Once logged in you will be redirected back to the development site. You will see a link to Email and Calendar.

  13. On the Email page enter a valid email address for a user in the Office 365 tenant and click the "Submit" button. You will receive a response of the most recent 10 emails for the user.

  14. On the Calendar page enter a valid email address for a user in the Office 365 tenant and click the "Submit" button. You will receive a response of all calendar events in the next 30 days for the user.


Connect with me on Twitter @marknelsondev

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.