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.

[Question] How to access refresh token

See original GitHub issue

Hi I need to keep refresh token in the database to sync up with client’s inbox. I couldn’t find any legal way to retrieve a refresh token from the IAuthenticationResult. I think up with temporal dirty workaround using reflection:

try {
            //see com.microsoft.aad.msal4j.AuthenticationResult#refreshToken
            final Field refreshTokenField = credentials.getClass()
                .getDeclaredField("refreshToken");
            refreshTokenField.setAccessible(true);
            return refreshTokenField.get(credentials).toString();
        } catch (IllegalAccessException | NoSuchFieldException e) {
            throw new RuntimeException(e);
        }

Is there better anyway to retrieve a refresh token? Serialize TokenCache doesn’t look much better for me.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sangonzalcommented, May 4, 2020

@sleshJdev Does ‘acquireTokenSilently’ work for your scenario? MSAL doesn’t expose the refresh token but instead takes care of refreshing the access token for you. When you acquire a token with any of the APIs, MSAL will store the refresh token in an in-memory cache, which you can save to disk. AcquireTokenSilently() will first look into the cache, see if you have a valid access token, and if not then will try to refresh the refresh token.

0reactions
navyasriccommented, May 12, 2020

Closing this issue as the question has been answered above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Question about access token and refresh token in google API
Currently, I am using OAuth 2.0 to access Google APIs. I got access token and refresh token, used the access token to connect...
Read more >
JSON Web Tokens | Access and Refresh Tokens - YouTube
Discussing JWT's with @Joseph Branch, @James Q Quick and @Colby Fayock "How to Store JWT for Authentication" by @Ben Awad - I'd strongly ......
Read more >
OAuth Access & refresh token questions - API and Webhooks
Yes, if a user logins in on a different device, the OAuth flow basically restarts, invalidating the current OAuth access and refresh tokens...
Read more >
Retrieve an Access Token and Refresh Token
Using Refresh Tokens ... Access tokens will expire after a set time period (normally returned in the expires_in parameter). When you obtain an...
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