Giter Site home page Giter Site logo

fangj99 / php-connect-rest-sample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from microsoftgraph/php-connect-rest-sample

0.0 2.0 0.0 276 KB

Use Microsoft Graph to access a user’s Microsoft account data from within a php web application. This sample gets OAuth tokens from the Azure AD v2.0 endpoint and uses REST calls directly to Microsoft Graph.

License: MIT License

HTML 4.48% PHP 93.22% CSS 0.83% JavaScript 0.52% Batchfile 0.55% Shell 0.39%

php-connect-rest-sample's Introduction

PHP Connect sample using Microsoft Graph

Build Status

Connecting to Microsoft Graph is the first step every app must take to start working with Office 365 services and data. This sample shows how to connect and then call one API through Microsoft Graph and uses the Office Fabric UI to create an Office 365 experience.

Try out the Microsoft Graph Quick Start page which simplifies registration so you can get this sample running faster.

PHP Connect sample screenshot

Note: For an in-depth look at the code, see [Call Microsoft Graph in a PHP app] (http://graph.microsoft.io/docs/platform/php).

Prerequisites

To use the PHP Connect sample, you need the following:

  • PHP is required to run the sample on a development server. The instructions in this sample use the PHP 5.4 built-in web server. However, the sample has also been tested on Internet Information Services and Apache Server.
    • Client URL (cURL) module. The web application uses cURL to issue requests to REST endpoints.
    • Composer, dependency manager for PHP

Register and configure the app

  1. Sign into the App Registration Portal using either your personal or work or school account.

  2. Select Add an app under Converged applications.

  3. Enter a name for the app, and select Create application.

    The registration page displays, listing the properties of your app.

  4. Under Platforms, select Add platform.

  5. Select Web.

  6. Add the following to the list of Redirect URIs:

    http://localhost:8000/oauth.php
    
  7. Under Application Secrets click Generate New Password.

  8. Copy the New password generated and Application Id, you'll need them in the next section.

  9. Click Save.

Configure and run the app

  1. Using your favorite IDE, open Constants.php in the src folder.

  2. Replace ENTER_YOUR_CLIENT_ID with the application id from the previous section.

  3. Replace ENTER_YOUR_SECRET with the password from the previous section.

  4. Install the dependencies with the following command:

    composer install
    
  5. Start the built-in web server with the following command:

    php -S 0.0.0.0:8000 -t app
    
  6. Navigate to http://localhost:8000 in your web browser.

Troubleshooting

Error: Unable to get local issuer certificate

You receive the following error after providing your credentials to the sign in page.

SSL certificate problem: unable to get local issuer certificate

cURL can't verify the validity of the Microsoft certificate when trying to issue a request call to get tokens. You must configure cURL to use a certificate when issuing https requests by following these steps:

  1. Download the cacert.pem file from cURL website.
  • In Chrome, right-click the cacert.pem link and choose Save link as.
  • In Microsoft Edge, right-click the cacert.pem link and choose Save target as. Then rename the saved file's htm extension to pem.
  1. Open your php.ini file and add the following line:

    curl.cainfo = "absolute_path_to_cacert/cacert.pem"
    
  2. Restart the server.

Contributing

If you'd like to contribute to this sample, see CONTRIBUTING.MD.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Questions and comments

We'd love to get your feedback about the PHP Connect sample. You can send your questions and suggestions to us in the Issues section of this repository.

Questions about Microsoft Graph development in general should be posted to Stack Overflow. Make sure that your questions or comments are tagged with [MicrosoftGraph] and [API].

Additional resources

Copyright

Copyright (c) 2016 Microsoft. All rights reserved.

php-connect-rest-sample's People

Contributors

ricalo avatar andrewjmay avatar iambmelt avatar krizalys avatar garethp avatar swgriffith avatar tadaomachida avatar o365devx avatar davidchesnut avatar

Watchers

 avatar  avatar

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.