Closed chud37 closed 4 years ago
Have you included the autoload file generated by Composer?
Eg.
require_once '../vendor/autoload.php';
@hajekj yes, that is why I can run the $provider->...$credentials line okay.
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!
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?
@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?
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
@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?
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.
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:
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.
(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?