question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I refresh id token manually?

See original GitHub issue

I want to update the user attribute and get a new token with updated params. I need it updated since our server takes some params from it.

How can I refresh the token so it will contain updated params? Also, I’m not sure should this token be refreshed automatically after parameter update?

Found similar issue in the AWS SDK: https://github.com/aws-amplify/aws-sdk-android/issues/696. It has a SharedPreferences workaround. Not sure if it will work with Amplify? What exact prefs do I need to clear? Thanks.

Amplify Auth version: 1.4.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

10reactions
TrekSoftcommented, Dec 3, 2020

Sorry guys, you’re correct - that does not achieve what you’re looking for and I see this is still a pending feature request for AWSMobileClient which Amplify Auth is currently based on. You can add your +1s there as well to help get it prioritized and reopened this so others can add +1s to this.

9reactions
dobrowinscommented, Sep 13, 2021

To extend @chinalwb 's great answer, here’s the code that works in 1.18.0:

val client = AWSMobileClient.getInstance()

val userPoolField: Field? = client::class.java.getDeclaredField("userpool")
userPoolField?.isAccessible = true
val userPool = userPoolField?.get(client) as? CognitoUserPool
val currentUser = userPool?.currentUser as CognitoUser

val readCachedTokensFun = CognitoUser::class.java.getDeclaredMethod("readCachedTokens")
readCachedTokensFun.isAccessible = true
val cachedSession = readCachedTokensFun.invoke(currentUser) as? CognitoUserSession

// async call! perform on background thread or exception would occur
val refreshSessionFun = CognitoUser::class.java.getDeclaredMethod("refreshSession", CognitoUserSession::class.java)
refreshSessionFun.isAccessible = true
val refreshedSession = refreshSessionFun.invoke(currentUser, cachedSession) as? CognitoUserSession

val cacheTokensFun = CognitoUser::class.java.getDeclaredMethod("cacheTokens", CognitoUserSession::class.java)
cacheTokensFun.isAccessible = true
cacheTokensFun.invoke(currentUser, refreshedSession)

But please for the sake of anything you cherish use it as last resort.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Refresh the access and ID tokens | Okta Developer
This guide shows you how to refresh access and ID tokens by using either the Identity Engine SDK or the OIDC & OAuth...
Read more >
What Are Refresh Tokens and How to Use Them Securely
This post will explore the concept of refresh tokens as defined by OAuth 2.0. We will learn how they compare to other token...
Read more >
Using the refresh token - Amazon Cognito - AWS Documentation
If the refresh token is expired, your app user must re-authenticate by signing in again to your user pool. If the minimum for...
Read more >
Refresh Tokens — IdentityServer4 1.0.0 documentation
You can request a refresh token by adding a scope called offline_access to the scope parameter. Requesting an access token using a refresh...
Read more >
Microsoft identity platform refresh tokens
The refresh token is used to obtain new access/refresh token pairs when the current access token expires. Refresh tokens are also used to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found