# PHP - get updated credentials, while user is logged in

**URL:** <https://community.auth0.com/t/php-get-updated-credentials-while-user-is-logged-in/115869>\
**Category:** Get Help\
**Tags:** rotating-refresh-tokens, sessions\
**Created:** [September 11, 2023, 1:03am UTC](https://community.auth0.com/t/php-get-updated-credentials-while-user-is-logged-in/115869 "2023-09-11T01:03:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![toomuchtimeondocs](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/toomuchtimeondocs/32/50714_2.png) [@toomuchtimeondocs](https://community.auth0.com/u/toomuchtimeondocs)\
**Post date:** [September 11, 2023, 1:03am UTC](https://community.auth0.com/t/php-get-updated-credentials-while-user-is-logged-in/115869/1 "2023-09-11T01:03:30Z")

</div>

I’m having uproblem with getting updated information in PHP-SDK  
Scenario:

1. User registers for account and is being logged into the app
2. In getCredentials response, I have email\_verified as false
3. Users verifies emails
4. I periodically issue renew() in PHP-SDK, to see if email\_verified is true and my action (performed on Login flow) added api.idToken.setCustomClaim(“custom\_date\_here”,(new Date)+‘’)  
I can see in the logs, that action is being performed correctly, without any issues, but getCredentials (after renew call) does not update email\_verified or custom\_date\_here, which is unexepected.  
**How to get updated data, without using management api in end user application server?**

After logging out and log in back, it works greate, but how to refresh this data without logging out?

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [September 11, 2023, 10:17am UTC](https://community.auth0.com/t/php-get-updated-credentials-while-user-is-logged-in/115869/3 "2023-09-11T10:17:01Z")

</div>

Hi @toomuchtimeondocs ,

AFAIK, the Actions are executed only when the user sign in and when a **new** refresh token is requested.

After reviewing the Auth0-php docs, the following got my attention -

- [renew()](https://auth0.github.io/auth0-PHP/classes/Auth0-SDK-Contract-Auth0Interface.html#method_renew) - it uses an **existing** refresh token to receive new id and access token

- [getCredentials()](https://auth0.github.io/auth0-PHP/classes/Auth0-SDK-Contract-Auth0Interface.html#method_getCredentials) - returns an object representing the current session credentials (including id token, access token, access token expiration, refresh token and user data) **without triggering an authorization flow**.

The above would explain why invoking these methods doesn’t trigger the Actions to execute.

* * *

[📹 _Want to join our next Community Interactive Q&A with our experts? This time we’re gonna talk about Auth0 Terraform Provider_](https://community.auth0.com/t/ask-me-anything-with-auth0-terraform-provider/115670)

---

<div class="post-metadata">

**Author:** ![toomuchtimeondocs](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/toomuchtimeondocs/32/50714_2.png) [@toomuchtimeondocs](https://community.auth0.com/u/toomuchtimeondocs)\
**Post date:** [September 11, 2023, 12:09pm UTC](https://community.auth0.com/t/php-get-updated-credentials-while-user-is-logged-in/115869/4 "2023-09-11T12:09:34Z")

</div>

@marcelina.barycka Thx for your response!

1. Unfortunately, I’m 100% positive, that calling renew() from PHP, triggers action to execute (I can see it being executed in Auth0 logs + I receive this event using stream)
2. I use api.idToken.setCustomClaim in action, to add my custom claim. AFAIK custom claim IS part of the token, so under definition ( it uses an **existing** refresh token to receive new id and access token) this data should be available.
3. Is there any way to get updated user data using authentication API?

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [September 13, 2023, 3:33pm UTC](https://community.auth0.com/t/php-get-updated-credentials-while-user-is-logged-in/115869/6 "2023-09-13T15:33:40Z")

</div>

> [@toomuchtimeondocs](#):
>
> Is there any way to get updated user data using authentication API?

Hi @toomuchtimeondocs ,

Based on my tests and the documentation for the t[he post-login Action](https://auth0.com/docs/manage-users/user-accounts/metadata/manage-user-metadata), unfortunately updating the user profile data occurs at the end of the action(s) within a flow. So if within a particular action you change a user metadata value from, for example, false to true AND you use this value (referencing an object) as a value for the custom claim, at first your claim will consists of the old value (false) and during another action run, it will take the updated value.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/b/b/bbe9709149a805655bf0d29b30279569954609f9.png)

An example:

```auto
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://myapp.example.com';
  const preffered_contact = event.user.email;
  api.user.setUserMetadata("new_metadata_key", preffered_contact);

  //the below metadata currently takes value "flase" and we update it to "true" at the end of this action (at the end of all actions in this flow)
  api.user.setUserMetadata("another_new_metadata_key", true);

    // Set claims 
    //the below claim will be addedd durig the first login as we do not refer to a user metadata value that has been updated now
    api.accessToken.setCustomClaim(`${namespace}/preferred_contact`, event.user.email);

    //the below claim will be updated with the new value starting from the second time the action will run as we refer to the usermetadata that is currently being updated
    api.accessToken.setCustomClaim(`${namespace}/another_new_metadata_key`, event.user.user_metadata.another_new_metadata_key);
  };

```

If you would like to check an example of updating user metadata via the Management API, here’s a good [topic](https://community.auth0.com/t/updating-user-profile-from-actions/85206/3) for that.

Please let me know if you would like to discuss it further. Thanks!

* * *

[📹 _Want to join our next Community Interactive Q&A with our experts? This time we’re gonna talk about Auth0 Terraform Provider_](https://community.auth0.com/t/ask-me-anything-with-auth0-terraform-provider/115670)

---

<div class="post-metadata">

**Author:** ![toomuchtimeondocs](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/toomuchtimeondocs/32/50714_2.png) [@toomuchtimeondocs](https://community.auth0.com/u/toomuchtimeondocs)\
**Post date:** [September 13, 2023, 11:07pm UTC](https://community.auth0.com/t/php-get-updated-credentials-while-user-is-logged-in/115869/7 "2023-09-13T23:07:23Z")

</div>

Thank you! I will do this via stream events, but to me it looks like a broken / not coded functionality for token renewal. But of course I’m novice to auth0, so I may be wrong.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [September 27, 2023, 11:08pm UTC](https://community.auth0.com/t/php-get-updated-credentials-while-user-is-logged-in/115869/8 "2023-09-27T23:08:11Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
