SpotifyAPI-NET icon indicating copy to clipboard operation
SpotifyAPI-NET copied to clipboard

How do I refresh the token with the AutorizationCodeAuth and why is it not safe?

Open Gruhlum opened this issue 9 years ago • 1 comments

Hi, I am making a desktop app and would like to know a good way to refresh the access token. Right now I run the auth method every hour, but this causes the browers to pop up which can be rather annoying.

Could someone give me an example on how to refresh the token? I tried auth.RefreshToken(spotify.AccessToken, "myClientSecret"); which does not work.

And to my second question, the example code says "NEVER DO THIS! You would need to provide the ClientSecret. You would need to do it e.g via a PHP-Script." Does this apply for desktop apps aswell? How could someone get a hold of my ClientSecret and how do I protect it? Would it still be a problem if I am the only one using the program?

Gruhlum avatar Jan 16 '17 01:01 Gruhlum

Hi @Gruhlum ,

Sorry for the late response. You will need to use the token.RefreshToken token instead of the actual access code. You get this refresh token when you exchange with auth.ExchangeAuthCode(response.Code, "XXXXXXXXXXX");.

If you're the only one using it, it's no problem. As soon as you send your program to other people, they can decompile it and view your client-secret. And with this client-secret they can make calls to the API through your account, you wouldn't want that, do you? 😛

JohnnyCrazy avatar Jan 31 '17 16:01 JohnnyCrazy