Git Product home page Git Product logo

omniauth-lastfm's Introduction

OmniAuth Last.fm

Last.fm strategy for OmniAuth 1.0.

Installing

Add to your Gemfile:

gem 'omniauth'
gem 'omniauth-lastfm'

Then bundle install.

Usage

You'll need an API account with Last.fm, you can get one here - http://www.last.fm/api.

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

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :lastfm, "consumer_key", "consumer_secret"
end

Now simply follow the README at: https://github.com/intridea/omniauth.

Auth Hash Schema

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

{
   "provider": "lastfm",
   "uid": "ripuk",
   "info": {
      "nickname": "ripuk",
      "name": "David Stephens",
      "url": "http://www.last.fm/user/ripuk",
      "image": "http://userserve-ak.last.fm/serve/252/46787679.jpg",
      "country": "UK",
      "age": "31",
      "gender": "m"
   },
   "credentials": {
      "token": "abcdefghijklmnop",
      "name": "ripuk"
   },
   "extra": {
      "raw_info": {
         "name": "ripuk",
         "realname": "David Stephens",
         "image": [
            {
               "#text": "http://userserve-ak.last.fm/serve/34/46787679.jpg",
               "size": "small"
            },
            {
               "#text": "http://userserve-ak.last.fm/serve/64/46787679.jpg",
               "size": "medium"
            },
            {
               "#text": "http://userserve-ak.last.fm/serve/126/46787679.jpg",
               "size": "large"
            },
            {
               "#text": "http://userserve-ak.last.fm/serve/252/46787679.jpg",
               "size": "extralarge"
            }
         ],
         "url": "http://www.last.fm/user/ripuk",
         "id": "25400308",
         "country": "UK",
         "age": "31",
         "gender": "m",
         "subscriber": "0",
         "playcount": "11530",
         "playlists": "0",
         "bootstrap": "0",
         "registered": {
            "#text": "2009-12-30 00:53",
            "unixtime": "1262134389"
         },
         "type": "user"
      }
   }
}

What Next?

The Rockstar Gem is a great way to make use of the auth token retrieved with this gem.

omniauth-lastfm's People

Contributors

masterkain avatar davestephens avatar arekk avatar krasnoukhov avatar rdsoze avatar

Stargazers

R. Kit Seal avatar Vasiliy Yorkin avatar Mathias Gawlista avatar Iheanyi Ekechukwu avatar Chris Wren avatar Reiji Kainuma avatar Nick Gooding avatar Niels Hoffmann avatar  avatar  avatar  avatar Jim Harvey avatar  avatar

Watchers

 avatar Valerio Chiodino avatar James Cloos avatar okihika avatar  avatar

omniauth-lastfm's Issues

Missing readme

Could you please create a README with instructions on how to use this gem to send requests to the LastFM REST API?

I have successfully authorized the user but how do I access their API?

Error on invalid tokens

In the callback_phase, when the token provided in the request is invalid, the decoded response we get from Last.fm looks as follows:

session = {"error"=>4, "message"=>"Invalid authentication token supplied.", "links"=>[]}

Something similar is returned when the api_key or the signature are invalid:

{"error"=>10, "message"=>"Invalid API key - You must be granted a valid key by last.fm", "links"=>[]}
{"error"=>13, "message"=>"Invalid method signature supplied", "links"=>[]}

Then, when trying to retrieve the user info, we try to access @json['session']['name'] to provide the user parameter, and this crashes with NoMethodError: undefined method '[]' for nil:NilClass.

Maybe this kind of errors should be handled in a different way.

Explicitly specify the callback url

I'd like to be able to specify the callback URL within the authorization url as a query string parameter (i.e. [auth-url]?cb=http://localhost:3000/etc/etc) to override the one specified to last.fm when creating the API application. I couldn't see any option in the docs to do this - I had a look over the source and got some of the way there, but couldn't quite figure out the necessary syntax to get this to work.

Any ideas?

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.