omniauth-bike-index 0.1.0 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +5 -8
- data/Gemfile +4 -6
- data/README.md +7 -14
- data/Rakefile +6 -3
- data/lib/omniauth-bike-index.rb +2 -2
- data/lib/omniauth/bike_index/version.rb +1 -1
- data/lib/omniauth/strategies/bike_index.rb +23 -18
- data/omniauth-bike-index.gemspec +18 -19
- data/spec/app.rb +20 -20
- data/spec/omniauth/strategies/bike_index_spec.rb +13 -15
- data/spec/spec_helper.rb +6 -6
- metadata +7 -8
- data/Guardfile +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ed476813826660c5afabb02e43fc77d9a423ed63dd9eeeb0864c2fd256876a46
|
4
|
+
data.tar.gz: 161e4b546c49eaa0e54728593d3d597e1ec0372374615d9a9fed19e5d4256083
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b19d2b3b2d040381ddba62e61ce7db388f54396958353f8c48f07597864fcf35c446aaf3948f83a48769910add600f91186f67c9a28322a62e576e0fd43a8742
|
7
|
+
data.tar.gz: 990b71281d87975209be63f652e261fb24d2ec304c3b0217e1dc98ef1f7604a1f0f48bfd2ce177bc6f14b98fa90fc45a89106ebe6917080f642aa29029377f00
|
data/.travis.yml
CHANGED
@@ -2,16 +2,13 @@ bundler_args: --without development
|
|
2
2
|
gemfile:
|
3
3
|
- Gemfile
|
4
4
|
language: ruby
|
5
|
+
before_install:
|
6
|
+
- gem install bundler
|
7
|
+
- gem update bundler
|
5
8
|
rvm:
|
6
|
-
-
|
7
|
-
-
|
8
|
-
- 2.0.0
|
9
|
-
- 2.1.0
|
10
|
-
- rbx-2
|
11
|
-
- ruby-head
|
12
|
-
- jruby-19mode
|
9
|
+
- 2.3.0
|
10
|
+
- 2.5.8
|
13
11
|
- jruby-head
|
14
12
|
matrix:
|
15
13
|
allow_failures:
|
16
14
|
- rvm: jruby-head
|
17
|
-
- rvm: ruby-head
|
data/Gemfile
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
|
-
gem
|
3
|
+
gem "rake"
|
4
4
|
|
5
5
|
group :test do
|
6
|
-
gem
|
7
|
-
gem
|
8
|
-
gem 'guard-rspec', '4.2.8'
|
9
|
-
gem 'guard-livereload'
|
6
|
+
gem "standard"
|
7
|
+
gem "rspec"
|
10
8
|
end
|
11
9
|
|
12
10
|
gemspec
|
data/README.md
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
OmniAuth::BikeIndex
|
2
|
-
==============
|
1
|
+
# OmniAuth::BikeIndex [![Build Status](https://travis-ci.org/bikeindex/omniauth-bike-index.svg?branch=master)](https://travis-ci.org/bikeindex/omniauth-bike-index)
|
3
2
|
|
4
3
|
Bike Index OAuth2 Strategy for OmniAuth 1.0.
|
5
4
|
|
6
5
|
Supports the OAuth 2.0 server-side and client-side flows.
|
7
6
|
|
8
|
-
|
9
7
|
## Creating an application
|
10
8
|
|
11
9
|
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.
|
@@ -14,8 +12,7 @@ Once you've added your application and your routes, you'll be able to see your A
|
|
14
12
|
|
15
13
|
**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
14
|
|
17
|
-
|
18
|
-
Check out **[API V2 Documentation](https://bikeindex.org/documentation/api_v2)** to see what can be done with authenticated users.
|
15
|
+
Check out the **[Bike Index API Documentation](https://bikeindex.org/documentation)** to see what can be done with authenticated users.
|
19
16
|
|
20
17
|
## Usage
|
21
18
|
|
@@ -36,17 +33,16 @@ Your `BIKEINDEX_APP_ID` and your `BIKEINDEX_APP_SECRET` are both application spe
|
|
36
33
|
|
37
34
|
Edit your routes.rb file to have:
|
38
35
|
|
39
|
-
`devise_for :users, :
|
36
|
+
`devise_for :users, controllers: { omniauth_callbacks: 'omniauth_callbacks' }`
|
40
37
|
|
41
38
|
And create a file called `omniauth_callbacks_controller.rb` which should have this inside:
|
42
39
|
|
43
40
|
```ruby
|
44
41
|
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
45
|
-
|
46
42
|
def bike_index
|
47
43
|
# Delete the code inside of this method and write your own.
|
48
44
|
# The code below is to show you where to access the data.
|
49
|
-
raise request.env[
|
45
|
+
raise request.env['omniauth.auth'].to_json
|
50
46
|
end
|
51
47
|
end
|
52
48
|
```
|
@@ -63,20 +59,17 @@ end
|
|
63
59
|
|
64
60
|
Available scopes: `read_user`, `write_user`, `read_bikes`, `write_bikes`
|
65
61
|
|
66
|
-
|
67
62
|
## Credentials
|
68
63
|
|
69
64
|
If you don't include a scope, the response will include a `uid` from Bike Index for the user and nothing else.
|
70
65
|
|
71
66
|
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
67
|
|
73
|
-
You can use these IDs to access information about the bikes - e.g. [
|
68
|
+
You can use these IDs to access information about the bikes - e.g. [api/v3/bikes/3414](https://bikeindex.org/api/v3/bikes/3414) & [api/v3/bikes/29367](https://bikeindex.org/api/v3/bikes/29367)
|
74
69
|
|
75
|
-
If you include the `read_user` scope, the response will include the user's nickname, email and name. You will also see their twitter handle and avatar if they have added them. The keys for these items -
|
70
|
+
If you include the `read_user` scope, the response will include the user's nickname, email and name. You will also see their twitter handle and avatar if they have added them. The keys for these items -
|
76
71
|
`nickname`, `email`, `name`, `twitter` & `image` - all accessible in the `request.env['omniauth.auth']`, e.g. `request.env['omniauth.auth'].info.email`
|
77
72
|
|
78
|
-
|
79
73
|
## Auth Hash
|
80
74
|
|
81
|
-
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/
|
82
|
-
|
75
|
+
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/v3/me?access_token=<OAUTH_ACCESS_TOKEN>`
|
data/Rakefile
CHANGED
data/lib/omniauth-bike-index.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "omniauth/bike_index/version"
|
2
|
+
require "omniauth/strategies/bike_index"
|
@@ -1,45 +1,51 @@
|
|
1
|
-
require
|
1
|
+
require "omniauth-oauth2"
|
2
2
|
|
3
3
|
module OmniAuth
|
4
4
|
module Strategies
|
5
5
|
class BikeIndex < OmniAuth::Strategies::OAuth2
|
6
6
|
option :name, :bike_index
|
7
|
-
DEFAULT_SCOPE =
|
8
|
-
option :client_options, :
|
9
|
-
:authorize_url => '/oauth/authorize'
|
7
|
+
DEFAULT_SCOPE = "public"
|
8
|
+
option :client_options, site: "https://bikeindex.org", authorize_url: "/oauth/authorize"
|
10
9
|
|
11
|
-
uid { raw_info[
|
10
|
+
uid { raw_info["id"] }
|
12
11
|
|
13
12
|
info do
|
14
13
|
prune!(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
"nickname" => raw_info["user"]["username"],
|
15
|
+
"bike_ids" => raw_info["bike_ids"],
|
16
|
+
"email" => raw_info["user"]["email"],
|
17
|
+
"secondary_emails" => raw_info["user"]["secondary_emails"],
|
18
|
+
"name" => raw_info["user"]["name"],
|
19
|
+
"twitter" => raw_info["user"]["twitter"],
|
20
|
+
"image" => raw_info["user"]["image"]
|
21
21
|
)
|
22
22
|
end
|
23
23
|
|
24
24
|
extra do
|
25
25
|
hash = {}
|
26
|
-
hash[
|
26
|
+
hash["raw_info"] = raw_info unless skip_info?
|
27
27
|
prune! hash
|
28
28
|
end
|
29
29
|
|
30
30
|
def raw_info
|
31
|
-
@raw_info ||= access_token.get(
|
31
|
+
@raw_info ||= access_token.get("/api/v3/me").parsed || {}
|
32
32
|
end
|
33
33
|
|
34
34
|
def request_phase
|
35
35
|
options[:authorize_params] = {
|
36
|
-
:
|
36
|
+
scope: (options["scope"] || DEFAULT_SCOPE),
|
37
|
+
partner: options["partner"],
|
38
|
+
unauthenticated_redirect: options["unauthenticated_redirect"]
|
37
39
|
}
|
38
|
-
|
39
40
|
super
|
40
41
|
end
|
41
42
|
|
42
|
-
|
43
|
+
# https://github.com/omniauth/omniauth-oauth2/issues/81
|
44
|
+
def callback_url
|
45
|
+
full_host + script_name + callback_path
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
43
49
|
|
44
50
|
def prune!(hash)
|
45
51
|
hash.delete_if do |_, value|
|
@@ -47,7 +53,6 @@ module OmniAuth
|
|
47
53
|
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
48
54
|
end
|
49
55
|
end
|
50
|
-
|
51
56
|
end
|
52
57
|
end
|
53
|
-
end
|
58
|
+
end
|
data/omniauth-bike-index.gemspec
CHANGED
@@ -1,25 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'omniauth/bike_index/version'
|
1
|
+
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "omniauth/bike_index/version"
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
6
|
-
s.name
|
7
|
-
s.version
|
8
|
-
s.authors
|
9
|
-
s.email
|
10
|
-
s.summary
|
11
|
-
s.description
|
12
|
-
s.homepage
|
13
|
-
s.license
|
5
|
+
s.name = "omniauth-bike-index"
|
6
|
+
s.version = OmniAuth::BikeIndex::VERSION
|
7
|
+
s.authors = ["Seth Herr"]
|
8
|
+
s.email = ["seth@bikeidnex.org"]
|
9
|
+
s.summary = "Bike Index strategy for OmniAuth"
|
10
|
+
s.description = "Bike Index strategy for OmniAuth v1.2"
|
11
|
+
s.homepage = "https://github.com/bikeindex/omniauth-bike-index"
|
12
|
+
s.license = "MIT"
|
14
13
|
|
15
|
-
s.files
|
16
|
-
s.test_files
|
17
|
-
s.executables
|
18
|
-
s.require_paths = [
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").collect { |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
19
18
|
|
20
|
-
s.add_runtime_dependency
|
21
|
-
s.add_runtime_dependency
|
19
|
+
s.add_runtime_dependency "omniauth", "~> 1.2"
|
20
|
+
s.add_runtime_dependency "omniauth-oauth2", "~> 1.1"
|
22
21
|
|
23
|
-
s.add_development_dependency
|
24
|
-
s.add_development_dependency
|
22
|
+
s.add_development_dependency "dotenv", "~> 0"
|
23
|
+
s.add_development_dependency "sinatra", "~> 0"
|
25
24
|
end
|
data/spec/app.rb
CHANGED
@@ -1,37 +1,37 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path(
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
1
|
+
$LOAD_PATH.unshift File.expand_path("..", __FILE__)
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
4
|
+
require "dotenv"
|
5
|
+
require "sinatra"
|
6
|
+
require "omniauth"
|
7
|
+
require "omniauth-bike-index"
|
8
8
|
|
9
9
|
Dotenv.load
|
10
10
|
|
11
|
-
use Rack::Session::Cookie, :
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
11
|
+
use Rack::Session::Cookie, key: "key",
|
12
|
+
domain: "localhost",
|
13
|
+
path: "/",
|
14
|
+
expire_after: 14_400,
|
15
|
+
secret: "secret"
|
16
16
|
|
17
17
|
use OmniAuth::Builder do
|
18
|
-
provider :bike_index, ENV[
|
18
|
+
provider :bike_index, ENV["CLIENT_ID"], ENV["CLIENT_SECRET"], scope: "access_profile"
|
19
19
|
end
|
20
20
|
|
21
|
-
get
|
21
|
+
get "/" do
|
22
22
|
<<-HTML
|
23
|
-
<a href='/auth/
|
23
|
+
<a href='/auth/bikeindex'>Sign in with Bike Index</a>
|
24
24
|
HTML
|
25
25
|
end
|
26
26
|
|
27
|
-
get
|
28
|
-
env[
|
27
|
+
get "/auth/failure" do
|
28
|
+
env["omniauth.error"].to_s
|
29
29
|
end
|
30
30
|
|
31
|
-
get
|
32
|
-
auth = request.env[
|
31
|
+
get "/auth/:name/callback" do
|
32
|
+
auth = request.env["omniauth.auth"]
|
33
33
|
|
34
|
-
puts %
|
34
|
+
puts %(
|
35
35
|
>> UID
|
36
36
|
#{auth.uid.inspect}
|
37
37
|
|
@@ -45,5 +45,5 @@ get '/auth/:name/callback' do
|
|
45
45
|
#{auth.extra.inspect}
|
46
46
|
)
|
47
47
|
|
48
|
-
|
48
|
+
"Check logs for user information."
|
49
49
|
end
|
@@ -1,34 +1,32 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe OmniAuth::Strategies::BikeIndex do
|
4
4
|
subject do
|
5
5
|
@subject ||= begin
|
6
|
-
args = [
|
6
|
+
args = ["client_id", "client_secret", @options || {}].compact
|
7
7
|
OmniAuth::Strategies::BikeIndex.new(*args)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
context
|
12
|
-
it
|
11
|
+
context "client options" do
|
12
|
+
it "has correct name" do
|
13
13
|
expect(subject.options.name).to eq(:bike_index)
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
17
|
-
expect(subject.options.client_options.site).to eq(
|
16
|
+
it "has correct site" do
|
17
|
+
expect(subject.options.client_options.site).to eq("https://bikeindex.org")
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
expect(subject.options.client_options.authorize_url).to eq(
|
20
|
+
it "has correct authorize url" do
|
21
|
+
expect(subject.options.client_options.authorize_url).to eq("/oauth/authorize")
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
25
24
|
|
26
|
-
context
|
27
|
-
it "gets log in" do
|
28
|
-
app = lambda{|env| [200, {}, ["Hello World."]]}
|
29
|
-
OmniAuth::Strategies::Developer.new(app).options.uid_field
|
30
|
-
OmniAuth::Strategies::Developer.new(app, :
|
25
|
+
context "figuring stuff out" do
|
26
|
+
it "gets log in" do
|
27
|
+
app = lambda { |env| [200, {}, ["Hello World."]] }
|
28
|
+
OmniAuth::Strategies::Developer.new(app).options.uid_field # => :email
|
29
|
+
OmniAuth::Strategies::Developer.new(app, uid_field: :name).options.uid_field # => :name
|
31
30
|
end
|
32
31
|
end
|
33
|
-
|
34
32
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path(
|
2
|
-
$LOAD_PATH.unshift File.expand_path(
|
1
|
+
$LOAD_PATH.unshift File.expand_path("..", __FILE__)
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
4
|
+
require "rspec"
|
5
|
+
require "omniauth"
|
6
|
+
require "omniauth-bike-index"
|
7
7
|
|
8
8
|
RSpec.configure do |config|
|
9
|
-
config.extend OmniAuth::Test::StrategyMacros, :
|
9
|
+
config.extend OmniAuth::Test::StrategyMacros, type: :strategy
|
10
10
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-bike-index
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seth Herr
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth
|
@@ -76,7 +76,6 @@ files:
|
|
76
76
|
- ".gitignore"
|
77
77
|
- ".travis.yml"
|
78
78
|
- Gemfile
|
79
|
-
- Guardfile
|
80
79
|
- README.md
|
81
80
|
- Rakefile
|
82
81
|
- lib/omniauth-bike-index.rb
|
@@ -90,7 +89,7 @@ homepage: https://github.com/bikeindex/omniauth-bike-index
|
|
90
89
|
licenses:
|
91
90
|
- MIT
|
92
91
|
metadata: {}
|
93
|
-
post_install_message:
|
92
|
+
post_install_message:
|
94
93
|
rdoc_options: []
|
95
94
|
require_paths:
|
96
95
|
- lib
|
@@ -105,9 +104,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
104
|
- !ruby/object:Gem::Version
|
106
105
|
version: '0'
|
107
106
|
requirements: []
|
108
|
-
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
110
|
-
signing_key:
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.7.6.2
|
109
|
+
signing_key:
|
111
110
|
specification_version: 4
|
112
111
|
summary: Bike Index strategy for OmniAuth
|
113
112
|
test_files:
|