Expo Module for native Spotify SDK
npm install @wwdrew/expo-spotify-sdkAn Expo Module for the native iOS and Android Spotify SDK
- Authentication
More to come...
``sh`
npx expo install @wwdrew/expo-spotify-sdk
Include the expo-spotify-sdk plugin in your app.json/app.config.js file with its required configuration:
`javascript`
...
"plugins": [
["@wwdrew/expo-spotify-sdk", {
"clientID": "
"scheme": "expo-spotify-sdk-example",
"host": "authenticate"
}]
],
...
Required:
- clientID: <string> the Spotify Client ID for your applicationscheme
- : <string> the URL scheme to link into your app as part of the redirect URIhost
- : <string> the path of the redirect URI
`typescript
isAvailable(): boolean
``
Determines if the Spotify app is installed on the target device.
---
`typescript`
authenticateAsync(config: SpotifyConfig): Promise
Starts the authentication process. Requires an array of OAuth scopes. If the Spotify app is installed on the target device it will interact directly with it, otherwise it will open a web view to authenticate with the Spotify website.
Note for Android: If not providing a token swap or refresh URL, the Spotify session response access token will expire after 60 minutes and will not include a refresh token. This is due to a limitation in the Android Spotify SDK. It's recommended to implement a token swap endpoint for this reason.
- tokenSwapURL (optional): <string> The URL to use for attempting to swap an authorization code for an access tokentokenRefreshURL
- (optional): <string> The URL to use for attempting to renew an access token with a refresh tokenscopes
- : An array of OAuth scopes that declare how your app wants to access a user's account. See Spotify Scopes for more information.
Note: The following scopes are not available to Expo Spotify SDK:
- user-read-playback-position
- user-soa-link
- user-soa-unlink
- user-manage-entitlements
- user-manage-partner
- user-create-partner
`typescript
interface SpotifyConfig {
scopes: SpotifyScope[];
tokenSwapURL?: string;
tokenRefreshURL?: string;
}
interface SpotifySession {
accessToken: string;
refreshToken: string | null;
expirationDate: number;
scopes: SpotifyScopes[];
}
type SpotifyScopes =
| "ugc-image-upload"
| "user-read-playback-state"
| "user-modify-playback-state"
| "user-read-currently-playing"
| "app-remote-control"
| "streaming"
| "playlist-read-private"
| "playlist-read-collaborative"
| "playlist-modify-private"
| "playlist-modify-public"
| "user-follow-modify"
| "user-follow-read"
| "user-top-read"
| "user-read-recently-played"
| "user-library-modify"
| "user-library-read"
| "user-read-email"
| "user-read-private";
`
An example token swap endpoint has been provided in the example project. For it to work it needs your Spotify client details to be included.
1. Open the server.js file and add your client details:
`javascript`
const CLIENT_ID = "
const CLIENT_SECRET = "
These values can be found in your Spotify Developer Dashboard. You will need an existing Spotify app for this.
2. Run the server
`sh`
node server.js
3. Set the tokenSwapURL value in your authenticateAsync call:
`javascript``
const session = await authenticateAsync({
tokenSwapURL: "http://192.168.1.120:3000/swap",
scopes: [
...
]
});
All authentication requests will now be sent through the token swap server.
This project has been heavily inspired by the following projects:
* react-native-spotify-remote
* expo-spotify
Contributions are welcome!
MIT