omniauth-bike-index 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8c7076b1968d8dd1146f2464aa3f5a312c2b7c8b
4
+ data.tar.gz: 57e24cb405f9e07d8460699c4d542437c6ff909f
5
+ SHA512:
6
+ metadata.gz: d77901f51616b78ff878d93aa899a9bfd5c2bf9ebf9f1597a7bc3da791a1214acfa13b090661b4964ea76c58bb3c41db0ee2e94b3f7fd67c35a23da690f66d73
7
+ data.tar.gz: 583f9cdf88a08cc72d433494e617adfe569e994103d31f3d80b036c7e0cc686216995eed447a24f5d94e5d82b42b71c3d47a86abfb72805ee08dcb5c4fd35a1c
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .env
19
+ .rspec
20
+ .ruby-*
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ bundler_args: --without development
2
+ gemfile:
3
+ - Gemfile
4
+ language: ruby
5
+ rvm:
6
+ - 1.9.2
7
+ - 1.9.3
8
+ - 2.0.0
9
+ - 2.1.0
10
+ - rbx-2
11
+ - ruby-head
12
+ - jruby-19mode
13
+ - jruby-head
14
+ matrix:
15
+ allow_failures:
16
+ - rvm: jruby-head
17
+ - rvm: ruby-head
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+
5
+ group :test do
6
+ gem 'rspec', '~> 2.7'
7
+ gem 'guard'
8
+ gem 'guard-rspec', '4.2.8'
9
+ gem 'guard-livereload'
10
+ end
11
+
12
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ rspec_opts = {
2
+ failed_mode: :focus
3
+ }
4
+
5
+ guard :rspec, cmd: "bundle exec rspec" do
6
+ watch(%r{^spec/.+_spec\.rb$})
7
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
8
+ end
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ OmniAuth::BikeIndex
2
+ ==============
3
+
4
+ Bike Index OAuth2 Strategy for OmniAuth 1.0.
5
+
6
+ Supports the OAuth 2.0 server-side and client-side flows.
7
+
8
+
9
+ ## Creating an application
10
+
11
+ To be able to use OAuth on the Bike Index, you have to create an application. Go to [BikeIndex.org/oauth/applications](https://bikeindex.org/oauth/applications) to add your application.
12
+
13
+ Once you've added your application and your routes, you'll be able to see your Application ID and Secret, which you will need for omniauth.
14
+
15
+ **Note**: Callback url has to be an exact match - if your url is `http://localhost:3001/users/auth/bike_index/callback` you _must_ enter that exactly - `http://localhost:3001/users/auth/` will not work.
16
+
17
+
18
+ _Right now (Nov 12 2014) the Bike Index OAuth API is still in beta, and is accessible at /api/v2 - it can provide a list of bike ids for a given user, more functionality will be added soon._
19
+
20
+ ## Usage
21
+
22
+ First add it to you Gemfile:
23
+
24
+ `gem 'omniauth-bike-index'`
25
+
26
+ Here's a quick example, adding the middleware to a Rails app in
27
+ `config/initializers/omniauth.rb`:
28
+
29
+ ```ruby
30
+ Rails.application.config.middleware.use OmniAuth::Builder do
31
+ provider :bike_index, ENV['BIKEINDEX_APP_ID'], ENV['BIKEINDEX_APP_SECRET']
32
+ end
33
+ ```
34
+
35
+ Your `BIKEINDEX_APP_ID` and your `BIKEINDEX_APP_SECRET` are both application specific. To create or view your applications go to [BikeIndex.org/oauth/applications](https://bikeindex.org/oauth/applications).
36
+
37
+ Edit your routes.rb file to have:
38
+
39
+ `devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" }`
40
+
41
+ And create a file called `omniauth_callbacks_controller.rb` which should have this inside:
42
+
43
+ ```ruby
44
+ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
45
+
46
+ def bike_index
47
+ # Delete the code inside of this method and write your own.
48
+ # The code below is to show you where to access the data.
49
+ raise request.env["omniauth.auth"].to_json
50
+ end
51
+ end
52
+ ```
53
+
54
+ ## Scopes
55
+
56
+ The default scope is `public` - which will be submitted unless you configure additional scopes. You can set scopes in the configuration with a space seperated list, e.g. for Devise
57
+
58
+ ```ruby
59
+ Devise.setup do |config|
60
+ config.omniauth :bike_index, ENV['BIKEINDEX_APP_ID'], ENV['BIKEINDEX_APP_SECRET'], scope: 'read_bikes write_user read_user`
61
+ end
62
+ ```
63
+
64
+ Available scopes: `read_user`, `write_user`, `read_bikes`, `write_bikes`, `create_bikes`, `read_bikewise`, `write_bikewise`
65
+
66
+
67
+ ## Credentials
68
+
69
+ If you don't include a scope, the response will include a `uid` from Bike Index for the user and nothing else.
70
+
71
+ If you include the `read_bikes` scope, the response will include an array of the ids the user has registered on the Index `bike_ids: [3414, 29367]`
72
+
73
+ You can use these IDs to access information about the bikes - e.g. [BikeIndex.org/api/v1/bikes/3414](https://bikeindex.org/api/v1/bikes/3414) & [/api/v1/bikes/29367](https://bikeindex.org/api/v1/bikes/29367)
74
+
75
+ _currently, you should use the v1 of the API ([documentation](https://bikeindex.org/documentation))_
76
+
77
+
78
+ If you include the `read_user` scope, the response will include the user's username, email and name. You will also see their twitter handle and avatar if they have added them. The keys for these items -
79
+ `username`, `email`, `name`, `twitter` & `image` - all accessible in the `request.env['omniauth.auth']`, e.g. `request.env['omniauth.auth'].info.email`
80
+
81
+
82
+ ## Auth Hash
83
+
84
+ You can also see the authetication hash (in JSON format) by going to the authentication url on the Bike Index with the user's access token - `https://bikeindex.org/api/v2/users/current?access_token=<OAUTH_ACCESS_TOKEN>`
85
+
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,2 @@
1
+ require 'omniauth/bike_index/version'
2
+ require 'omniauth/strategies/bike_index'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module BikeIndex
3
+ VERSION = '0.0.2'
4
+ end
5
+ end
@@ -0,0 +1,55 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class BikeIndex < OmniAuth::Strategies::OAuth2
6
+ option :name, :bike_index
7
+ DEFAULT_SCOPE = 'public'
8
+ option :client_options, :site => 'https://bikeindex.org',
9
+ :authorize_url => '/oauth/authorize'
10
+
11
+ uid { raw_info['id'] }
12
+
13
+ info do
14
+ prune!(
15
+ 'username' => raw_info['user']['username'],
16
+ 'bike_ids' => raw_info['bike_ids'],
17
+ 'email' => raw_info['user']['email'],
18
+ 'name' => raw_info['user']['name'],
19
+ 'twitter' => raw_info['user']['twitter'],
20
+ 'image' => raw_info['user']['image'],
21
+ )
22
+ end
23
+
24
+ extra do
25
+ hash = {}
26
+ hash['raw_info'] = raw_info unless skip_info?
27
+ prune! hash
28
+ end
29
+
30
+ def raw_info
31
+ @raw_info ||= access_token.get('/api/v2/users/current').parsed || {}
32
+ end
33
+
34
+ def request_phase
35
+ options[:authorize_params] = {
36
+ # :client_id => options['client_id'],
37
+ # :response_type => 'code',
38
+ :scope => (options['scope'] || DEFAULT_SCOPE)
39
+ }
40
+
41
+ super
42
+ end
43
+
44
+ private
45
+
46
+ def prune!(hash)
47
+ hash.delete_if do |_, value|
48
+ prune!(value) if value.is_a?(Hash)
49
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
+ require 'omniauth/bike_index/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'omniauth-bike-index'
7
+ s.version = OmniAuth::BikeIndex::VERSION
8
+ s.authors = ['Seth Herr']
9
+ s.email = ['seth@bikeidnex.org']
10
+ s.summary = 'Bike Index strategy for OmniAuth'
11
+ s.description = 'Bike Index strategy for OmniAuth v1.2'
12
+ s.homepage = 'https://github.com/bikeindex/omniauth-bike-index'
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").collect { |f| File.basename(f) }
18
+ s.require_paths = ['lib']
19
+
20
+ s.add_runtime_dependency 'omniauth', '~> 1.2'
21
+ s.add_runtime_dependency 'omniauth-oauth2', '~> 1.1'
22
+
23
+ s.add_development_dependency 'dotenv', '~> 0'
24
+ s.add_development_dependency 'sinatra', '~> 0'
25
+ end
data/spec/app.rb ADDED
@@ -0,0 +1,49 @@
1
+ $LOAD_PATH.unshift File.expand_path('..', __FILE__)
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'dotenv'
5
+ require 'sinatra'
6
+ require 'omniauth'
7
+ require 'omniauth-bike-index'
8
+
9
+ Dotenv.load
10
+
11
+ use Rack::Session::Cookie, :key => 'key',
12
+ :domain => 'localhost',
13
+ :path => '/',
14
+ :expire_after => 14_400,
15
+ :secret => 'secret'
16
+
17
+ use OmniAuth::Builder do
18
+ provider :bike_index, ENV['CLIENT_ID'], ENV['CLIENT_SECRET'], :scope => 'access_profile'
19
+ end
20
+
21
+ get '/' do
22
+ <<-HTML
23
+ <a href='/auth/venmo'>Sign in with Venmo</a>
24
+ HTML
25
+ end
26
+
27
+ get '/auth/failure' do
28
+ env['omniauth.error'].to_s
29
+ end
30
+
31
+ get '/auth/:name/callback' do
32
+ auth = request.env['omniauth.auth']
33
+
34
+ puts %Q(
35
+ >> UID
36
+ #{auth.uid.inspect}
37
+
38
+ >> ACCESS TOKEN
39
+ #{auth.credentials.token.inspect}
40
+
41
+ >> INFO
42
+ #{auth.info.inspect}
43
+ #
44
+ >> EXTRA
45
+ #{auth.extra.inspect}
46
+ )
47
+
48
+ 'Check logs for user information.'
49
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::BikeIndex do
4
+ subject do
5
+ @subject ||= begin
6
+ args = ['client_id', 'client_secret', @options || {}].compact
7
+ OmniAuth::Strategies::BikeIndex.new(*args)
8
+ end
9
+ end
10
+
11
+ context 'client options' do
12
+ it 'has correct name' do
13
+ expect(subject.options.name).to eq(:bike_index)
14
+ end
15
+
16
+ it 'has correct site' do
17
+ expect(subject.options.client_options.site).to eq('https://bikeindex.org')
18
+ end
19
+
20
+ it 'has correct authorize url' do
21
+ expect(subject.options.client_options.authorize_url).to eq('/oauth/authorize')
22
+ end
23
+
24
+ end
25
+
26
+ context 'figuring stuff out' do
27
+ it "gets log in" do
28
+ app = lambda{|env| [200, {}, ["Hello World."]]}
29
+ OmniAuth::Strategies::Developer.new(app).options.uid_field # => :email
30
+ OmniAuth::Strategies::Developer.new(app, :uid_field => :name).options.uid_field # => :name
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift File.expand_path('..', __FILE__)
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'rspec'
5
+ require 'omniauth'
6
+ require 'omniauth-bike-index'
7
+
8
+ RSpec.configure do |config|
9
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
10
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-bike-index
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Seth Herr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Bike Index strategy for OmniAuth v1.2
70
+ email:
71
+ - seth@bikeidnex.org
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - Guardfile
80
+ - README.md
81
+ - Rakefile
82
+ - lib/omniauth-bike-index.rb
83
+ - lib/omniauth/bike_index/version.rb
84
+ - lib/omniauth/strategies/bike_index.rb
85
+ - omniauth-bike-index.gemspec
86
+ - spec/app.rb
87
+ - spec/omniauth/strategies/bike_index_spec.rb
88
+ - spec/spec_helper.rb
89
+ homepage: https://github.com/bikeindex/omniauth-bike-index
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.2.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Bike Index strategy for OmniAuth
113
+ test_files:
114
+ - spec/app.rb
115
+ - spec/omniauth/strategies/bike_index_spec.rb
116
+ - spec/spec_helper.rb