Giter Site home page Giter Site logo

core-php-client's Introduction

Core Component (internal)

Requirements

PHP 5.4.0 and later

Installation & Usage

Composer

To install the bindings via Composer run:

composer require autodesk/core

Manual Installation

Download the files and include autoload.php:

require_once('/path/to/AutodeskCore/autoload.php');

Tests

To run the unit tests:

composer install
./vendor/bin/phpunit

Getting Started

Please follow the installation procedure and then run the following:

Two legged

<?php

require_once __DIR__ . '/vendor/autoload.php';

Autodesk\Auth\Configuration::getDefaultConfiguration()
    ->setClientId('XXXXXX')
    ->setClientSecret('XXXXXX');

$twoLeggedAuth = new Autodesk\Auth\OAuth2\TwoLeggedAuth();
$twoLeggedAuth->setScopes(['bucket:read']);

/**
 * Other options to manage the scopes
 *
 * $twoLeggedAuth->addScope('data:read');
 * $twoLeggedAuth->addScopes([]);
 * $twoLeggedAuth->setScopes($scopes);
 */

if (isset($cache['applicationToken']) && $cache['expiry'] > time()) {
    $twoLeggedAuth->setAccessToken($cache['applicationToken']);
} else {
    $twoLeggedAuth->fetchToken();

    $cache['applicationToken'] = $twoLeggedAuth->getAccessToken();
    $cache['expiry'] = time() + $twoLeggedAuth->getExpiresIn();
}

Three legged

index.php

<?php

require_once __DIR__ . '/vendor/autoload.php';

session_start();

Autodesk\Auth\Configuration::getDefaultConfiguration()
    ->setClientId('XXXXXX')
    ->setClientSecret('XXXXXX')
    ->setRedirectUrl("http://{$_SERVER['HTTP_HOST']}/callback.php");

$threeLeggedAuth = new Autodesk\Auth\OAuth2\ThreeLeggedAuth();
$threeLeggedAuth->addScope('code:all');

if (isset($_SESSION['isAuthenticated']) && $_SESSION['expiry'] > time()) {
    $threeLeggedAuth->setAccessToken($_SESSION['accessToken']);

    print_r('Token was fetched from the session');
} else {
    if (isset($_SESSION['refreshToken'])) {
        $threeLeggedAuth->refreshToken($_SESSION['refreshToken']);

        $_SESSION['isAuthenticated'] = true;
        $_SESSION['accessToken'] = $threeLeggedAuth->getAccessToken();
        $_SESSION['refreshToken'] = $threeLeggedAuth->getRefreshToken();
        $_SESSION['expiry'] = time() + $threeLeggedAuth->getExpiresIn();

        print_r('Token was refreshed');
    } else {
        $redirectTo = $threeLeggedAuth->createAuthUrl();

        header('Location: ' . filter_var($redirectTo, FILTER_SANITIZE_URL));
        return;
    }
}

callback.php

<?php

require_once __DIR__ . '/vendor/autoload.php';

session_start();

Autodesk\Auth\Configuration::getDefaultConfiguration()
    ->setClientId('XXXXXX')
    ->setClientSecret('XXXXXX')
    ->setRedirectUrl("http://{$_SERVER['HTTP_HOST']}/callback.php");

$threeLeggedAuth = new Autodesk\Auth\OAuth2\ThreeLeggedAuth();
$threeLeggedAuth->addScopes(['data:read']);

if (isset($_GET['code']) && $_GET['code']) {
    $threeLeggedAuth->fetchToken($_GET['code']);

    $_SESSION['isAuthenticated'] = true;
    $_SESSION['accessToken'] = $threeLeggedAuth->getAccessToken();
    $_SESSION['refreshToken'] = $threeLeggedAuth->getRefreshToken();
    $_SESSION['expiry'] = time() + $threeLeggedAuth->getExpiresIn();

    $url = 'http://' . $_SERVER['HTTP_HOST'] . '/';
    header('Location: ' . filter_var($url, FILTER_SANITIZE_URL));
} else {
    header('Location: ' . $threeLeggedAuth->createAuthUrl());
}

Documentation For Authorization

  • data:read: The application will be able to read the end user’s data within the Autodesk ecosystem.
  • data:write: The application will be able to create, update, and delete data on behalf of the end user within the Autodesk ecosystem.
  • data:create: The application will be able to create data on behalf of the end user within the Autodesk ecosystem.
  • data:search: The application will be able to search the end user’s data within the Autodesk ecosystem.
  • bucket:create: The application will be able to create an OSS bucket it will own.
  • bucket:read: The application will be able to read the metadata and list contents for OSS buckets that it has access to.
  • bucket:update: The application will be able to set permissions and entitlements for OSS buckets that it has permission to modify.
  • bucket:delete: The application will be able to delete a bucket that it has permission to delete.
  • code:all: The application will be able to author and execute code on behalf of the end user (e.g., scripts processed by the Design Automation API).
  • account:read: For Product APIs, the application will be able to read the account data the end user has entitlements to.
  • account:write: For Product APIs, the application will be able to update the account data the end user has entitlements to.
  • user-profile:read: The application will be able to read the end user’s profile data.

Author

[email protected]

core-php-client's People

Contributors

augustogoncalves avatar ido567 avatar johnonsoftware avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

core-php-client's Issues

Client doesn't work with PHP < 5.6.0

The documentation specify that the client works with PHP >= 5.4.0. But classes ScopeValidator and TokenFetcher define array constants, which are only supported in PHP >= 5.6.0.

This throws the following error: Arrays are not allowed in class constants.

Add CI integration

To let this package functionality behaviors be reliable, I think it should add the CI integration.

IMHO, we can consider using the Travis CI to accomplish this issue.

Upgrading guzzle dependency to last major 7.5.0

Hello,

Could it be possible to upgrade to guzzlehttp dependency to the last major version 7.5.0 if submitting a PR ?
Thiw would fix the last "outdated" warning from composer outdated command. However for now this is not an emergency we can work with the v6.5.8

Have a nice day,
Guillaume

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.