Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuthorizationUrl is not correct #73

Open
dbrmr opened this issue Feb 23, 2024 · 2 comments
Open

AuthorizationUrl is not correct #73

dbrmr opened this issue Feb 23, 2024 · 2 comments
Labels
type:bug A broken experience

Comments

@dbrmr
Copy link

dbrmr commented Feb 23, 2024

Hello,

I am trying to upgrade my application to use msgraph-sdk-php v2 and found this issue in this package.

$tokenRequestContext = new AuthorizationCodeContext(
    'tenantId', 'clientId', 'clientSecret', 'authCode', 'redirectUri');

$scopes = ['User.Read'];
$authProvider = new GraphPhpLeagueAuthenticationProvider($tokenRequestContext, $scopes);
$redirectUrl = $authProvider->getAccessTokenProvider()
    ->getOauthProvider()->getAuthorizationUrl();

The authorization url is not correct because of:

  1. AADSTS900144: The request body must contain the following parameter: 'client_id'.
  2. AADSTS900144: The request body must contain the following parameter: 'scope'.
  3. Also the redirectUri is missing, there is no specific error for this, but it is necessary.

The clientId and redirectId issues could be fixed in the ProviderFactory class when creating the GenericProvider.
The scopes issue could be fixed in the PhpLeagueAccessTokenProvider constructor and pass them to the ProviderFactory::create, and then to the GenericProvider.

The goal is to have the League\OAuth2\Client\Provider\GenericProvider class fully equipped, which might also require passing the clientSecret to it, but it is not necessary for getAuthorizationUrl().

I can imagine that this fix might not be as simple as I described, but if you could look into it, it would be greatly appreciated.

Thanks!

@tarkanaydin
Copy link

PhpLeagueAccessTokenProvider is missing to include $scopes in parameter list of ProviderFactory->create

$this->oauthProvider = $oauthProvider ?? ProviderFactory::create($tokenRequestContext);

Also, ProviderFactory->create method is missing to include neccesary data that $tokenRequestContext when creating GenericProvider as $clientOptions is empty

$allOptions = array_merge(
[
'urlAccessToken' => "$tokenServiceBaseUrl/{$tokenRequestContext->getTenantId()}/oauth2/v2.0/token",
'urlAuthorize' => "$tokenServiceBaseUrl/{$tokenRequestContext->getTenantId()}/oauth2/v2.0/authorize",
'urlResourceOwnerDetails' => "$userInfoServiceBaseUrl/oidc/userinfo",
'accessTokenResourceOwnerId' => 'id_token'
], $clientOptions
);
return new GenericProvider($allOptions, $collaborators + [
'grantFactory' => $grantFactory
]);

@dbrmr
Copy link
Author

dbrmr commented Aug 17, 2024

PhpLeagueAccessTokenProvider is missing to include $scopes in parameter list of ProviderFactory->create

$this->oauthProvider = $oauthProvider ?? ProviderFactory::create($tokenRequestContext);

Also, ProviderFactory->create method is missing to include neccesary data that $tokenRequestContext when creating GenericProvider as $clientOptions is empty

$allOptions = array_merge(
[
'urlAccessToken' => "$tokenServiceBaseUrl/{$tokenRequestContext->getTenantId()}/oauth2/v2.0/token",
'urlAuthorize' => "$tokenServiceBaseUrl/{$tokenRequestContext->getTenantId()}/oauth2/v2.0/authorize",
'urlResourceOwnerDetails' => "$userInfoServiceBaseUrl/oidc/userinfo",
'accessTokenResourceOwnerId' => 'id_token'
], $clientOptions
);
return new GenericProvider($allOptions, $collaborators + [
'grantFactory' => $grantFactory
]);

Thanks for your input.

I ended giving up on using the php sdk, and moved everything talking to the MS Graph to a .NET component.

@Ndiritu Ndiritu added this to Kiota Aug 19, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Aug 19, 2024
@Ndiritu Ndiritu moved this from Needs Triage 🔍 to Todo 📃 in Kiota Aug 19, 2024
@Ndiritu Ndiritu added the type:bug A broken experience label Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug A broken experience
Projects
Status: Todo 📃
Development

No branches or pull requests

3 participants