Git Product home page Git Product logo

omniauth-spotify's Introduction

Spotify OmniAuth Strategy

This gem provides a simple way to authenticate to Spotify Web API using OmniAuth with OAuth2.

Installation

Add this line to your application's Gemfile:

gem 'omniauth-spotify'

And then execute:

$ bundle

Or install it yourself as:

$ gem install omniauth-spotify

Usage

You'll need to register an app on Spotify, you can do this here - https://developer.spotify.com/my-applications/#!/

Usage of the gem is very similar to other OmniAuth strategies. You'll need to add your app credentials to config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :spotify, 'app_id', 'app_secret', scope: 'playlist-read-private user-read-private user-read-email'
end

Please replace the example scope provided with your own. Read more about scopes here: https://developer.spotify.com/web-api/using-scopes/

Or with Devise in config/initializers/devise.rb:

config.omniauth :spotify, 'app_id', 'app_secret', scope: 'playlist-read-private user-read-private user-read-email'

Auth Hash Schema

Here's an example auth hash, available in request.env['omniauth.auth']:

Some of this fields depend on what scopes you ask, namely

  • user-read-email affects the presence of the email field
  • user-read-private affects the value of name (if the scope is missing it will reflect username) and the presence of image
{
  :provider => "spotify",
  :uid => "1111111111",
  :info => {
    :name => "Claudio Poli",
    :nickname => 'SomeName',
    :email => "[email protected]",
    :urls => {:spotify => "https://open.spotify.com/user/1111111111"},
    :image => 'https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/t1.0-1/s320x320/301234_1962753760624_625151598_n.jpg'

  },
  :credentials => {
    :token => "xxxx",
    :refresh_token => "xxxx",
    :expires_at => 1403021232,
    :expires => true
  },
  :extra => {
    :raw_info => {
      :country => "IT",
      :display_name => "Claudio Poli",
      :email => "[email protected]",
      :external_urls => {
        :spotify => "https://open.spotify.com/user/1111111111"
      },
      :href => "https://api.spotify.com/v1/users/1111111111",
      :id => "1111111111",
      :images => [
        {
          "height" => nil,
          "url" => "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/t1.0-1/s320x320/301234_1962753760624_625151598_n.jpg",
          "width" => nil
        }
      ],
      :product => "open",
      :type => "user",
      :uri => "spotify:user:1111111111"
    }
  }
}

More

This gem is brought to you by the AudioBox guys. Enjoy!

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

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.