TheNetworg / oauth2-azure

Azure AD provider for the OAuth 2.0 Client.
https://packagist.org/packages/thenetworg/oauth2-azure
MIT License
230 stars 108 forks source link

Problems with URL parameter #137

Open RaminMohazzab opened 3 years ago

RaminMohazzab commented 3 years ago

Hello! First of all: I am a physics teacher, so please don't expect too much from me. I want to query the contacts from the school's Office365. When I test the query in Microsoft Graphexplorer, everything works fine:

https://graph.microsoft.com/v1.0/users?$search="displayName:Mohazza"

but when I do the query with php, the options are ignored:

$str = 'users?$search="displayName:Mohazzab"'; <= No effect. $response = $provider->get($str, $accessToken);

Can anybode help, please? Thx Ramin

hajekj commented 3 years ago

Hey, no worries, all questions are welcome!

Can you please try calling Graph with full URL of the endpoint and see if that works?

$provider->get('https://graph.microsoft.com/v1.0/users?$search="displayName:Mohazzab"', $token);

/cc: @RaminMohazzab

RaminMohazzab commented 3 years ago

Hey! Thank you for your answer. I tried this - i get this message:

Fatal error: Uncaught Error: Call to a member function hasExpired() on null in /var/www/web991/html/wordpress/elternsprechtag/vendor/thenetworg/oauth2-azure/src/Provider/Azure.php:204 Stack trace: #0 /var/www/web991/html/wordpress/elternsprechtag/vendor/thenetworg/oauth2-azure/src/Provider/Azure.php(169): TheNetworg\OAuth2\Client\Provider\Azure->request('get', 'https://graph.m...', NULL, Array) #1 /var/www/web991/html/wordpress/elternsprechtag/oauth.php(38): TheNetworg\OAuth2\Client\Provider\Azure->get('https://graph.m...', NULL) #2 {main} thrown in /var/www/web991/html/wordpress/elternsprechtag/vendor/thenetworg/oauth2-azure/src/Provider/Azure.php on line 204

Do i have to use another endpoint? Thanks!

hajekj commented 3 years ago

Hm, hasExpired is being called on $token, have you properly authenticated and obtained the token? I could do a quick Teams call to check it with you today (I am in GMT+1, Prague, Czech Republic timezone), so if we could get it aligned, would be probably quicker via a screen share. I am free between 15:00 - 16:30 today.

RaminMohazzab commented 3 years ago

hey, this would be great! My Email: ramin.mohazzab@gympet.net

RaminMohazzab commented 3 years ago

maybe it is a problem with the header - the key "ConsistencyLevel" is needed. Is this correct?

    $headers = [
        'ConsistencyLevel' => 'eventual',
    ];

$str = 'users?$search="displayName:Moh"';
$response = $provider->get($str, $accessToken, ['headers' => $headers]);
hajekj commented 3 years ago

Yeah, consistency level is required as per docs: https://docs.microsoft.com/en-us/graph/api/user-list?view=graph-rest-1.0&tabs=http