Skip to content

cyrillef/simple-forge-php-sample

Repository files navigation

PHP 7 Platforms License

oAuth2 Data-Management OSS Viewer

Simple Forge Sample (supports 2 and 3 legged)

Note: For using this sample, you need a valid oAuth credential. Visit this page for instructions to get on-board.

Description

This sample exercises the PHP7 engine to demonstrate the Forge OAuth authorisation process and most of the Forge Services API such as Data Management, BIM360, Viewer, ...

Demonstrates the use of the Autodesk Forge API using a PHP7 application. Supports both 2 legged and 3 legged protocols.

Prerequisites

  1. Forge Account: Learn how to create a Forge Account, activate subscription and create an app at this tutorial.
  2. Visual Studio Code: other text editors could be used too, but Visual Studio Code is a widely used editor, see https://code.visualstudio.com/.
  3. PHP7: basic knowledge of PHP, see https://php.net/.
  4. JavaScript: basic knowledge.
  5. If you want to use the BIM360 API - BIM 360 or other Autodesk storage account: if you want to use it with files from BIM 360 Docs then you must be an Account Admin to add the app integration. Learn about provisioning.

Setup/Usage Instructions

  1. Install PHP7

  2. Download (fork, or clone) this project

  3. Install PHP dependency modules:

    php composer.phar install
  4. Request your consumer client/secret keys from https://forge.autodesk.com.

  5. Note for the 3 legged sample: while registering your keys, make sure that the callback you define for your callback (or redirect_uri) match your localhost and PORT number.

  6. Provision your application key on the BIM360 application integration page. Learn about provisioning. This step is not required for Fusion Team.

  7. Open the /server/.env file and set your data

  8. If using mySQL vs PHP_SESSION

    a. Edits /server/2legged-oauth.php at #41 #42

    b. Edits /server/3legged-oauth.php at #37 #38

    c. Create the mySQL table in your database - create statement here

    d. Edit your mySQL connection information here and here

  9. You can choose you default model by changing the URNs - for 2 legged here and for 3 legged here

  10. For 3 legged, specify your BIM360 or Fusion Team HUB and PROJECT IDs here

Note: To find your URN, hub_id, project_id, folder_id version_id, you can use the '/api/forge/public/3hubs-tree' endpoint.

  1. call http://localhost/api/forge/public/3hubs-tree which will give you the list of hubs and projects. Choose the pair you want to use.
  2. call the same endpoint with hub_id and project_id parameters, like this: 'http://localhost/api/forge/public/3hubs-tree?hub_id=a.YnVzaW5lc3M6ZnJlZTM4ODc&project_id=a.YnVzaW5lc3M6ZnJlZTM4ODcjMjAyMDA3MTUzMTU4OTMyODE' - replace values with yours from step 1.

Note: Edit the server/.env file and replace the placeholders by the values listed above.

Usage

To use the 2legged version, just got to the root of your server, for example http://localhost/

To use the 3legged version, go to http://localhost/login for creating a new pair of tokens, otherwise go to http://localhost/www/view.html. When using the /login option, you willbe redirected to /www/view.html after authentication.

Further reading

Documentation:

Tutorials:

Blogs:

thumbnail

License

This sample is licensed under the terms of the MIT License. Please see the LICENSE file for full details.

Written by

Cyrille Fauvel
Forge Developer Advocacy and Support
https://forge.autodesk.com/
https://around-the-corner.typepad.com

Thumbnail

thumbnail