Git Product home page Git Product logo

venveo / azure-activedirectory-library-for-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from introp-software/azure-activedirectory-library-for-php

1.0 2.0 0.0 29 KB

The ADAL SDK for PHP gives your application the full functionality of Microsoft Azure AD, including industry standard protocol support for OAuth2, Web API integration with user level consent, and two factor authentication support.

License: Other

PHP 100.00%

azure-activedirectory-library-for-php's Introduction

Microsoft Azure Active Directory Authentication Library (ADAL) for PHP

The ADAL SDK for PHP gives your application the full functionality of Microsoft Azure AD, including industry standard protocol support for OAuth2, Web API integration with user level consent, and two factor authentication support.

NOTE

This is an early, pre-release version of the library.

Installation

To install this library:

git clone [email protected]:AzureAD/azure-activedirectory-for-php.git

This library is mostly self-contained, however it uses PSR-4 for autoloading, and PHPUnit for unit testing. You can use Composer to install PHPUnit and generate a PSR-4 autoloader.

  1. See https://getcomposer.org/ for information on how to install composer on your system.
  2. Run php composer.phar install to install PHPUnit and generate a PSR-4 autoloader.
  3. You can then use the Composer autoloader by requiring the vendor/autoload.php file in your scripts.

Usage

Construct an HttpClient object:

$httpclient = new \microsoft\adalphp\HttpClient;

Construct a storage object. A storage object needs to implement the \microsoft\adalphp\OIDC\StorageInterface interface. Currently, two sample implementations are available under microsoft\adalphp\OIDC\StorageProviders namespace - SQLite and Session, but you may need to implement this class yourself based on your storage needs or environment. Initialize SQLite storage provider (as shown in samples folder):

$storage = new \microsoft\adalphp\OIDC\StorageInterface\SQLite(__DIR__.'/storagedb.sqlite');

or initialize the Session storage provider:

$storage = new \microsoft\adalphp\OIDC\StorageInterface\Session();

Construct the AzureAD client class using the $httpclient and $storage instances.

$client = new \microsoft\adalphp\AAD\Client($httpclient, $storage);

Set your client ID, client secret, and redirect URI.

$client->set_clientid($clientid);
$client->set_clientsecret($clientsecret);
$client->set_redirecturi($redirecturi);

You client is now ready to use.

To initiate an authorization request:

$client->authrequest();

To handle an authorization request response (this should be in your redirect URI page):

list($idtoken, $tokenparams, $stateparams) = $client->handle_auth_response($_REQUEST);

To perform a resource-owner credentials request:

$returned = $client->rocredsrequest($_POST['username'], $_POST['password']);
$idtoken = \microsoft\adalphp\AAD\IDToken::instance_from_encoded($returned['id_token']);

To get user information from an IDToken, call ->claim() on the $idtoken object. This returns OpenID Connect claims:

$idtoken->claim('name');
$idtoken->claim('upn');

Samples and Documentation

The samples folder contains a sample implementation of the library demonstrating basic authentication in several different ways.

Community Help and Support

We leverage Stack Overflow to work with the community on supporting Azure Active Directory and its SDKs, including this one! We highly recommend you ask your questions on Stack Overflow (we're all on there!) Also browse existing issues to see if someone has had your question before.

We recommend you use the "adal" tag so we can see it! Here is the latest Q&A on Stack Overflow for ADAL: http://stackoverflow.com/questions/tagged/adal

Contributing

All code is licensed under the MIT license and we triage actively on GitHub. We enthusiastically welcome contributions and feedback. You can fork the repo and start contributing now. More details about contributing.

License

Copyright (c) Microsoft Corporation. Licensed under the MIT License.

azure-activedirectory-library-for-php's People

Contributors

hajekj avatar jamesmcq avatar zckb avatar

Stargazers

 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.