GithubHelp home page GithubHelp logo

isabella232 / spotifylogin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from spotify/spotifylogin

0.0 0.0 0.0 150 KB

Swift framework for authenticating with the Spotify API

License: Apache License 2.0

Swift 89.03% Ruby 4.07% Objective-C 2.33% Shell 4.57%

spotifylogin's Introduction

SpotifyLogin - Swift 5 Framework for authenticating with the Spotify API

Build Status Version Carthage compatible

SpotifyLogin

SpotifyLogin is a Swift 5 Framework for authenticating with the Spotify API.

Usage of this framework is bound under the Developer Terms of Use.

Usage

Disclaimer

SpotifyLogin is appropriate for prototyping and non-commercial use only.

If your app is meant for commercial production usage, SpotifyLogin can NOT be used.

Compatibility

SpotifyLogin requires Xcode 10.2+. It is compatible with iOS 9 or later.

Pre-requisites

You will need to register your app in the Developer Portal.

Make sure to use a unique redirect url and to supply the bundle ID from your app.

After registering, you will receive a client ID and a client secret.

Set up SpotifyLogin

Set up SpotifyLogin using any of the methods detailed below (Cocoapods / Carthage / manually).

Set up info.plist

In Xcode, go to your app's target and select the Info tab. At the bottom, of the screen you will find URL Types, expand the list and create a new one.

Set up info.plist

Add the app's identifer as the Identifier and the redirect url scheme in URL schemes.

Additionally, you will need to add "spotify-action" to the LSApplicationQueriesSchemes key: LSApplicationQueriesSchemes

Set up your AppDelegate

Add the following to your app delegate:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    SpotifyLogin.shared.configure(clientID: <#T##String#>, clientSecret: <#T##String#>, redirectURL: <#T##URL#>)
    return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    let handled = SpotifyLogin.shared.applicationOpenURL(url) { (error) in }
    return handled
}

Check if a user is logged in.

You can retrieve an access token and check if a user is logged in by:

SpotifyLogin.shared.getAccessToken { (accessToken, error) in
    if error != nil {
        // User is not logged in, show log in flow.
    }
}

This also automatically takes care of renewing expired tokens.

Log in / Log out

To add the default log in button:

let button = SpotifyLoginButton(viewController: self, scopes: [.streaming, .userLibraryRead])
self.view.addSubview(button)

The scopes define the set of permissions your app will be able to use. For more information about available scopes, see Scopes Documentation

To log out:

SpotifyLogin.shared.logout()

Update UI after successful log in.

The log in flow is completed in applicationOpenURL. To respond to a successful log in, you can add your own code in the completion handler or respond to the SpotifyLoginSuccessful notification:

NotificationCenter.default.addObserver(self, selector: #selector(loginSuccessful), name: .SpotifyLoginSuccessful, object: nil)

Additional features

Access the current user's username:

let username = SpotifyLogin.shared.username

To trigger the log in flow from a custom action:

SpotifyLoginPresenter.login(from: self, scopes: [.streaming, .userLibraryRead])

Setting up

Setting up with CocoaPods

source 'https://github.com/CocoaPods/Specs.git'
pod 'SpotifyLogin', '~> 0.1'

Setting up with Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate SpotifyLogin into your Xcode project using Carthage, specify it in your Cartfile:

github "spotify/SpotifyLogin"

Code of conduct

This project adheres to the Open Code of Conduct. By contributing, you are expected to honor this code.

Additional information

Spotify Developer Portal | API Reference

spotifylogin's People

Contributors

afruitpie avatar broich avatar hughrawlinson avatar jeanherfs avatar joelevin avatar juliofruta avatar marmelroy avatar nataliq avatar oxve avatar tomaculum avatar

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.