# Access Token for Social Connections - when are they refreshed?

**URL:** <https://community.auth0.com/t/access-token-for-social-connections-when-are-they-refreshed/6759>\
**Category:** Get Help\
**Tags:** refresh\_token, rules\
**Created:** [May 26, 2017, 10:26am UTC](https://community.auth0.com/t/access-token-for-social-connections-when-are-they-refreshed/6759 "2017-05-26T10:26:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacob.wang](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@jacob.wang](https://community.auth0.com/u/jacob.wang)\
**Post date:** [May 26, 2017, 10:26am UTC](https://community.auth0.com/t/access-token-for-social-connections-when-are-they-refreshed/6759/1 "2017-05-26T10:26:15Z")

</div>

I’m running into an issue where in my Auth0 Rules, the social connection access token I obtain through `user.identities[0].access_token` expired.

This seems to happen sporadically for a typical login from frontend SPA, and consistently for `/oauth/token` endpoint when I’m using a stored Auth0 refresh token to fetch a valid Access Token.

Here’s the scenario,

Social connection User use to login: Salesforce

Clients: “CompanySPA”

API: “CompanyAPI”

Our backend (CompanyAPI) stores the Auth0 refresh token of certain users (“API Users”) which we use to run background tasks that doesn’t follow the typical http request-response cycle.

In one of our Auth0 Rules, we use the access token of our social connection (Salesforce) to fetch some information from SF and then populate the JWT with some custom claims. This works mostly fine for SPA implicit grant flow, but for refresh\_token , this isn’t working.

By refresh token flow, I mean this:

```
POST http://company.auth0.com/oauth/token

{
  "grant_type": "refresh_token",
  "client_id": "(client id of CompanySPA)",
  "refresh_token": "(refresh token of the user)"
}

```

The webtask logs indicates that the rules are running, but Salesforce is rejecting the access token because it has expired. In our scenario the API User is not a real user, so it never logs in which means the access token won’t be refreshed.

To summarize, the problems:

1. If a user hasn’t logged in for a while, the social connection’s access token available through user.identities[0].access\_token is an expired one
2. Sometimes when a user logs in through SPA, `user.identities[0].access_token` may be expired.

Can Auth0 ensure that when a rule is run, the social connection’s access token is valid?

EDIT: I’m following the instructions in [Access Token for Social Connections - when are they refreshed? - Auth0 Community](http://community.auth0.com/questions/3189/access-token-for-social-connections-when-are-they) but the access token i get is expired.

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [June 2, 2017, 8:29pm UTC](https://community.auth0.com/t/access-token-for-social-connections-when-are-they-refreshed/6759/2 "2017-06-02T20:29:15Z")

</div>

The social connection access tokens are obtained as a by-product of user authentication at the social provider itself. As a consequence only a full user authentication at the social provider will lead to a new access token and certain flows like it’s the case of using an Auth0 refresh token won’t cause user authentication at the social provider.

* * *

For certain social providers in addition to the access token there will also be available a refresh token which would allow you implement your own refresh process; however, this is not available for Salesforce.

See [Identity Provider Access Tokens - Renewing the token](https://auth0.com/docs/tokens/idp#renewing-the-token) section for reference information on this subject.

---

<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:** [March 2, 2018, 5:54am UTC](https://community.auth0.com/t/access-token-for-social-connections-when-are-they-refreshed/6759/3 "2018-03-02T05:54:08Z")

</div>


