Open donghee214 opened 4 years ago
hey @donghee214 , I haven't had a chance to look at getting the refresh token stuff set up. I've added this is an enhancement. Thanks
Not too comfortable with native development so unsure if renewSession()
would involve some work on that end for proper implementation, but just made a basic helper method to serve as a renewSession()
if anyone else needs it.
private async renewSession(refresh_token: string){
const response = await fetch(`${SPOTIFY_SERVER}/refresh`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
refresh_token
})
})
const json = await response.json()
this.setState((state) => ({
...state,
token: json.access_token
}))
}
}
This was added to the context Component in example/AppContext.ts
, and you can just pass this as a prop like the other methods to access it throughout your child components
cool! Hopefully something can get incorporated into this package soon for this.
Hey @donghee214 & @cjam just trying to understand the gaps are for refreshing the access token.
Looking at the iOS doc (https://spotify.github.io/ios-sdk/html/Classes/SPTConfiguration.html && https://developer.spotify.com/documentation/ios/guides/token-swap-and-refresh/) it seems like it supports tokenSwap & tokenRefresh, the sdk would call your server urls when it needs a fresh accessToken.
As for Android reference, https://spotify.github.io/android-sdk/auth-lib/docs/, it doesn't mention tokenSwap & tokenRefresh, so I'm assuming Android SDK doesn't support refresh.
Question for @cjam , I see this bit of code here: https://github.com/cjam/react-native-spotify-remote/blob/c0a81d7fb4dae4686b713268aa51471188729562/android/src/main/java/com/reactlibrary/RNSpotifyRemoteAuthModule.java#L45 . Have you tried putting in redirect/refresh url values using the method setCustomParam()
from https://spotify.github.io/android-sdk/auth-lib/docs/ from AuthenticationRequest.Builder?
Question for @donghee214 on this post:
Not too comfortable with native development so unsure if
renewSession()
would involve some work on that end for proper implementation, but just made a basic helper method to serve as arenewSession()
if anyone else needs it.private async renewSession(refresh_token: string){ const response = await fetch(`${SPOTIFY_SERVER}/refresh`, { method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ refresh_token }) }) const json = await response.json() this.setState((state) => ({ ...state, token: json.access_token })) } }
This was added to the context Component in
example/AppContext.ts
, and you can just pass this as a prop like the other methods to access it throughout your child components
For your Android side impl, how did you get the refresh_token? since refresh_token is not returned from SpotifyAuth.authorize() or SpotifyAuth.initialize()?
@MrBuggySan Interesting thought on the setCustomParam
, their docs are pretty slim on that method. Any ideas on what it does?
Just linking this issue with #67 and #68 as they seem to be related.
@cjam never mind about using the setCustomParams() it seems like getting the refresh token to work with Spotify Android SDK is still in suggestion phase: https://github.com/spotify/android-sdk/issues/255 We'll just have to refresh the session manually on our own via the POST /refresh of this repo's sample server
@MrBuggySan
We'll just have to refresh the session manually on our own via the POST /refresh of this repo's sample server
That is what we did; Worked well.
It would be great to show put an example of this into the example app. @reinhardholl @MrBuggySan do you guys have a simple bit of code that I could add to the example app and then point to from the docs? It seems to be a common question/need. I haven't had the chance to get this setup in my apps but it's definitely on my road map.
@cjam might be an idea to suggest using a general OAuth lib to authorize / refresh? I'm using: https://github.com/FormidableLabs/react-native-app-auth which also features a Spotify example: https://github.com/FormidableLabs/react-native-app-auth/blob/main/docs/config-examples/spotify.md
I'm using: https://github.com/FormidableLabs/react-native-app-auth which also features a Spotify example: https://github.com/FormidableLabs/react-native-app-auth/blob/main/docs/config-examples/spotify.md
Hi @dylancom Were you able to get this to work well? Did you encounter issues with iOS backgrounding the Spotify app so that reconnecting to it is difficult? Thanks.
Is this left up for our own implementation at the moment or supposed to be renewed with the getSession method? Just curious if I was setting up the server incorrectly or not.
Thank you