Skip to content

Using package in laravel #1683

Open
Open

Description

Please help me, i'm confused
I have project using laravel and laravel socialite, i got access_token from laravel socialite. How to use that access_token in this package?

I use this method

$tokenRequestContext = new OnBehalfOfContext(
  config("services.microsoft.tenant"),
  config("services.microsoft.client_id"),
  config("services.microsoft.client_secret"),
  session()->get("microsoft_access_token"),
);

$graphServiceClient = new GraphServiceClient($tokenRequestContext);
$user = $graphServiceClient->me()->get()->wait();
dd($user);

why the process is very long, and the result is invalid grant? I have checked that all parameters (tenant id, client id, etc) are valid

Image

Activity

  1. edikurniawan-dev commented on May 21, 2025

    @edikurniawan-dev
    Author

    why this package doesn't implement it easily like microsoft graph postman collection, i can even input manual access token in postman header and call api directly

  2. Spawnrad commented on May 28, 2025

    @Spawnrad

    with symfony i use this code if it can help you

        $tokenRequestContext = new ClientCredentialContext(
            $this->tenantId,
            $this->clientId,
            $this->clientSecret,
        );
    
        $accessToken = new AccessToken([
            'access_token' => $oauthUser->getAccessToken(),
            'refresh_token' => $oauthUser->getRefreshToken(),
        ]);
    
        $scopes = ['User.Read', 'Mail.ReadWrite', 'Mail.Send'];
    
        $inMemoryCache = new InMemoryAccessTokenCache($tokenRequestContext, $accessToken);
    
        $graphServiceClient = GraphServiceClient::createWithAuthenticationProvider(
            GraphPhpLeagueAuthenticationProvider::createWithAccessTokenProvider(
                GraphPhpLeagueAccessTokenProvider::createWithCache(
                    $inMemoryCache,
                    $tokenRequestContext,
                    $scopes
                )
            )
        );
    
  3. edikurniawan-dev commented on May 30, 2025

    @edikurniawan-dev
    Author

    thanks for the suggestion, i will try it later.
    i followed this solution and it worked 1472

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions