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

feat: custom http client #16

Merged
merged 1 commit into from
Feb 27, 2023
Merged

Conversation

adrienbrault
Copy link
Contributor

While microsoft/microsoft-graph 2.0-RC13 allows using a custom guzzle client, the OAuth authentication does not.

In order to use a custom client this is what's currently required:

$accessToken = $this->getAccessTokenUsingMyGuzzleClient();

$authenticationProvider = new BaseBearerTokenAuthenticationProvider(
    new class($accessToken) implements AccessTokenProvider {
        public function __construct(private AccessTokenInterface $accessToken)
        {
        }

        public function getAuthorizationTokenAsync(string $url): Promise
        {
            return new FulfilledPromise($this->accessToken);
        }

        public function getAllowedHostsValidator(): AllowedHostsValidator
        {
            return new AllowedHostsValidator([]);
        }
    }
);

return new GraphServiceClient(
    new GraphRequestAdapter(
        $authenticationProvider,
        $this->guzzleClient
    )
);

This patch should make it simpler:

$authenticationProvider = new BaseBearerTokenAuthenticationProvider(
    new PhpLeagueAccessTokenProvider(
        $this->tokenRequestContext,
        [],
        [],
        ProviderFactory::create(
            $this->tokenRequestContext,
            [
                'httpClient' => $this->guzzleClient,
            ]
        )
    )
);

return new GraphServiceClient(
    new GraphRequestAdapter(
        $authenticationProvider,
        $this->guzzleClient
    )
);

@Ndiritu
Copy link
Contributor

Ndiritu commented Feb 23, 2023

Also @baywet how should we approach custom HTTP clients for authentication? Should we support passing down a custom HTTP client from the request adapter into the auth layer?

Please lmk if creating an issue on the main Kiota repo would be better for this discussion

@baywet
Copy link
Member

baywet commented Feb 23, 2023

Also @baywet how should we approach custom HTTP clients for authentication? Should we support passing down a custom HTTP client from the request adapter into the auth layer?

Please lmk if creating an issue on the main Kiota repo would be better for this discussion

Let's wait to see if there's any demand for that before we start putting the work.

@baywet
Copy link
Member

baywet commented Feb 23, 2023

@adrienbrault ça fait plaisir de croiser un ancien SUPINFO :)

src/PhpLeagueAccessTokenProvider.php Outdated Show resolved Hide resolved
src/PhpLeagueAccessTokenProvider.php Outdated Show resolved Hide resolved
src/Oauth/ProviderFactory.php Show resolved Hide resolved
src/Oauth/ProviderFactory.php Outdated Show resolved Hide resolved
@adrienbrault
Copy link
Contributor Author

@baywet 👋 :-)

@Ndiritu
Copy link
Contributor

Ndiritu commented Feb 24, 2023

@baywet unable to confirm if the SONAR_TOKEN secret is missing from this repo's settings. Kindly assist

@Ndiritu Ndiritu merged commit a0b1512 into microsoft:dev Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants