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.

ImplicitGrantAuth loses authentication after a while

See original GitHub issue

I wrote a programm which uses both, web and local api. I just need the webapi to get fulltrack information and got the authentication process to work with ImplicitGrantAuth. After a while though, it won’t work anymore. It seems like the auth expires.

Is there a way to extend the auth? I read on the Spotify API-Doc that there is something called “refresh_token” but I’m not sure if its documented in your library or if it’s even possible to refresh the authentication.

This is the code which connects when a button is clicked.

private async void SpotifyWebConnect()
        {
            WriteConsole("Trying to connect so Spotify", null);
            WebAPIFactory webApiFactory = new WebAPIFactory(
                   "http://localhost",
                   8000,
                   "XXXXXXXXXXXXXXXXXXXXX",
                   Scope.None,
                   TimeSpan.FromSeconds(20)
            );

            try
            {
                _spotifyWeb = await webApiFactory.GetWebApi();
            }
            catch (Exception ex)
            {
                WriteConsole(ex.Message, ex);
            }
            if (_spotify == null)
                return;
        }

and after a while

FullTrack fulltrack = null;
fulltrack = _spotifyWeb.GetTrack(SPOTIFY_URI);

always returns null.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
jscholescommented, Jul 22, 2018

I do this every 20 minutes but after 3600 secs when token expires, API doesn’t respond anymore.

There’s no need to refresh your token every 20 minutes when they last for 60. Either refresh it once the API tells you the token has expired, or set up some sort of timer to refresh the token just before that (say at 55-59 minutes). Then ensure that you’re updating the access token which is actually being sent to the API. It’s not enough to simply refresh the token, you need to actually make sure your API requests are being sent by updating the access token which is being used by your SpotifyWebAPI instance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Refreshing token in Oauth2 Implicit Grant Flow and 3rd ...
The client authentication step by providing client secret and authorization code is missing. · The access token is sent back as a URL...
Read more >
OAuth2 Implicit Grant and SPA
The original OAuth2 specification introduces the implicit grant in SPAs as the way JavaScript code can obtain access tokens and call APIs ...
Read more >
What is the OAuth 2.0 Implicit Grant Type?
The Implicit Grant Type is a way for a single-page JavaScript app to get an access token without an intermediate code exchange step....
Read more >
Is the OAuth 2.0 Implicit Flow Dead?
The primary reason the Implicit flow was created was because of an old limitation in browsers.
Read more >
Refreshing Access Tokens when using the Implicit Flow
This means that if their access token expires, they should still be around to authorize another to be issued. We're not expecting the...
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