This repository has been archived by the owner on Apr 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Omniauth Strategy for Napster oAuth (#1)
* Omniauth Strategy for Napster oAuth This strategy can be verified by installing the gem and using the [OmniAuth Test Harness](https://github.com/PracticallyGreen/omniauth-test-harness) This gem has NOT been pushed to RubyGems yet. We need to wait for the rename. * fix circular reference in requires * Bundle install will work on clean build Change homepage to reference the new home at github.com/Napster * Override only `token_url` Updated rspec to reflect that we're not overriding defaults for `authorize_url`
- Loading branch information
Richard Luck
authored
Jul 12, 2016
1 parent
dd264a4
commit 057cb98
Showing
12 changed files
with
208 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.gem | ||
.bundle | ||
.config | ||
Gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--format documentation | ||
--color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
source 'https://rubygems.org' | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,100 @@ | ||
# omniauth-napster | ||
Omniauth Strategy for Napster Music | ||
<!-- | ||
[![Gem Version](https://badge.fury.io/rb/omniauth-napster.svg)](https://badge.fury.io/rb/omniauth-napster) | ||
--> | ||
|
||
# Napster Music OmniAuth Strategy | ||
|
||
This gem provides the [OmniAuth](https://github.com/intridea/omniauth) strategy for the [Napster API](https://developer.napster.com). | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
```$ gem 'omniauth-napster'``` | ||
|
||
And then execute: | ||
|
||
```$ bundle``` | ||
|
||
Or install it yourself as: | ||
|
||
```$ gem install omniauth-napster``` | ||
|
||
## Usage | ||
|
||
You'll need to register your app with Napster. Visit https://developer.napster.com/developer/apps/new to get started. | ||
|
||
Using this gem is similar to other OmniAuth strategies. Add your app credentials to `config/initializers/omniauth.rb`: | ||
|
||
```ruby | ||
Rails.application.config.middleware.use OmniAuth::Builder do | ||
provider :napster, ENV['NAPSTER_API_KEY'], ENV['NAPSTER_API_SECRET'] | ||
end | ||
``` | ||
|
||
Or with Devise in `config/initializers/devise.rb`: | ||
|
||
```ruby | ||
config.omniauth :napster, ENV['NAPSTER_API_KEY'], ENV['NAPSTER_API_SECRET'] | ||
``` | ||
|
||
## Auth Hash Schema | ||
|
||
Here's an example auth hash, available in `request.env['omniauth.auth']`: | ||
``` | ||
{ | ||
"provider":"napster", | ||
"uid":"295DC739BEDA4BB8E050960A380358BC", | ||
"info": { | ||
"uid":"295DC739BEDA4BB8E050960A380358BC", | ||
"name":"Testy Testerson", | ||
"username":"NAPIcat", | ||
"image":"http://direct.rhapsody.com/imageserver/v2/external/aHR0cHM6Ly9yaGFwc29keS1uYXBpLnMzLmFtYXpvbmF3cy5jb20vbWVtYmVyLzI5NURDNzM5QkVEQTRCQjhFMDUwOTYwQTM4MDM1OEJDL2F2YXRhci9vcmlnaW5hbA%3D%3D/images/108x108.jpg" | ||
}, | ||
"credentials": { | ||
"token":"NTQ3NjI5NDktNWIyZC00MDVlLTg2MDMtZDhhMGQ2YTYzMTk3", | ||
"refresh_token":"0b4bdad8-1c82-44d0-8cdb-dd8d2b6e6331", | ||
"expires_at":1463103543, | ||
"expires":true | ||
}, | ||
"extra": { | ||
"raw_info": { | ||
"me": { | ||
"id": "295DC739BEDA4BB8E050960A380358BC", | ||
"realName": "Testy Testerson", | ||
"screenName": "NAPIcat", | ||
"bio": "The cat is back!", | ||
"location":"Seattle, WA", | ||
"visibility": "public", | ||
"type": "member", | ||
"href": "http://api.rhapsody.com/members/295DC739BEDA4BB8E050960A380358BC", | ||
"favoriteAlbumsCount": 0, | ||
"favoriteArtistsCount": 0, | ||
"favoriteTracksCount": 0, | ||
"playlistsTotalCount": 0, | ||
"playlistsPublishedCount": 0, | ||
"stationsCount": 0, | ||
"radioCount": 0, | ||
"followingCount": 2, | ||
"followerCount": 10, | ||
"avatar": "http://direct.rhapsody.com/imageserver/v2/external/aHR0cHM6Ly9yaGFwc29keS1uYXBpLnMzLmFtYXpvbmF3cy5jb20vbWVtYmVyLzI5NURDNzM5QkVEQTRCQjhFMDUwOTYwQTM4MDM1OEJDL2F2YXRhci9vcmlnaW5hbA%3D%3D/images/108x108.jpg", | ||
"avatarId": "aHR0cHM6Ly9yaGFwc29keS1uYXBpLnMzLmFtYXpvbmF3cy5jb20vbWVtYmVyLzI5NURDNzM5QkVEQTRCQjhFMDUwOTYwQTM4MDM1OEJDL2F2YXRhci9vcmlnaW5hbA%3D%3D", | ||
"defaultAvatar": "false", | ||
"avatarVersion": 1465508896140 | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## More | ||
|
||
This gem is brought to you by the NAPI (Napster API) development team. Please [reach out to us](https://groups.google.com/forum/#!forum/rhapsody-api) if you have any questions. | ||
|
||
## 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 a new Pull Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require "bundler/gem_tasks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require "omniauth/napster" | ||
require "omniauth/strategies/napster" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module OmniAuth | ||
module Napster | ||
VERSION = "0.1.0" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'omniauth-oauth2' | ||
|
||
module OmniAuth | ||
module Strategies | ||
class Napster < OmniAuth::Strategies::OAuth2 | ||
include OmniAuth::Strategy | ||
option :name, 'napster' | ||
|
||
option :client_options, { | ||
:site => 'https://api.napster.com', | ||
:token_url => '/oauth/access_token' | ||
} | ||
|
||
uid{ raw_info['me']['id'] } | ||
|
||
info do | ||
{ | ||
:uid => raw_info['me']['id'], | ||
:name => raw_info['me']['realName'], | ||
:username => raw_info['me']['screenName'], | ||
:image => raw_info['me']['avatar'] | ||
} | ||
end | ||
|
||
extra do | ||
{ | ||
'raw_info' => raw_info | ||
} | ||
end | ||
|
||
def raw_info | ||
@raw_info ||= access_token.get('/me').parsed | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require 'omniauth/napster' | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "omniauth-napster" | ||
s.version = OmniAuth::Napster::VERSION | ||
s.authors = ["Richard Luck"] | ||
s.email = ["rluck@rhapsody.com"] | ||
s.description = %q{This gem provides the OmniAuth strategy for connecting to the Napster API.} | ||
s.summary = %q{OmniAuth strategy for Napster Music Service} | ||
s.homepage = "https://github.com/Napster/omniauth-napster.git" | ||
s.required_ruby_version = '~> 2.0' | ||
s.license = 'MIT' | ||
s.files = `git ls-files`.split($/) | ||
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) } | ||
s.test_files = s.files.grep(%r{^(test|spec|features)/}) | ||
s.require_paths = ["lib"] | ||
s.add_runtime_dependency 'omniauth-oauth2', '~> 1.3' | ||
s.add_development_dependency 'rspec', '~> 3.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'spec_helper' | ||
describe 'OmniAuth::Napster::VERSION' do | ||
it "should return version number" do | ||
expect(OmniAuth::Napster::VERSION).to eq('0.1.0') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'spec_helper' | ||
describe 'OmniAuth::Strategies::Napster' do | ||
subject do | ||
OmniAuth::Strategies::Napster.new({}) | ||
end | ||
|
||
context "client options" do | ||
it 'should have correct name' do | ||
expect(subject.options.name).to eq("napster") | ||
end | ||
|
||
it 'should have correct site' do | ||
expect(subject.options.client_options.site).to eq('https://api.napster.com') | ||
end | ||
|
||
it 'should have correct token url' do | ||
expect(subject.options.client_options.token_url).to eq('/oauth/access_token') | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'bundler/setup' | ||
Bundler.setup | ||
|
||
require 'omniauth-napster' | ||
|
||
RSpec.configure do |config| | ||
# some (optional) config here | ||
end |