How to get >24h refresh tokens for mobile app with Azure B2C?

Stefan Schweiger 1 Reputation point
2022-08-01T07:04:15.043+00:00

We are currently looking into creating a mobile app with react native (expo). The whole authentication stuff works now after a bit of tinkering. But whats a problem for us is that apparently you are not able to get refresh tokens which are valid for longer than 24h when you use the code flow with PKCE.

As far as I've gathered from online resources it's recommended to use PKCE for mobile apps for security reasons. But having the user login do a complete login after 24h is kind of a show stopper for us.

What other options are there to use refresh tokens which are valid for more than 24h in a secure way for mobile apps?

Microsoft Security | Microsoft Entra | Microsoft Entra External ID
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Shyamal Parikh 5 Reputation points
    2023-04-21T08:59:27.4533333+00:00

    Developers should have an ability to extend the refresh_token lifetime on browser for atleast a week. Current time of 24 hours is very short

    1 person found this answer helpful.
    0 comments No comments

  2. Shweta Mathur 30,296 Reputation points Microsoft Employee Moderator
    2022-08-02T08:40:57.793+00:00

    Hi @Stefan Schweiger ,

    Thanks for reaching out.

    Your understanding is correct here. Unfortunately, as of now for Single Page Applications, the token is valid only for 24 hours. After 24 hours you need to go to /authorization endpoint of azure ad to get the new access and refresh token. This can also be also non-interactive flow if the browser has the valid login session.

    Another way is to use the implicit flow where refresh token happens in hidden iframe, but implicit flow is not recommended as going further 3rd party cookies will be blocked.

    The only workaround option available is to use "Keep me signed in" to get long lived sessions. In order to set the KMSI checkbox checked by default, you need to use JavaScript as there is no option available for this purpose in B2C user flow or custom policy.

    Thanks,
    Shweta

    -----------------------------

    Please remember to "Accept Answer" if answer helped you.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.