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

Add client options to the ProviderFactory::create #88

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions src/Oauth/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,41 @@ class ProviderFactory
* Initialises a PHP League provider for the Microsoft Identity platform
* @param TokenRequestContext $tokenRequestContext
* @param array<string, object> $collaborators
* @param string $tokenServiceBaseUrl Base URL for the token and authorize endpoint. Defaults to
* @param string|null $tokenServiceBaseUrl Base URL for the token and authorize endpoint. Defaults to
* https://login.microsoftonline.com
* @param string $userInfoServiceBaseUrl Base URL for the user info endpoint. Defaults to
* @param string|null $userInfoServiceBaseUrl Base URL for the user info endpoint. Defaults to
* https://graph.microsoft.com
* @param array<string, string> $clientOptions Additional client options to pass to the underlying http client.
* @return GenericProvider
*/
public static function create(
TokenRequestContext $tokenRequestContext,
array $collaborators = [],
string $tokenServiceBaseUrl = 'https://login.microsoftonline.com',
string $userInfoServiceBaseUrl = 'https://graph.microsoft.com'
?string $tokenServiceBaseUrl = null,
?string $userInfoServiceBaseUrl = null,
array $clientOptions = []
): GenericProvider
{
if ($tokenServiceBaseUrl === null || empty(trim($tokenServiceBaseUrl))) {
$tokenServiceBaseUrl = 'https://login.microsoftonline.com';
}
if ($userInfoServiceBaseUrl === null || empty(trim($userInfoServiceBaseUrl))) {
$userInfoServiceBaseUrl = 'https://graph.microsoft.com';
}

$grantFactory = new GrantFactory();
// Add our custom grant type to the registry
$grantFactory->setGrant('urn:ietf:params:Oauth:grant-type:jwt-bearer', new OnBehalfOfGrant());

return new GenericProvider([
'urlAccessToken' => "$tokenServiceBaseUrl/{$tokenRequestContext->getTenantId()}/oauth2/v2.0/token",
'urlAuthorize' => "$tokenServiceBaseUrl/{$tokenRequestContext->getTenantId()}/oauth2/v2.0/authorize",
'urlResourceOwnerDetails' => "$userInfoServiceBaseUrl/oidc/userinfo",
'accessTokenResourceOwnerId' => 'id_token'
], $collaborators + [
$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
]);
}
Expand Down