TheNetworg/oauth2-azure

Exception "The client_id / audience is invalid!" when using accesstoken

kingma-sbw opened this issue · 8 comments

I get an exception when using a token.

This is how I save the token after succesfull logon:

$token = $provider->getAccessToken( 'authorization_code', [ 
    'code' => $_GET[ 'code' ],
] );
$_SESSION['accessToken'] = $token->getToken() );

This is how I use the stored access token (for debugging I use the token in the session:

$accessToken = $_SESSION['accessToken'];

try {
    $claims = $provider->validateAccessToken($accessToken);
	var_dump($claims);
} catch (Exception $e) {
    var_dump($e);
}

I've checked the token and it is the value created.

What please is the value of AUD in the token claims?

ehm. AUD token? where ist that set?

Ah. I assumed that your "I've checked the token and it is the value created" meant that you had decoded the access token.
You can easily check the client id. But to check the audience:

I see thanks, I could see the content. But how is the validateAccessToken supposed to work? I assumed in an API call I can do a quick test to check it the the session is (still) valid.

Since the error message is saying that either or both of the client ID (which you input) and AUD (which you didn't) are bad, could you please reply with the AUD value - it is not sensitive.
If the token had timed out - they have a very short life of perhaps an hour, or the key signature was bad - I would hope that the error message would say so.

If I decode the result of getToken and base64_decode it I get something proper but also some garbage at the end

�$@RD_�BZC^�Pv~9P`�8BZq�yt]�^�D)>ϧEꮉ�T<`,_#ⴅ3�uoR,?or�wIjB@d�X� )RtPtI_C=/Ae-j��$t�m.�\.7�j`D:nsʽ�p��垝�M[�&d%�LbȈ
>	���w�p!y�J�S�KPs\7j$� 

And json_encode cannot use it.

but the AUD is "https://graph.windows.net/",

I cannot tell what the garbage is, but if you are using Graph as the resource provider, the AUD should be https://graph.microsoft.com.
If instead you are using a non-Microsoft package such as PHPMailer to send SMTP mail, the AUD must be https://outlook.office.com/ or authentication will fail; this AUD is forced using a Scope operand

Thanks. but what I see we don't need the results from getToken, only the getResourceOwner data which we will store in a PHP session variable.