TheNetworg / oauth2-azure

Azure AD provider for the OAuth 2.0 Client.
https://packagist.org/packages/thenetworg/oauth2-azure
MIT License
230 stars 108 forks source link

Class 'Azure' not found #106

Closed sftgunner closed 4 years ago

sftgunner commented 4 years ago

Apologies if this is a really obvious fix.

I tried to install and set up oauth2-azure by running composer require thenetworg/oauth2-azure in a new directory on my webserver, which appeared to complete successfully.

However, when I copied and pasted the Authorization Code Flow sample from the README file, i get the following error:

Fatal error: Uncaught Error: Class 'Azure' not found in /Users/Gunner237/GitHub/oauth-test/index.php:11 Stack trace: #0 {main} thrown in /Users/Gunner237/GitHub/oauth-test/index.php on line 11.

index.php is identical to the code in the Authorization Code Flow sample from the README, except that I added the line require_once __DIR__ . '/vendor/autoload.php'; at the beginning, and substituted my own client ID, secret and redirect URI for the placeholders.

I've tried deleting the vendor and composer files and redownloading different branches, but to no avail.

When I tried commenting out the offending line (beginning $provider->defaultEndPointVersion), as the comment above seems to imply that that line is optional, I instead receive this error

Fatal error: Uncaught Error: Call to undefined method TheNetworg\OAuth2\Client\Provider\Azure::getRootMicrosoftGraphUri() in /Users/Gunner237/GitHub/oauth-test/index.php:13 Stack trace: #0 {main} thrown in /Users/Gunner237/GitHub/oauth-test/index.php on line 13

Line 13 is $baseGraphUri = $provider->getRootMicrosoftGraphUri(null);

I'm using Apache2 on MacOS 10.15.4 with PHP 7.3.11 by default, if that makes a difference. Composer is up-to-date (1.10.6).

Below is the total CLI output when trying to use composer:

Gunner237@My-Mac oauth-test % composer require thenetworg/oauth2-azure
Using version ^1.4 for thenetworg/oauth2-azure
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 12 installs, 0 updates, 0 removals
  - Installing firebase/php-jwt (v5.2.0): Loading from cache
  - Installing paragonie/random_compat (v9.99.99): Downloading (100%)         
  - Installing ralouphie/getallheaders (3.0.3): Loading from cache
  - Installing psr/http-message (1.0.1): Downloading (100%)         
  - Installing guzzlehttp/psr7 (1.6.1): Loading from cache
  - Installing guzzlehttp/promises (v1.3.1): Downloading (100%)         
  - Installing symfony/polyfill-php72 (v1.17.0): Loading from cache
  - Installing symfony/polyfill-mbstring (v1.17.0): Loading from cache
  - Installing symfony/polyfill-intl-idn (v1.17.0): Loading from cache
  - Installing guzzlehttp/guzzle (6.5.3): Loading from cache
  - Installing league/oauth2-client (2.4.1): Downloading (100%)         
  - Installing thenetworg/oauth2-azure (v1.4.2): Downloading (100%)         
paragonie/random_compat suggests installing ext-libsodium (Provides a modern crypto API that can be used to generate random bytes.)
guzzlehttp/psr7 suggests installing zendframework/zend-httphandlerrunner (Emit PSR-7 responses)
symfony/polyfill-intl-idn suggests installing ext-intl (For best performance)
guzzlehttp/guzzle suggests installing psr/log (Required for using the Log middleware)
Writing lock file
Generating autoload files
3 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
mbrouwer88nl commented 4 years ago

Same issue here! Did the same as Gunner 237. Used the exact example for the readme, and just added autoload.php and entered variables of my app.

Running the script results in "PHP Fatal error: Uncaught Error: Class 'Azure' not found in C:\inetpub\site5\public\aad.php:13".

I am running IIS 10 and PHP 7.3.7.

skle commented 4 years ago

I had the same problem. Turns out, using composer, the latest version is 1.4.2. The documentation on this github page is not compatible with this version. Solution is to use the documentation on the 1.4.2 tree: https://github.com/TheNetworg/oauth2-azure/tree/v1.4.2.

This offcourse if you decide to use the 1.4.2 version.

mbrouwer88nl commented 4 years ago

Hi SKLE, okay, that explains why it's not working.

But what version do we need to use for the example in the documentation then? Is there something newer than 1.4.2?

sftgunner commented 4 years ago

@skle I also tried using the v2.0.0.x-dev branch, to no avail; I'll try dev-master shortly to see if that makes a difference. Thanks for providing a link to the 1.4.2 documentation though, that makes a lot of sense. Will also try that.

skle commented 4 years ago

Try changing the version in composer.json from 1.4 to 'dev-master'. Run 'composer update' after that. That did the trick for me.

hajekj commented 4 years ago

Hi everyone, I am aiming to release the current master as v1.5 or v2.0 rather since it has breaking changes which you are experiencing right now. All I want to do there before the release is the cache of OIDC metadata calls.

sftgunner commented 4 years ago

Can confirm that using the dev-master branch fixed this issue. Many thanks to all