To have a unified library that allows to do Spotify authentication through their native SDK, both in iOS and Android.
Important! This library requires you to have registered your apps properly in the Spotify developers dashboard, including Bundle Id/Package Name and SHA1 signature.
$ yarn add wiyarmir/react-native-spotify-auth
$ react-native link react-native-spotify-authUnfortunately, transitive AAR dependencies are not bundled. Since Spotify SDK is not published in Maven or pods, you need to manually include spotify lib from your project.
There are two options for this.
In your android/build.gradle file add the following:
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
+ flatDir {
+ dirs "$rootDir/../node_modules/react-native-spotify-auth/android/libs"
+ }
flatDir {
dirs "libs"
}
}
}Add the Spotify auth .aar file to the android/libs/ directory of your project. Current used version is 1.0.0-beta13 and can be found in their GitHub repo
WIP
The default export provides you with a class and flowtype annotations.
Method startLogin() returns a Promise that will resolve with a SpotifyAuthData type.
type SpotifyAuthData = {
token: string,
code: string,
error: string,
state: string,
expiresIn: number,
};import SpotifyAuth from 'react-native-spotify-auth';
let auth = new SpotifyAuth(Constants.SPOTIFY_CLIENT_ID, Constants.SPOTIFY_REDIRECT_URI);
auth.startLogin()
.then(
function(data) {
console.log(data.token);
},
function(error){
console.warn(error);
}
);- Android auth flow
- iOS auth flow