Skip to content

Commit

Permalink
🔀 Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoLegends committed Jan 21, 2017
2 parents adfbc5f + 3875ad2 commit 443a987
Show file tree
Hide file tree
Showing 37 changed files with 1,573 additions and 24 deletions.
92 changes: 92 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Node template
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# SpotifySDK
src/ios/spotify-sdk/
src/android/spotify-auth/
src/android/spotify-sdk/

# Serverless
.serverless/

# env config
.env

# Android
.gradle/

# Webpack
www/build/
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Festify

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Cordova Spotify SDK Plugin (Beta)

An [Apache Cordova](https://cordova.apache.org/) plugin providing a thin wrapper over the Spotify SDK for iOS and Android.

## Features

This plugin provides a very thin layer over the authentication and playback functionality of the Spotify SDK. It allows your users to authenticate using OAuth 2.0 and allows you to play Spotify tracks via their URI. Metadata functionality has deliberately been left out in favor of the [Web API](https://developer.spotify.com/web-api/). After your users have been authenticated, you are given the access token, so accessing the Web API is trivial.

## Stability

This plugin is currently in beta. This means its reasonably stable but hasn't seen much production use yet. This plugin will be used in the new [Festify](https://github.com/Festify/app), so it will be production-ready once Festify is released. We will fix bugs as soon as we find them.

## Contributing

Pull requests are very welcome! Please use the [gitmoji](https://gitmoji.carloscuesta.me/) style for commit messages.

## Installation

```bash
git clone https://github.com/Festify/cordova-spotify
cd ./MyCordovaProject
cordova plugin add ../cordova-spotify
```

An npm-based installation as well as API documentation will be provided at a later stage when the stability has improved.

Note: Make sure your installation path doesn't contain any spaces.

## OAuth Code Grant Flow

The Spotify SDK needs some server code because you don't want to login your users repeatedly every hour: [Documentation](https://developer.spotify.com/technologies/spotify-ios-sdk/token-swap-refresh/)

To implement the endpoints for `tokenSwapURL` and `tokenRefreshURL` we built a [Serverless](https://serverless.com) service that you can deploy to AWS Lambda. Make sure you [install the Serverless Framework properly](https://serverless.com/framework/docs/providers/aws/guide/installation/)!

For the execution of the functions to work you need to set some environmental configuration in the file `oauth-token-api/.env`

```bash
CLIENT_ID="<Your Spotify Client ID>"
CLIENT_SECRET="<Your Spotify Client Secret>"
CLIENT_CALLBACK_URL="<The callback url of your app>" # e.g. "festify-spotify://callback"
ENCRYPTION_SECRET="<Secret used to encrypt the refresh token - please generate>"
```

You can then deploy the functions to AWS:

```bash
cd oauth-token-api
serverless deploy
```
11 changes: 11 additions & 0 deletions build-extras.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
}

packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
29 changes: 29 additions & 0 deletions install-android.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

AUTH_INSTALL_PATH="plugins/rocks.festify.cordova-spotify/src/android/spotify-auth"
AUTH_DOWNLOAD_PATH="https://github.com/spotify/android-auth/archive/1.0.tar.gz"
SDK_INSTALL_PATH="plugins/rocks.festify.cordova-spotify/src/android/spotify-sdk"
SDK_DOWNLOAD_PATH="https://github.com/spotify/android-sdk/archive/24-noconnect-2.20b.tar.gz"

if [ ! -d "$AUTH_INSTALL_PATH" ]; then
mkdir -p "$AUTH_INSTALL_PATH"
curl -LsS $AUTH_DOWNLOAD_PATH | tar -xz -C "$AUTH_INSTALL_PATH" --strip 1
else
echo "Skipping auth library download since it's already there."
fi

if [ ! -d "$SDK_INSTALL_PATH" ]; then
mkdir -p "$SDK_INSTALL_PATH"
curl -LsS $SDK_DOWNLOAD_PATH | tar -xz -C "$SDK_INSTALL_PATH" --strip 1
else
echo "Skipping streaming SDK download since it's alredy there."
fi

cd $(dirname $0)/src/android/spotify-auth
echo "include ':auth-lib'" > settings.gradle

if [ ! -f "auth-lib/build/outputs/aar/spotify-android-auth-1.0.0.aar" ]; then
./gradlew clean build
else
echo "Skipping auth library build since the AAR is already there."
fi
9 changes: 9 additions & 0 deletions install-ios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

INSTALL_PATH="plugins/rocks.festify.cordova-spotify/src/ios/spotify-sdk"
DOWNLOAD_PATH="https://github.com/spotify/ios-sdk/archive/beta-25.tar.gz"

if [ ! -d $INSTALL_PATH ]; then
mkdir -p $INSTALL_PATH
curl -LsS $DOWNLOAD_PATH | tar -xzv -C $INSTALL_PATH --strip 1
fi
6 changes: 6 additions & 0 deletions oauth-token-api/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# package directories
node_modules
jspm_packages

# Serverless directories
.serverless
15 changes: 15 additions & 0 deletions oauth-token-api/lib/crypto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

const crypto = require('crypto');

const algo = 'aes-256-cbc';

module.exports.encrypt = (text, key) => {
const cipher = crypto.createCipher(algo, key);
return cipher.update(text, 'utf8', 'hex') + cipher.final('hex');
};

module.exports.decrypt = (text, key) => {
const decipher = crypto.createDecipher(algo, key);
return decipher.update(text, 'hex', 'utf8') + decipher.final('utf8');
};
28 changes: 28 additions & 0 deletions oauth-token-api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "spotify-oauth-token-api",
"version": "1.0.0",
"description": "The AWS lambda service that is responsible for dealing with OAuth token refresh and exchange.",
"repository": {
"type": "git",
"url": "git+https://github.com/Festify/cordova-spotify.git"
},
"keywords": [
"cordova",
"spotify",
"token",
"exchange",
"oauth"
],
"author": "Festify Dev Team <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/Festify/cordova-spotify/issues"
},
"homepage": "https://github.com/Festify/cordova-spotify#readme",
"dependencies": {
"dotenv": "^2.0.0",
"es6-promise": "^4.0.5",
"qs": "^6.3.0",
"request": "^2.79.0"
}
}
28 changes: 28 additions & 0 deletions oauth-token-api/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---

service: oauth-token-api

provider:
name: aws
runtime: nodejs4.3
region: eu-central-1
profile: festify
memorySize: 128

package:
include:
- lib/**

functions:
exchangeCode:
handler: spotifyTokenService.exchangeCode
events:
- http:
path: exchange
method: post
refreshToken:
handler: spotifyTokenService.refreshToken
events:
- http:
path: refresh
method: post
Loading

0 comments on commit 443a987

Please sign in to comment.