GithubHelp home page GithubHelp logo

spotify / spotifylogin Goto Github PK

View Code? Open in Web Editor NEW
346.0 31.0 43.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 marmelroyspotify avatar nataliq avatar oxve avatar tomaculum avatar

Stargazers

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

Watchers

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

spotifylogin's Issues

Unable to access "SpotifyLogin.shared.session"

I integrate SpotifyLogin Swift4 framework by pod into my project and I import "SpotifyLogin" framework into my local class.

Then I am trying to access the session by "SpotifyLogin.shared.session" , but I am receiving error "'session' is inaccessible due to 'internal' protection level" .

May I know why this is happening ?

Can you please provide a solution.

Thanks in Advance.

SpotifyLoginSuccessful notification gets called even when you login from SnapSDK

I have snapchat and spotify social logins implements inside my app and the SpotifyLoginSuccessful notification is called after coming back to app from snapchat login. On debugging i found applicationOpenURL inside SpotifyLogin.swift is posting that notification. For now i have setup a check if url does not contain snap-kit only then the rest of the function will be called otherwise returned false. Please fix this issue, thank you the library nonetheless it is working great!

Snap library link - https://github.com/Snapchat/login-kit-sample/tree/master/ios/Pods/SnapSDK

Get a session

Is there a way that the SpotifyLogin pod can work with the SPTAuthentication class from the iOS SDK. Specifically I am curious about setting the session in SPTAuthentication from Spotify Login.

Example project crashing because of missing resources

Description

When trying to run the example project, it crashes.

self.setImage(UIImage(named: "spotifylogo-32.png",
                              in: Bundle(for: SpotifyLoginButton.self),
                              compatibleWith: nil)!

This line returns nil for me.

Versions

Xcode 9 Beta 6 on macOS Sierra with latest
available version of iOS in the simulator

Severity

Major, since the only example usage of SpotifyLogin does not work.

Steps to Reproduce

  1. Download repository
  2. Run pod install inside the example project folder to install dependencies from CocoaPods
  3. Build and run example project

Actual behaviour

The line described above returns nil, hence the application crashes.

Verify Premium User

We have some properties like SPTUser and SPTProduct.premium to verify User premium account for Swift 2 Spotify Login framework.

But, I am unable to find the way to verify the User is premium or not for Swift 4 SpotifyLogin framework.

Please provide the solution for this asap.

Thanks in Advance.

How renew Spotify session

Hi,
I am implementing your library in my app and I have a little problem.
When my application is launched I'll want to restore my stored session then check if it's valid and renew it if necessary. I want also renew my access_token when i launch my application in a new device but I want to avoid interaction by the user. Then i would like store the refresh_token in my online DB.
But i can't access to the refresh token and I can't find a function to refresh my access_token with a refresh_token.
Do you have an idea of how to do it with your library ?
Thanks

canHandleURL on URLBuilder

checking prefix on this function does not account for possibility of url having upper case characters. quick fix is
let redirectURLString = redirectURL.absoluteString.lowercased()

The operation couldn’t be completed. (OSStatus error -10814.)

If you are filing a bug report, please include information for the topics below. Also, please make sure to only report one bug/feature request/question per issue.

Description

I am getting The operation couldn’t be completed. (OSStatus error -10814.) upon trying to login. I suspect the setup around URI is wrong. It fails with web browser and iOS app.

Versions

iOS SDK version: 0.1.6
Spotify app version (if native SSO flow is involved): 8.5.66.762

Severity

Trivial

Steps to Reproduce

  1. Add URI to Spotify dev dashboard myappmedia:// and myappmedia://callback
  2. Setup the URI Types in Xcode project with URL Schemes: myappmedia
  3. Add the following code to AppDelegate.swift:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        SpotifyLogin.shared.configure(clientID: "aaa123", clientSecret: "bbb123", redirectURL: URL(string: "myappmedia://callback")! ) 
        return true
    }

, where "aaa123" and "bbb123" are real clientID and clientSecret respectively.

  1. Build and run, try to sign in with Facebook login
  2. Web page with the scope of permissions is presented
  3. Press AGREE

Actual behaviour

Get The operation couldn’t be completed. (OSStatus error -10814.) error after pressing Sign In button, and them after pressing AGREE nothing happens.

Expected behaviour

Successful sign in

Logs

2020-07-21 23:11:59.790846-0700 MyApp-iOS[70870:5832280] -canOpenURL: failed for URL: "spotify-action://authorize?utm_campaign=spotifylogin&show_dialog=true&nosignup=true&utm_medium=spotifylogin&scope=playlist-read-private%20playlist-read-collaborative%20playlist-modify-public%20playlist-modify-private&redirect_uri=myappmedia%3A%2F%2Fcallback&response_type=code&client_id= aaa123&nolinks=true&utm_source=spotify-sdk" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"

Can't authorize with Spotify app

Thanks guys for this awesome library! I'm not sure if this is a bug or I just didn't set up the app right, however I followed all instructions in the readme.

Description

When the Spotify app is installed, SpotifyLogin does not obtain a valid session after redirecting from the Spotify app.

Versions

iOS 11.1
Spotify 8.4.28

Severity

Minor

Steps to Reproduce

  1. User taps login button (provided by SpotifyLogin)

Actual behaviour

Spotify app opens, popup says "...Authorizing" and then a check mark. Redirects back to app, however an active session is not present.

Expected behaviour

Should create an active session with an auth token after redirecting

Change BPM value of Spotify Song Swift

I am trying to build an application that plays Spotify songs. I am really confused about how to change BPM(Beats Per Minute,) value of Spotify songs.
First Step: Login through Spotify.
Second Step: Get Current user all album.
Third Step: get album track.
Last Step: play track.
I have done All step with Spotify Delegates. but I want to change the BPM value of the track.
Can someone please explain to me how to change the BPM value?

error returned in URL for AppDelegate callback

If you are filing a bug report, please include information for the topics below. Also, please make sure to only report one bug/feature request/question per issue.

Description

A concise description of what the problem is.

Versions

iOS SDK version
Spotify app version (if native SSO flow is involved)

Severity

Trivial, Minor, Major, Catastrophic

Steps to Reproduce

  1. Step by step instructions on how to reproduce this bug.
  2. The more detailed your list of instructions, the easier it is for the developer to track down the problem!

Actual behaviour

Describe what happens when you perform the steps above.

Expected behaviour

Describe what you expected to happen when performing the steps above.

Logs

Please include any relevant log output that might assist in tracking down the problem.

when running the Sample test, for the following AppDelegate callback:

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

I receive the following for the url content:

loginsample://?error=invalid_app_identifier&error_description=The%20app%20identifier%20is%20not%20valid%20with%20the%20client%20ID%20provided

This appears to be flagging an error regarding incorrect app id, though I have checked and rechecked and this is the ID as specified on the developer portal.

Is this an issue? The Sample app ignores the contents returned in the url

thanks.

I am using the most recent Xcode Version 10.1 (10B61)

Sample Project not working for me

I downloaded the sample project and added in my redirectURL, client id and client secret. Added the correct URL type in the info tab. The app launches, I press the login button, it takes me to Spotify and I authorize it successfully and then takes me back to the login screen and nothing else happens. The loginSuccessful() method is never called. Please help

Allow show_dialog to be false

If you are filing a bug report, please include information for the topics below. Also, please make sure to only report one bug/feature request/question per issue.

Description

show_dialog is hardcoded to true. It should be able to be set by the developer.

Versions

1.0.6

Severity

Minor

SpotifyLogin does not work in iOS 12

If you are filing a bug report, please include information for the topics below. Also, please make sure to only report one bug/feature request/question per issue.

Description

A concise description of what the problem is.
Using the correct values for Client ID, Client Secret, Redirect URL, and following the tutorial exactly, the error "Safari cannot open the page because the address is invalid" is thrown on iOS 12.

Versions

iOS SDK version: iOS 12 (-sdk iphoneos12.0)
Spotify app version (if native SSO flow is involved)

Severity

Trivial, Minor, Major, Catastrophic

Major

Steps to Reproduce

  1. Step by step instructions on how to reproduce this bug.
    Install iOS 12 developer beta 6, complete the sample included in the repo. During login at the "cancel" or "okay" screen, both buttons cause "Safari cannot open the page because the address is invalid."
  2. The more detailed your list of instructions, the easier it is for the developer to track down the problem!

Actual behaviour

Describe what happens when you perform the steps above.
Safari closes and app is logged in

Expected behaviour

Describe what you expected to happen when performing the steps above.
Error: "Safari cannot open the page because the address is invalid."

Logs

Please include any relevant log output that might assist in tracking down the problem.
No logs

Best way of UITesting App with SpotifyLogin

I am in the process of writing UI tests for my application that uses SpotifyLogin. Do you have an recommendations on how to handle authenticating? XCUI does not like webviews at all and crashes whenever they are interacted with.

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.