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

Uncaught Error: Class 'Azure' not found #108

Closed chud37 closed 4 years ago

chud37 commented 4 years ago

(I'm new to all of this, so forgive me if I'm being dumb)

I've installed the oauth2-azure using composer: composer require thenetworg/oauth2-azure And that all went in fine.

I can run this code fine: $provider = new TheNetworg\OAuth2\Client\Provider\Azure($credentials);

However this next line: $provider->defaultEndPointVersion = Azure::ENDPOINT_VERSION_2_0;

Gives me the error: Uncaught Error: Class 'Azure' not found

Also the next line, if I use it: $baseGraphUri = $provider->getRootMicrosoftGraphUri(null);

Gives me the following error: Uncaught Error: Call to undefined method TheNetworg\OAuth2\Client\Provider\Azure::getRootMicrosoftGraphUri()

I dont understand why I'm missing things that surely should have been installed when I ran the composer require line at the top?

Any ideas why I don't have this class? Or where I can get the correct one from to install using Composer?

hajekj commented 4 years ago

Have you included the autoload file generated by Composer?

Eg.

require_once '../vendor/autoload.php';
chud37 commented 4 years ago

@hajekj yes, that is why I can run the $provider->...$credentials line okay.

chud37 commented 4 years ago

I've moved the code into a single file at the root of the domain, to rule out any conflict issues. The script (with keys and secrets removed) is:

require_once(__DIR__."/vendor/autoload.php");

$tenantID = "";

$credentials = [
  'clientId'                => "",
  'clientSecret'            => "",
  'redirectUri'             => "",
  'urlAuthorize'            => "https://login.microsoftonline.com/{$tenantID}/oauth2/v2.0/authorize",
  'urlAccessToken'          => "https://login.microsoftonline.com/{$tenantID}/oauth2/v2.0/token",
  'urlResourceOwnerDetails' => 'https://graph.microsoft.com/v1.0/me',
  'scopes'                  => 'openid profile offline_access user.read calendars.read'
];

  $provider = new TheNetworg\OAuth2\Client\Provider\Azure([
      'clientId'          => $credentials['clientId'],
      'clientSecret'      => $credentials['clientSecret'],
      'redirectUri'       => $credentials['redirectUri'],
  ]);

  $provider->defaultEndPointVersion = Azure::ENDPOINT_VERSION_2_0;

  $baseGraphUri = $provider->getRootMicrosoftGraphUri(null);
  $provider->scope = 'openid profile email offline_access ' . $baseGraphUri . '/User.Read';

Which produces the Azure error: Fatal error: Uncaught Error: Class 'Azure' not found for the Azure::ENDPOINT line.

@hajekj Please help!

chud37 commented 4 years ago

Just to clarify, my composer.json looks like this:

{
    "require-dev": {
        "symfony/var-dumper": "^4.2"
    },
    "require": {
        "thenetworg/oauth2-azure": "^1.4",
        "league/oauth2-client": "^2.4"
    }
}

@hajekj Am i missing any critical components here?

chud37 commented 4 years ago

@hajekj It would appear that the file Azure.php in \Provider does not have that consant, yet on Github it clearly does. As far as I can see Composer is using version 1.4.2 - Does that help at all?

hajekj commented 4 years ago

Oh, that's it. The current documentation on web reflects master version from Compsoer. If you want to use 1.4.2, please refer to: https://github.com/TheNetworg/oauth2-azure/tree/v1.4.2 for docs. master had some breaking changes, so it will be likely released as v2

chud37 commented 4 years ago

@hajekj I dont understand, 1.4.2 is the version that Composer automatically assigned to me. I'm fine with using the latest version, just so long as it works.

Why is the documentation for the master when composer automatically chooses v1.4.2?

hajekj commented 4 years ago

Composer gives you the latest stable version, eg. 1.4.2. master branch contains bits and pieces which are not ready for production yet. I posted a link to the state of release for 1.4.2 where you can find the appropriate docs.

mbrouwer88nl commented 4 years ago

Hi @hajekj , if I still want to use this "new" version (dev-master) instead of 1.4.2... How to make composer use that version?

I tried this composer.json: { "require": { "components/jquery": "~3.4.1", "league/oauth2-client": "^2.0", "microsoft/microsoft-graph": "^1.0", "guzzlehttp/guzzle": "~6.0", "thenetworg/oauth2-azure": "dev-master" }, "minimum-stability": "dev", "prefer-stable": true }

Composer returns: _c:\inetpub\site6>composer install

Deprecated: Directive 'track_errors' is deprecated in Unknown on line 0 Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 14 installs, 0 updates, 0 removals

But still running my script returns: _PHP Fatal error: Uncaught Error: Class 'Azure' not found in C:\inetpub\site6\public\index.php:13 Stack trace:

0 {main}

thrown in C:\inetpub\site6\public\index.php on line 13_

What am I doing wrong? Hash c5d6b2c seems to be the new library that it's loading.