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

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

Open
kingma-sbw opened this issue Aug 9, 2023 · 8 comments

Comments

@kingma-sbw
Copy link

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.

@decomplexity
Copy link

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

@kingma-sbw
Copy link
Author

ehm. AUD token? where ist that set?

@decomplexity
Copy link

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:

@kingma-sbw
Copy link
Author

kingma-sbw commented Aug 11, 2023

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.

@decomplexity
Copy link

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.

@kingma-sbw
Copy link
Author

kingma-sbw commented Sep 7, 2023

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/",

@decomplexity
Copy link

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

@kingma-sbw
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants