Open Test18415 opened 6 days ago
Thank you for using kiota and for reaching out.
Can you share more about the error and the potential stack trace please?
The error happens when I try to run UserController.php,
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\View\View;
use GetUser\Client\GraphApiClient;
use Microsoft\Kiota\Abstractions\ApiException;
use Microsoft\Kiota\Authentication\Oauth\AuthorizationCodeContext;
use Microsoft\Kiota\Authentication\PhpLeagueAuthenticationProvider;
use Microsoft\Kiota\Http\GuzzleRequestAdapter;
class UserController extends Controller
{
/**
* Show the profile for a given user.
*/
public function show(string $id)
{
try {
//https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=<omitted for security reasons>&response_type=code&redirect_uri=http%3A%2F%2Flocalhost&response_mode=query&scope=User.Read
$clientId = '<omitted for security reasons>';
$clientSecret = '<omitted for security reasons>';
$authorizationCode = '1.AQIANSvYzHQftEG5ev5kr8mI8L5u_mKaF55DjAdXiDSLHRTcALsCAA.AgABBAIAAADW6jl31mB3T7ugrWTT8pFeAwDs_wUA9P9lfWe6VN2UXxQNItvlT8ak2O0o-29Rh6VCWyg65Z4zRwZMUaGkOLWEMWxSYVCJwO6sW9uag2o-O5e13oHWQcHVKlX1BOcJRqmTA2naGOkKuPWFnFB5fEMhOlc6f7lK1B0_Ri_vEykaoo2xpc4GohV336iWM4vmRROfwJYGjPIwFDVgBzY18zbcs1xExunRUN0yCHPAx1GnrfjYO_FNiCdDrvehJdTwXHscjHABCvzUTLEfO9P3tWA8Cwp30cLIXkm-8sFUxueqPhgRsGQgW0pY1judT9IxxB_Zp3WNZ3SxmnJdzSjCkURvIem7ZH-kdDXLCrZ8HoIBuXVTqZEOd1fZEB6PBIpvvJVeKc8d5s8vrnSXtXLYMrz4oVjKZP5CiGnvCjEMzHdG5TY-_-y7-DWDXfffxUqqgTQROucqsvzHm8n5wz9ctZW-7AiMFY0m-9XnCCv4hZyIl1rm2T72aQ8ezqYOsCY52SHh6JZb08sPua2hVwWWFcSRifFyaBRIqyKV3xI68QQlByb_XZT-GMGrzI0QeF5Zd4YITNOLjaOIOFGnGHCKFd34O9VeE9YyPtHmh23IV82phJTxZjqOZ1J_rqN2VWRdpeOXjW49R0cYVbqlAO7Zd0jxI0fOvxWxuIr7hGfZejfB2MUhOmCQt-OYhMX1jx86usrY6ZVDGgsM_XcrfRIk3kjBw_0BFSAzDPnQPSYeyKI1Zg';
$tenantId = 'common';
$redirectUri = 'http://localhost';
// The auth provider will only authorize requests to
// the allowed hosts, in this case Microsoft Graph
$allowedHosts = ['graph.microsoft.com'];
$scopes = ['User.Read'];
$tokenRequestContext = new AuthorizationCodeContext(
$tenantId,
$clientId,
$clientSecret,
$authorizationCode,
$redirectUri
);
$authProvider = new PhpLeagueAuthenticationProvider($tokenRequestContext, $scopes, $allowedHosts);
$requestAdapter = new GuzzleRequestAdapter($authProvider);
$client = new GraphApiClient($requestAdapter);
$me = $client->me()->get()->wait();
echo "Hello {$me->getDisplayName()}, your ID is {$me->getId()}";
} catch (ApiException $ex) {
echo $ex->getMessage();
}
}
}
[2024-11-19 15:33:52] local.ERROR: invalid_client {"exception":"[object] (League\OAuth2\Client\Provider\Exception\IdentityProviderException(code: 0): invalid_client at C:\xampp_82\htdocs\support.tool.api\vendor\league\oauth2-client\src\Provider\GenericProvider.php:236) [stacktrace]
@Ndiritu can you have a look when you have some time please?
I got more info,
Array ( [error] => invalid_client [error_description] => AADSTS700025: Client is public so neither 'client_assertion' nor 'client_secret' should be presented. Trace ID: 7db09244-1aed-4ab4-b961-e46d0e350e00 Correlation ID: ae0be87f-2716-4dd0-863e-71de12872f20 Timestamp: 2024-11-20 10:19:23Z [error_codes] => Array ( [0] => 700025 ) [timestamp] => 2024-11-20 10:19:23Z [trace_id] => 7db09244-1aed-4ab4-b961-e46d0e350e00 [correlation_id] => ae0be87f-2716-4dd0-863e-71de12872f20 )
Hi @Test18415, The error means that your registered app is a public client and such clients shouldn't be trusted with client secrets therefore you shouldn't be passing the client secret to such apps.
The sample provided assumes that a confidential client/application is registered. This happens when the Redirect URI
platform is set to Web
See more on public vs confidential clients
You can double-check your application configuration on the Azure portal under App Registrations > Your App > Authentication
Ensure you've configured your redirect URI under the web platform & check that you public client flows are disabled at the bottom of the page:
Feel free to let me know if you still face further issues.
I have followed https://learn.microsoft.com/en-us/openapi/kiota/tutorials/php-azure?tabs=portal but when I run the code I get invalid_client, is this normal behavior or did I make some mistake somewhere?