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

Logging example would be useful #1560

Open
ianef opened this issue Jul 23, 2024 · 0 comments
Open

Logging example would be useful #1560

ianef opened this issue Jul 23, 2024 · 0 comments
Labels
documentation type:question An issue that's a question

Comments

@ianef
Copy link

ianef commented Jul 23, 2024

I can't find any practical examples of how to apply logging to graph requests. When things don't work as expected it's really handy to be able to see what you are actually sending and receiving from the API.

I've tried the following but it crashes trying to create the client:

        $this->tokenRequestContext = new AuthorizationCodeContext(
            $this->config['tenant_id'],
            $this->config['app_id'],
            $this->config['client_secret_value'],
            'NOT_AUTHENTICATED', // Auth code dummy value
            $this->urlGenerator->generate('ms365_login_callback', [], UrlGeneratorInterface::ABSOLUTE_URL),
        );

        $tokenCache = new UserAccessTokenCache($this->tokenRequestContext); // Custom cache
        // Create the default handler stack
        $handlerStack = GraphClientFactory::getDefaultHandlerStack();

        // Add the log handler
        $handlerStack->push(Middleware::log(
            $this->logger,
            new \GuzzleHttp\MessageFormatter('{req_headers} - {req_body} - {res_headers} - {res_body}')
        ));

        $adapter = new GraphRequestAdapter(
            GraphPhpLeagueAuthenticationProvider::createWithAccessTokenProvider(
                GraphPhpLeagueAccessTokenProvider::createWithCache(
                    $tokenCache,
                    $this->tokenRequestContext,
                    self::AZURE_SCOPES
                )
            ),
            GraphClientFactory::createWithMiddleware($handlerStack)
        );

        $this->graphServiceClient = GraphServiceClient::createWithRequestAdapter($adapter);

Any help with this would be very handy.

@Ndiritu Ndiritu added documentation type:question An issue that's a question labels Aug 8, 2024
@rkodev rkodev removed their assignment Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation type:question An issue that's a question
Projects
None yet
Development

No branches or pull requests

3 participants