├── .gitignore ├── src ├── ClientException.php ├── InvalidRequestException.php ├── Entity.php ├── Delegates │ ├── Authorize.php │ └── Receive.php ├── EndpointConfig.php └── ActiveDirectory.php ├── registration.php ├── examples ├── integration │ └── mcm │ │ └── index.php └── server │ └── index.php ├── composer.json ├── etc └── settings.xml ├── readme.MD └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | vendor/ 3 | composer.lock 4 | -------------------------------------------------------------------------------- /src/ClientException.php: -------------------------------------------------------------------------------- 1 | addSecureBase(__DIR__ . DIRECTORY_SEPARATOR . 'etc'); 5 | $repo->registerConfigurationFile( 6 | new \Magium\Configuration\File\Configuration\XmlFile( 7 | __DIR__ . DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'settings.xml' 8 | ) 9 | ); 10 | -------------------------------------------------------------------------------- /examples/integration/mcm/index.php: -------------------------------------------------------------------------------- 1 | getManager(); 9 | $configuration = $manager->getConfiguration(); 10 | 11 | $adapter = new \Magium\ActiveDirectory\ActiveDirectory($configuration, $request); 12 | 13 | $entity = $adapter->authenticate(); 14 | -------------------------------------------------------------------------------- /examples/server/index.php: -------------------------------------------------------------------------------- 1 | [ 9 | 'ad' => [ 10 | 'client_id' => '', 11 | 'client_secret' => '', 12 | 'enabled' => '1', 13 | 'directory' => '' 14 | ] 15 | ] 16 | ]; 17 | 18 | $request = new \Zend\Http\PhpEnvironment\Request(); 19 | 20 | $ad = new \Magium\ActiveDirectory\ActiveDirectory( 21 | new \Magium\Configuration\Config\Repository\ArrayConfigurationRepository($config), 22 | Zend\Psr7Bridge\Psr7ServerRequest::fromZend(new \Zend\Http\PhpEnvironment\Request()) 23 | ); 24 | 25 | $entity = $ad->authenticate(); 26 | 27 | echo $entity->getName() . '
'; 28 | echo $entity->getOid() . '
'; 29 | echo $entity->getPreferredUsername() . '
'; 30 | -------------------------------------------------------------------------------- /src/Entity.php: -------------------------------------------------------------------------------- 1 | data = $data; 13 | } 14 | 15 | public function __get($name) 16 | { 17 | if (isset($this->data[$name])) { 18 | return $this->data[$name]; 19 | } 20 | return null; 21 | } 22 | 23 | public function getAccessToken() 24 | { 25 | return $this->access_token; 26 | } 27 | 28 | public function getName() 29 | { 30 | return $this->name; 31 | } 32 | 33 | public function getOid() 34 | { 35 | return $this->oid; 36 | } 37 | 38 | public function getPreferredUsername() 39 | { 40 | return $this->preferred_username; 41 | } 42 | 43 | public function getData() 44 | { 45 | return $this->data; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "magium/active-directory", 3 | "description": "Provides connectivity to Active Directory implementations", 4 | "minimum-stability": "stable", 5 | "license": "Apache-2.0", 6 | "authors": [ 7 | { 8 | "name": "Kevin Schroeder", 9 | "email": "kschroeder@magiumlib.com" 10 | } 11 | ], 12 | "autoload": { 13 | "psr-4": { 14 | "Magium\\ActiveDirectory\\": "src" 15 | }, 16 | "files": [ 17 | "registration.php" 18 | ] 19 | }, 20 | "autoload-dev": { 21 | "psr-4": { 22 | "Magium\\ActiveDirectory\\Tests\\": "tests" 23 | } 24 | }, 25 | "require-dev": { 26 | "phpunit/phpunit": "^6.0 | ^7.0", 27 | "magium/magium": "~1.1" 28 | }, 29 | "require": { 30 | "magium/configuration-manager": "^1.0.1", 31 | "league/oauth2-client": "^1.4", 32 | "microsoft/microsoft-graph": "^1.0", 33 | "zendframework/zend-psr7bridge": "^0.2" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Delegates/Authorize.php: -------------------------------------------------------------------------------- 1 | provider = $provider; 24 | $this->response = $response; 25 | } 26 | 27 | public function execute() 28 | { 29 | $_SESSION[ActiveDirectory::SESSION_KEY] = []; 30 | $authorizationUrl = $this->provider->getAuthorizationUrl(); 31 | $_SESSION[ActiveDirectory::SESSION_KEY]['state'] = $this->provider->getState(); 32 | $finalResponse = new Response(); 33 | if ($this->response instanceof ResponseInterface) { 34 | $response = Psr7Response::toZend($this->response); 35 | $finalResponse->setHeaders($response->getHeaders()); 36 | } 37 | $location = (new Location())->setUri($authorizationUrl); 38 | $finalResponse->getHeaders()->addHeader($location); 39 | $finalResponse->setStatusCode(302); 40 | $finalResponse->sendHeaders(); 41 | // We do not send the body because it's irrelevant 42 | exit; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/EndpointConfig.php: -------------------------------------------------------------------------------- 1 | authorityUrl = $authorityUrl; 23 | $this->application = $application; 24 | $this->authorizeEndpoint = $authorizeEndpoint; 25 | $this->tokenEndpoint = $tokenEndpoint; 26 | $this->resourceId = $resourceId; 27 | } 28 | 29 | /** 30 | * @return string 31 | */ 32 | public function getAuthorityUrl() 33 | { 34 | return $this->authorityUrl . $this->application; 35 | } 36 | 37 | /** 38 | * @return string 39 | */ 40 | public function getAuthorizeEndpoint() 41 | { 42 | return $this->authorizeEndpoint; 43 | } 44 | 45 | /** 46 | * @return string 47 | */ 48 | public function getTokenEndpoint() 49 | { 50 | return $this->tokenEndpoint; 51 | } 52 | 53 | /** 54 | * @return string 55 | */ 56 | public function getResourceId() 57 | { 58 | return $this->resourceId; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /etc/settings.xml: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | Is the Magium Active Directory integration enabled? 6 | 0 7 | 8 | 9 | You need to configure an application in Active Directory and enter its ID here 10 | 11 | 12 | When you created an application in Active Directory you should have received a one-time use key. Enter that here. 13 | 14 | 15 | Provide a directory ID if you are using your own Azure instance instead of Microsoft's global database. The directory ID is usually found under the directory properties. 16 | common 17 | 18 | 19 | This is the URL you want Active Directory to redirect back to after authentication. 20 | 21 | 22 | Should the system remap HTTP-based URLs to HTTPS. Azure Active Directory generally will not redirect to a non-secure URL. Enabling this setting protects against that. 23 | 1 24 | 25 | 26 |
27 |
28 | -------------------------------------------------------------------------------- /src/Delegates/Receive.php: -------------------------------------------------------------------------------- 1 | request = $request; 31 | $this->provider = $provider; 32 | $this->response = $response; 33 | $this->returnUrl = $returnUrl; 34 | } 35 | 36 | /** 37 | * @return AbstractProvider 38 | */ 39 | public function getProvider() 40 | { 41 | return $this->provider; 42 | } 43 | 44 | /** 45 | * @return ServerRequestInterface 46 | */ 47 | public function getRequest() 48 | { 49 | return $this->request; 50 | } 51 | 52 | /** 53 | * @return ResponseInterface 54 | */ 55 | public function getResponse() 56 | { 57 | return $this->response; 58 | } 59 | 60 | /** 61 | * @return mixed 62 | */ 63 | public function getReturnUrl() 64 | { 65 | return $this->returnUrl; 66 | } 67 | 68 | public function execute() 69 | { 70 | $params = $this->getRequest()->getQueryParams(); 71 | if ( 72 | !isset($_SESSION[ActiveDirectory::SESSION_KEY]['state']) 73 | || empty($params['state']) 74 | || ($params['state'] !== $_SESSION[ActiveDirectory::SESSION_KEY]['state']) 75 | ) { 76 | unset($_SESSION[ActiveDirectory::SESSION_KEY]); 77 | throw new InvalidRequestException('Request state did not match'); 78 | } 79 | // Get an access token using the authorization code grant 80 | $accessToken = $this->getProvider()->getAccessToken('authorization_code', [ 81 | 'code' => $params['code'] 82 | ]); 83 | 84 | // The id token is a JWT token that contains information about the user 85 | // It's a base64 coded string that has a header, payload and signature 86 | $idToken = $accessToken->getValues()['id_token']; 87 | $decodedAccessTokenPayload = base64_decode( 88 | explode('.', $idToken)[1] 89 | ); 90 | $jsonAccessTokenPayload = json_decode($decodedAccessTokenPayload, true); 91 | 92 | $data = $jsonAccessTokenPayload; 93 | $data['access_token'] = $accessToken->getToken(); 94 | $entity = new Entity($data); 95 | $_SESSION[ActiveDirectory::SESSION_KEY]['entity'] = $entity; 96 | 97 | $response = $this->getResponse(); 98 | if ($response instanceof ResponseInterface) { 99 | $response = new Response(Psr7Response::toZend($response)); 100 | } 101 | $location = (new Location())->setUri($this->getReturnUrl()); 102 | $response->getHeaders()->addHeader($location); 103 | $response->setStatusCode(302); 104 | $response->sendHeaders(); 105 | exit; 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/ActiveDirectory.php: -------------------------------------------------------------------------------- 1 | config = $config; 47 | $this->request = $request; 48 | $this->returnUrl = $returnUrl; 49 | $this->scopes = $scopes; 50 | $this->response = $response; 51 | $this->oauthProvider = $oauthProvider; 52 | $this->endpointConfig = $endpointConfig; 53 | } 54 | 55 | /** 56 | * @param ConfigInterface $config 57 | */ 58 | public function setConfig($config) 59 | { 60 | $this->config = $config; 61 | } 62 | 63 | public function getConfig() 64 | { 65 | return $this->config; 66 | } 67 | 68 | /** 69 | * @param ServerRequestInterface $request 70 | */ 71 | public function setRequest($request) 72 | { 73 | $this->request = $request; 74 | } 75 | 76 | /** 77 | * @param ResponseInterface $response 78 | */ 79 | public function setResponse($response) 80 | { 81 | $this->response = $response; 82 | } 83 | 84 | /** 85 | * @param string $scopes 86 | */ 87 | public function setScopes($scopes) 88 | { 89 | $this->scopes = $scopes; 90 | } 91 | 92 | /** 93 | * @param EndpointConfig $endpointConfig 94 | */ 95 | public function setEndpointConfig($endpointConfig) 96 | { 97 | $this->endpointConfig = $endpointConfig; 98 | } 99 | 100 | /** 101 | * @param AbstractProvider $oauthProvider 102 | */ 103 | public function setOauthProvider($oauthProvider) 104 | { 105 | $this->oauthProvider = $oauthProvider; 106 | } 107 | 108 | public function getProvider() 109 | { 110 | if (!$this->oauthProvider instanceof AbstractProvider) { 111 | $endPointConfig = $this->getEndpointConfig(); 112 | $this->oauthProvider = new GenericProvider([ 113 | 'clientId' => $this->config->getValue(self::CONFIG_CLIENT_ID), 114 | 'clientSecret' => $this->config->getValue(self::CONFIG_CLIENT_SECRET), 115 | 'redirectUri' => $this->getReturnUrl($this->request), 116 | 'urlAuthorize' => $endPointConfig->getAuthorityUrl() . $endPointConfig->getAuthorizeEndpoint(), 117 | 'urlAccessToken' => $endPointConfig->getAuthorityUrl() . $endPointConfig->getTokenEndpoint(), 118 | 'urlResourceOwnerDetails' => '', 119 | 'scopes' => $this->scopes 120 | ]); 121 | } 122 | return $this->oauthProvider; 123 | } 124 | 125 | public function getRequest() 126 | { 127 | return $this->request; 128 | } 129 | 130 | public function isEnabled() 131 | { 132 | return $this->config->getValueFlag(self::CONFIG_ENABLED); 133 | } 134 | 135 | public function forget() 136 | { 137 | if (isset($_SESSION[self::SESSION_KEY])) { 138 | unset($_SESSION[self::SESSION_KEY]); 139 | } 140 | } 141 | 142 | public function getResponse() 143 | { 144 | if (!$this->response instanceof ResponseInterface) { 145 | $this->response = Psr7Response::fromZend(new Response()); 146 | } 147 | return $this->response; 148 | } 149 | 150 | public function authenticate() 151 | { 152 | if (!$this->isEnabled()) { 153 | throw new InvalidRequestException('Do not authenticate if the Active Directory integration is not enabled'); 154 | } 155 | if (session_status() !== PHP_SESSION_ACTIVE) { 156 | throw new InvalidRequestException('The PHP session must be started prior to authenticating'); 157 | } 158 | 159 | if (isset($_SESSION[self::SESSION_KEY]['entity'])) { 160 | return $_SESSION[self::SESSION_KEY]['entity']; 161 | } 162 | 163 | $request = $this->getRequest(); 164 | $params = $request->getQueryParams(); 165 | 166 | if ($request->getMethod() == 'GET' && isset($params['error'])) { 167 | throw new ClientException($params['error_description']); 168 | } else if ($request->getMethod() == 'GET' && !isset($params['code'])) { 169 | (new Authorize( 170 | $this->getProvider(), 171 | $this->getResponse() 172 | ))->execute(); 173 | } else if ($request->getMethod() == 'GET' && isset($params['code'])) { 174 | (new Receive( 175 | $this->getRequest(), 176 | $this->getProvider(), 177 | $this->getResponse(), 178 | $this->getReturnUrl($request) 179 | ))->execute(); 180 | } 181 | throw new InvalidRequestException('Could not understand the request'); 182 | } 183 | 184 | public function setReturnUrl($url) 185 | { 186 | $uri = new Uri((string)$url); 187 | $this->returnUrl = $this->rewriteUrl( 188 | $uri->getScheme(), 189 | $uri->getHost(), 190 | $uri->getPath(), 191 | $uri->getPort(), 192 | $uri->getQuery() 193 | ); 194 | } 195 | 196 | public function getReturnUrl(ServerRequestInterface $request) 197 | { 198 | if ($this->returnUrl === null) { 199 | $configReturnUrl = $this->getConfig()->getValue(self::CONFIG_RETURN_URL); 200 | if ($configReturnUrl) { 201 | $this->returnUrl = $configReturnUrl; 202 | } else { 203 | $this->returnUrl = $this->getDefaultReturnUrl($request); 204 | } 205 | } 206 | return $this->returnUrl; 207 | } 208 | 209 | public function getEndpointConfig() 210 | { 211 | if (!$this->endpointConfig instanceof EndpointConfig) { 212 | $tenant = $this->getConfig()->getValue(self::CONFIG_TENANT); 213 | if ($tenant) { 214 | $this->endpointConfig = new EndpointConfig($tenant); 215 | } else { 216 | $this->endpointConfig = new EndpointConfig(); 217 | } 218 | } 219 | return $this->endpointConfig; 220 | } 221 | 222 | private function rewriteUrl($scheme, $host, $path, $port, $query) 223 | { 224 | $uri = new Uri(); 225 | if ($host != 'localhost' 226 | && $this->config->getValueFlag(self::CONFIG_REMAP_HTTPS)) { 227 | $uri->setScheme('https'); 228 | } else { 229 | $uri->setScheme($scheme); 230 | } 231 | $uri->setHost($host); 232 | $uri->setPath($path); 233 | $uri->setPort($port); 234 | $uri->setQuery($query); 235 | return $uri->toString(); 236 | } 237 | 238 | public function getDefaultReturnUrl(ServerRequestInterface $request) 239 | { 240 | $uri = $request->getUri(); 241 | return $this->rewriteUrl($uri->getScheme(), $uri->getHost(), $uri->getPath(), $uri->getPort(), $uri->getQuery()); 242 | } 243 | 244 | } 245 | -------------------------------------------------------------------------------- /readme.MD: -------------------------------------------------------------------------------- 1 | # Package is deprecated 2 | 3 | My apologies to all. I do not have time to maintain this code. If you are interested in maintaining this code feel free to fork it or create a derivative work. I would direct people there frmo here. 4 | 5 | # Magium Active Directory Integration 6 | 7 | *For stupid-easy PHP integration with Azure Active Directory*. 8 | 9 | This is a simple library that uses the `league/oauth2-client` to provide OAuth2 based integration with Active Directory. Out of the box it is configured to work with Active Directory on Azure but, though I haven't tested it, you can provide a different configuration object to the primary adapter and you should be able to authenticate against any Active Directory implementation as long as it has OAuth2 connectivity. 10 | 11 | There are two purposes (well, three) for library. 12 | 13 | 1. Provide sub-5 minute installation and integration times for any PHP-based application 14 | 2. Provide a launching pad for other third-party integrations to Microsoft Azure Active Directory, such as Magento, Drupal, Oro, or whatever. 15 | 3. (provide libraries that use other Magium libraries so people can see how awesome all the Magium stuff is) 16 | 17 | First, watch the [installation video on YouTube](https://www.youtube.com/watch?v=9FupzL2XsqA). It shows you how to create an application in Azure Active Directory. A big part of the installation is going to the Microsoft Application Console at [https://apps.dev.microsoft.com](https://apps.dev.microsoft.com). That is where you are going to get all of your authentication keys and such. 18 | 19 | **Note** Azure will not redirect from a secure URL (i.e. their login page) to an unsecure page (i.e. your page). No HTTPS to HTTP in other words. In yet other words, if you use Azure you will need to also use HTTPS. Though there are worse things in the world... like *not* using HTTPS. 20 | 21 | ## Basic Usage 22 | 23 | Anywhere in your application that requires authentication you can provide this code (properly architected, not cut and paste, in other words): 24 | 25 | ``` php 26 | $ad = new \Magium\ActiveDirectory\ActiveDirectory( 27 | $configuration, // shown later 28 | $psr7CompatibleRequest 29 | ); 30 | 31 | $entity = $ad->authenticate(); 32 | ``` 33 | 34 | The `authenticate()` method will do 1 of 3 things. 35 | 36 | 1. Check the session and see that the user is not logged in, forwarding that person to their Azure Active Directory login page 37 | 2. Validate return data from Active Directory 38 | 3. Simply return the `Entity` object if the person is already logged in. 39 | 40 | If you want to log out all you do is: 41 | 42 | ``` php 43 | $ad->forget(); 44 | ``` 45 | 46 | Not that this only purges the AD entity from the session, it does not do any other session cleanup for your application. 47 | 48 | Clearly this library is not intended to be your only means of session management, though, for simple applications, you could use it that way. Most likely you will want to take the data retrieved from AD and link it to a local account. The `Entity` class has 3 defined getters to help you do this mapping: 49 | 50 | ``` php 51 | echo $entity->getName() . '
'; // The user's name 52 | echo $entity->getOid() . '
'; //The user's AD object ID, useful for mapping to a local user obhect 53 | echo $entity->getPreferredUsername() . '
'; // The user's username, usually an email address. 54 | ``` 55 | 56 | ## Installation 57 | 58 | ``` 59 | composer require magium/active-directory 60 | ``` 61 | 62 | Done. 63 | 64 | ## Configuration 65 | 66 | This is a little more in-depth, but it shouldn't be overly complex. 67 | 68 | The base configuration is managed by the [Magium Configuration Manager](https://www.github.com/magium/configuration-manager), out of the box. But, that said, the MCM has a really simple mechanism that allows you to not use the underlying plumbing. I believe that the underlying plumbing will eventually make application management easier, but I'm not going to force it on you. 69 | 70 | ### Configuration using the Magium Configuration Manager 71 | 72 | The configuration manager provides the means to manage and deploy settings at runtime in both a CLI and (eventually) a web-based interface. If you are using the configuration manager you need to get an instance of the configuration factory, which provides an instance of the manager, which provides the configuration object. The `ActiveDirectory` adapter requires that configuration object. 73 | 74 | ``` php 75 | // Convert to PSR7 request object 76 | $request = \Zend\Psr7Bridge\Psr7ServerRequest::fromZend( 77 | new \Zend\Http\PhpEnvironment\Request() 78 | ); 79 | 80 | $factory = new \Magium\Configuration\MagiumConfigurationFactory(); 81 | $manager = $factory->getManager(); 82 | $configuration = $manager->getConfiguration(); 83 | 84 | $adapter = new \Magium\ActiveDirectory\ActiveDirectory($configuration, $request); 85 | 86 | $entity = $adapter->authenticate(); 87 | ``` 88 | 89 | First, in your application root directory run `vendor/bin/magium magium:configuration:list-keys`. This is done after you have configured the MCM according to its instructions in the GitHub link. You will see output like this: 90 | 91 | ``` 92 | Valid configuration keys 93 | authentication/ad/enabled (default: 0) 94 | (Is the Magium Active Directory integration enabled?) 95 | 96 | authentication/ad/client_id 97 | (You need to configure an application in Active Directory and enter its ID here) 98 | 99 | authentication/ad/client_secret 100 | (When you created an application in Active Directory you should have received a one-time use key. Enter that here. ) 101 | 102 | authentication/ad/directory (default: common) 103 | (Provide a directory ID if you are using your own Azure instance instead of Microsoft's global database. The directory ID is usually found under the directory properties.) 104 | 105 | authentication/ad/return_url 106 | (This is the URL you want Active Directory to redirect back to after authentication.) 107 | 108 | authentication/ad/remap_https (default: 1) 109 | (Should the system remap HTTP-based URLs to HTTPS. Azure Active Directory generally will not redirect to a non-secure URL. Enabling this setting protects against that.) 110 | ``` 111 | 112 | You will need to provide those two values for the configuration: 113 | 114 | ``` 115 | vendor/bin/magium magium:configuration:set magium/ad/client_id '' 116 | Set magium/ad/client_id to (context: default) 117 | Don't forget to rebuild your configuration cache with magium:configuration:build 118 | 119 | vendor/bin/magium magium:configuration:set magium/ad/client_secret '' 120 | Set magium/ad/client_secret to (context: default) 121 | Don't forget to rebuild your configuration cache with magium:configuration:build 122 | 123 | vendor/bin/magium magium:configuration:build 124 | Building context: default 125 | Building context: production 126 | Building context: development 127 | ``` 128 | 129 | And you should be good to go. 130 | 131 | **Achtung!!!** The defaults for the adapter will allow *anyone* with a Microsoft ID to access your system, kind of like allowing any Twitter user access your system if they have a valid Twitter account. If you are looking to authenticate against your own Active Directory instance make sure you provide the Directory ID for the directory you will to validate against. All of the following examples include the directory configuration key, whose default is "common". Make sure you are authenticating not just against the correct application with the client_id, but also the correct directory with the directory key. 132 | 133 | ### Configuration using PHP Arrays 134 | 135 | Now, I know the MCM is new and you probably aren't using it. That's why I provided a way for you configure the adapter without using the full-blown MCM. You can use the `Magium\Configuration\Config\Repository\ArrayConfigurationRepository` class to provide a raw array that will be mapped to the two configuration settings `magium/ad/client_id` and `magium/ad/client_secret` 136 | 137 | ``` php 138 | session_start(); 139 | 140 | $config = [ 141 | 'authentication' => [ 142 | 'ad' => [ 143 | 'client_id' => '', 144 | 'client_secret' => '', 145 | 'enabled' => 'yes', 146 | 'directory' => '' 147 | ] 148 | ] 149 | ]; 150 | 151 | $request = new \Zend\Http\PhpEnvironment\Request(); 152 | 153 | $ad = new \Magium\ActiveDirectory\ActiveDirectory( 154 | new \Magium\Configuration\Config\Repository\ArrayConfigurationRepository($config), 155 | Zend\Psr7Bridge\Psr7ServerRequest::fromZend(new \Zend\Http\PhpEnvironment\Request()) 156 | ); 157 | 158 | $entity = $ad->authenticate(); 159 | 160 | echo $entity->getName() . '
'; 161 | echo $entity->getOid() . '
'; 162 | echo $entity->getPreferredUsername() . '
'; 163 | ``` 164 | 165 | ### Configuration using YAML 166 | 167 | Pretty much the same, but rather than using the `ArrayConfigurationRepository` you will use the `YamlConfigurationRepository`. It's pretty similar: 168 | 169 | ``` php 170 | $yaml = << 174 | client_secret: 175 | enabled: yes 176 | directory: 177 | YAML; 178 | 179 | $obj = new YamlConfigurationRepository(trim($yaml)); 180 | $ad = new \Magium\ActiveDirectory\ActiveDirectory( 181 | $obj, $request 182 | ); 183 | 184 | $entity = $ad->authenticate(); 185 | ``` 186 | 187 | ### Configuration using JSON 188 | 189 | Pretty much the same, but rather than using the `YamlConfigurationRepository` you will use the `JsonConfigurationRepository`. It's pretty similar: 190 | 191 | ``` php 192 | $json = <<", 197 | "client_secret": "", 198 | "enabled": "yes", 199 | "directory": "" 200 | } 201 | } 202 | } 203 | JSON; 204 | $obj = new JsonConfigurationRepository(trim($json)); 205 | $ad = new \Magium\ActiveDirectory\ActiveDirectory( 206 | $obj, $request 207 | ); 208 | 209 | $entity = $ad->authenticate(); 210 | ``` 211 | 212 | ### Configuration using INI Files 213 | 214 | Pretty much the same, but rather than using the `JsonConfigurationRepository` you will use the `IniConfigurationRepository`. It's pretty similar: 215 | 216 | ``` php 217 | $ini = << 220 | ad[client_srcret] = 221 | ad[enabled] = yes 222 | ad[directory] = 223 | INI; 224 | 225 | $obj = new IniConfigurationRepository(trim($ini)); 226 | $ad = new \Magium\ActiveDirectory\ActiveDirectory( 227 | $obj, $request 228 | ); 229 | 230 | $entity = $ad->authenticate(); 231 | ``` 232 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------