omniauth-bike-index 1.0.0 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +3 -0
- data/.travis.yml +2 -2
- data/Gemfile +4 -3
- data/README.md +1 -7
- data/Rakefile +3 -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 +34 -16
- data/omniauth-bike-index.gemspec +18 -19
- data/spec/app.rb +19 -19
- data/spec/omniauth/strategies/bike_index_spec.rb +13 -14
- data/spec/spec_helper.rb +6 -6
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 01d745f15c082b6b8906b5643f130d20f39bbc66b7425b563a2b12b3f85f17d1
|
4
|
+
data.tar.gz: 39c97a47c2950793af76588ad1697b49ae653fdd08714198162a7f97b4e8f6a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dfcab4f77621d617a78870bd923379fdc2f311b33dab85549f8fc8df08668876d1d9d78671fbc4f2aeb4a42b52774e0826788a54acbca66b08630ea1d165b37
|
7
|
+
data.tar.gz: 4b53ab68270c7c2634bafecedc156314cc1023036e44e83a94b578f49a87eda4393ca15464983bd6490b251665a8d6128023fcc0be2324963ebb583a6ffc1608
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
# OmniAuth::BikeIndex [](https://travis-ci.org/bikeindex/omniauth-bike-index)
|
2
|
-
==============
|
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,7 +12,6 @@ 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
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
|
@@ -62,7 +59,6 @@ end
|
|
62
59
|
|
63
60
|
Available scopes: `read_user`, `write_user`, `read_bikes`, `write_bikes`
|
64
61
|
|
65
|
-
|
66
62
|
## Credentials
|
67
63
|
|
68
64
|
If you don't include a scope, the response will include a `uid` from Bike Index for the user and nothing else.
|
@@ -71,11 +67,9 @@ If you include the `read_bikes` scope, the response will include an array of the
|
|
71
67
|
|
72
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)
|
73
69
|
|
74
|
-
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 -
|
75
71
|
`nickname`, `email`, `name`, `twitter` & `image` - all accessible in the `request.env['omniauth.auth']`, e.g. `request.env['omniauth.auth'].info.email`
|
76
72
|
|
77
|
-
|
78
73
|
## Auth Hash
|
79
74
|
|
80
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>`
|
81
|
-
|
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,41 +1,60 @@
|
|
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, site:
|
7
|
+
DEFAULT_SCOPE = "public"
|
8
|
+
option :client_options, site: "https://bikeindex.org", authorize_url: "/oauth/authorize"
|
9
9
|
|
10
|
-
uid { raw_info[
|
10
|
+
uid { raw_info["id"] }
|
11
11
|
|
12
12
|
info do
|
13
13
|
prune!(
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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"]
|
20
21
|
)
|
21
22
|
end
|
22
23
|
|
23
24
|
extra do
|
24
25
|
hash = {}
|
25
|
-
hash[
|
26
|
+
hash["raw_info"] = raw_info unless skip_info?
|
26
27
|
prune! hash
|
27
28
|
end
|
28
29
|
|
29
30
|
def raw_info
|
30
|
-
@raw_info ||= access_token.get(
|
31
|
+
@raw_info ||= access_token.get("/api/v3/me").parsed || {}
|
32
|
+
end
|
33
|
+
|
34
|
+
def param_or_option(key)
|
35
|
+
# omniauth.params are the parameters passed in to the URL
|
36
|
+
# (e.g. company in /users/auth/bike_index?company=Metro)
|
37
|
+
# So for partner, company and unauthenticated_redirect it tries those params, then goes from settings
|
38
|
+
session["omniauth.params"] && session["omniauth.params"][key] ||
|
39
|
+
option[key]
|
31
40
|
end
|
32
41
|
|
33
42
|
def request_phase
|
34
|
-
options[:authorize_params] = {
|
43
|
+
options[:authorize_params] = {
|
44
|
+
scope: (options["scope"] || DEFAULT_SCOPE),
|
45
|
+
partner: param_or_option("partner"),
|
46
|
+
company: param_or_option("company"),
|
47
|
+
unauthenticated_redirect: param_or_option("unauthenticated_redirect")
|
48
|
+
}
|
35
49
|
super
|
36
50
|
end
|
37
51
|
|
38
|
-
|
52
|
+
# https://github.com/omniauth/omniauth-oauth2/issues/81
|
53
|
+
def callback_url
|
54
|
+
full_host + script_name + callback_path
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
39
58
|
|
40
59
|
def prune!(hash)
|
41
60
|
hash.delete_if do |_, value|
|
@@ -43,7 +62,6 @@ module OmniAuth
|
|
43
62
|
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
44
63
|
end
|
45
64
|
end
|
46
|
-
|
47
65
|
end
|
48
66
|
end
|
49
|
-
end
|
67
|
+
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
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,33 +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
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: 1.0.
|
4
|
+
version: 1.0.5
|
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: 2021-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth
|
@@ -89,7 +89,7 @@ homepage: https://github.com/bikeindex/omniauth-bike-index
|
|
89
89
|
licenses:
|
90
90
|
- MIT
|
91
91
|
metadata: {}
|
92
|
-
post_install_message:
|
92
|
+
post_install_message:
|
93
93
|
rdoc_options: []
|
94
94
|
require_paths:
|
95
95
|
- lib
|
@@ -104,9 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
|
-
|
108
|
-
|
109
|
-
signing_key:
|
107
|
+
rubygems_version: 3.0.3
|
108
|
+
signing_key:
|
110
109
|
specification_version: 4
|
111
110
|
summary: Bike Index strategy for OmniAuth
|
112
111
|
test_files:
|