Coder Social home page Coder Social logo

wiyarmir / react-native-spotify-auth Goto Github PK

View Code? Open in Web Editor NEW
20.0 2.0 0.0 166 KB

Bridge between your React Native app and the Spotify Auth SDK

License: Apache License 2.0

Java 72.55% JavaScript 12.79% Objective-C 5.16% Ruby 9.49%
react-native spotify spotify-sdk spotify-authentication

react-native-spotify-auth's Introduction

react-native-spotify-auth

Objectives

To have a unified library that allows to do Spotify authentication through their native SDK, both in iOS and Android.

Prerequisites

Important! This library requires you to have registered your apps properly in the Spotify developers dashboard, including Bundle Id/Package Name and SHA1 signature.

Installing

$ yarn add wiyarmir/react-native-spotify-auth
$ react-native link react-native-spotify-auth

Unfortunately, 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.

Android

There are two options for this.

Option 1

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"
         }
     }
}

Option 2

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

iOS

WIP

Usage

API

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,
};

Example

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);
    }
  );

Roadmap

v0.9.0

  • Android auth flow

v1.0.0

  • iOS auth flow

react-native-spotify-auth's People

Contributors

wiyarmir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-native-spotify-auth's Issues

Error during authorisation

I am trying to make the example work but the data return Error: Error during authorisation., any suggests?

startLogin() doesn't open the login page

Hi,

I only meet this problem today, after months of testing.

On the simulator I never had problems, but today I'm testing on a real device some new things on my app and the first attempt to login on Spotify fail (I don't know why but the login page has opened).

When I restarted the app and I tried to login again, the login page never appears and return immediately "Error during authorization".

I don't know how to 'reset' to show again the login page...

Transitive dependencies are not carried over

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
   > Could not find any matches for com.spotify.sdk:spotify-auth:+ as no versions of com.spotify.sdk:spotify-auth are available.
     Searched in the following locations:
         file:/Users/guillermoruiz/stuff/Morrison/android/app/libs/
     Required by:
         Morrison:app:unspecified > Morrison:react-native-spotify-auth:unspecified

then function is not working

Hi.

I didnt take token from plugin. When ı add native toast in native code. I can see token. But I didnt get token on react view.

Not working then function. Please help me.

Thanks.

let auth = new SpotifyAuth("token", "test://callback");
.
.
.
.
.
auth
.startLogin()
.then(function (data) {
// not working here
}, function (error) {
// alert(error);
});

Cannot read property 'launchAuth' of undefined

Hi,

I test this library with ios emulator, but when I do login with auth.startLogin(), this error appears in console:

Cannot read property 'launchAuth' of undefined

In the instructions for iOS appears WIP, I supposed that I don't configure nothing in the iOS Folder.

I check the node_modules/react-native-spotify-auth/index.js this const RNSpotifyAuth is undefined

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.