ImplicitGrantAuth loses authentication after a while
See original GitHub issueI 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:
- Created 5 years ago
- Comments:13 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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.
Please have a look at the methods provided by those objects before asking, VS should help you out in a lot of times:
https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/df53f75368717e9b071fe9f97ad8becfcc73a5ee/SpotifyAPI/Web/Auth/AutorizationCodeAuth.cs#L45
https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/df53f75368717e9b071fe9f97ad8becfcc73a5ee/SpotifyAPI/Web/Models/Token.cs#L20