omniauth-fishbrain 0.9.0 → 0.11.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +55 -0
- data/lib/omniauth-fishbrain.rb +3 -1
- data/lib/{omniauth/fishbrain → omniauth-fishbrain}/version.rb +1 -1
- data/lib/omniauth/fishbrain/premium_status.rb +23 -0
- data/lib/omniauth/fishbrain/verifies_id_token.rb +45 -0
- data/lib/omniauth/strategies/fishbrain.rb +33 -53
- data/lib/omniauth/strategies/fishbrain_id.rb +60 -0
- metadata +13 -18
- data/.gitignore +0 -56
- data/README.md +0 -25
- data/examples/sinatra/Gemfile +0 -10
- data/examples/sinatra/fishbrain_example.rb +0 -34
- data/examples/sinatra/views/auth_failure.haml +0 -10
- data/examples/sinatra/views/callback.haml +0 -9
- data/examples/sinatra/views/index.haml +0 -14
- data/lib/omniauth/fishbrain.rb +0 -3
- data/omniauth-fishbrain.gemspec +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 815a9d4e769ec9b9d05bb7cd0314395df844c3190b148960403207030b4b5cfc
|
4
|
+
data.tar.gz: 29f2f2cde590788567aedfbb85ff569943f77a8068a3d78590a35876e2d762f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 174826683c500756bc406c58e0bca176d9e43ded8eb65eaf4c445981e702dd6de42cf43a8e0a86bc64a29ba8b5d4ca621e9f6ccaf6524904b5acdef8054c3552
|
7
|
+
data.tar.gz: c93625fad9bcc3ce07f51191992cc89cee90eef27b2593003ae807141a285c0ae963a40902bfdf2dbd006325af0c22edd75d63745782155d07432542a2788376
|
data/README.markdown
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# OmniAuth Fishbrain
|
2
|
+
|
3
|
+
![](https://github.com/omniauth/omniauth-github/workflows/Ruby/badge.svg?branch=master)
|
4
|
+
|
5
|
+
This gem provides two OmniAuth strategies for Fishbrain.
|
6
|
+
|
7
|
+
1. The `fishbrain` strategy is a standard OmniAuth OAuth2 strategy.
|
8
|
+
2. The `fishbrain_id` strategy is intended for sharing identities between
|
9
|
+
services.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'omniauth-fishbrain'
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
In production environments:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
use OmniAuth::Builder do
|
23
|
+
provider :fishbrain, ENV['FISHBRAIN_CLIENT_ID'], ENV['FISHBRAIN_CLIENT_SECRET']
|
24
|
+
provider :fishbrain_id
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
In development/test/staging environments:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
use OmniAuth::Builder do
|
32
|
+
provider :fishbrain, ENV['FISHBRAIN_CLIENT_ID'], ENV['FISHBRAIN_CLIENT_SECRET'],
|
33
|
+
user_pool_id: 'eu-west-1_WlBhbuD6e',
|
34
|
+
client_options: {
|
35
|
+
site: 'https://accounts-staging.fishbrain.com',
|
36
|
+
}
|
37
|
+
provider :fishbrain_id, user_pool_id: 'eu-west-1_WlBhbuD6e'
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
`path_prefix` is supported too:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
use OmniAuth::Builder do
|
45
|
+
...
|
46
|
+
|
47
|
+
configure { |c| c.path_prefix = '/client/auth' }
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
See [`/examples`](examples) for full example using Sinatra.
|
52
|
+
|
53
|
+
## License
|
54
|
+
|
55
|
+
[MIT](LICENSE)
|
data/lib/omniauth-fishbrain.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
module Fishbrain
|
7
|
+
module PremiumStatus
|
8
|
+
def premium_status
|
9
|
+
return {} unless id_token['premium_status']
|
10
|
+
|
11
|
+
JSON.parse(id_token['premium_status'])
|
12
|
+
rescue JSON::ParserError
|
13
|
+
{}
|
14
|
+
end
|
15
|
+
|
16
|
+
def premium?
|
17
|
+
Time.xmlschema(premium_status['end_date']) > Time.new.utc
|
18
|
+
rescue ArgumentError
|
19
|
+
false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'jwt'
|
5
|
+
|
6
|
+
module OmniAuth
|
7
|
+
module Fishbrain
|
8
|
+
module VerifiesIdToken
|
9
|
+
def id_token
|
10
|
+
@_id_token ||= if raw_id_token&.strip&.empty?
|
11
|
+
{}
|
12
|
+
else
|
13
|
+
JWT.decode(raw_id_token, nil, true, decode_options).first
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def decode_options
|
18
|
+
{
|
19
|
+
iss: iss,
|
20
|
+
aud: options[:client_id],
|
21
|
+
verify_aud: true,
|
22
|
+
verify_expiration: true,
|
23
|
+
verify_iat: true,
|
24
|
+
verify_iss: true,
|
25
|
+
verify_not_before: true,
|
26
|
+
leeway: options[:jwt_leeway],
|
27
|
+
algorithm: 'RS256',
|
28
|
+
jwks: jwks,
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def iss
|
33
|
+
"https://cognito-idp.#{options[:aws_region]}.amazonaws.com/#{options[:user_pool_id]}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def jwks
|
37
|
+
@_jwks ||= \
|
38
|
+
"#{iss}/.well-known/jwks.json"
|
39
|
+
.yield_self(&URI.method(:parse))
|
40
|
+
.yield_self(&Net::HTTP.method(:get))
|
41
|
+
.yield_self { |it| JSON.parse(it, symbolize_names: true) }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,84 +1,64 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'omniauth-oauth2'
|
4
|
-
require '
|
4
|
+
require 'omniauth/fishbrain/verifies_id_token'
|
5
|
+
require 'omniauth/fishbrain/premium_status'
|
5
6
|
|
6
7
|
module OmniAuth
|
7
8
|
module Strategies
|
8
|
-
# OmniAuth Strategy for Fishbrain
|
9
9
|
class Fishbrain < OmniAuth::Strategies::OAuth2
|
10
|
+
include OmniAuth::Fishbrain::VerifiesIdToken
|
11
|
+
include OmniAuth::Fishbrain::PremiumStatus
|
12
|
+
|
10
13
|
option :name, 'fishbrain'
|
11
|
-
option :client_options,
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
auth_scheme: :basic_auth
|
14
|
+
option :client_options, site: 'https://accounts.fishbrain.com',
|
15
|
+
authorize_url: '/oauth2/authorize',
|
16
|
+
token_url: '/oauth2/token',
|
17
|
+
auth_scheme: :basic_auth
|
16
18
|
option :scope, 'email openid profile'
|
17
|
-
option :
|
18
|
-
option :user_pool_id, 'eu-west-1_5r0WbR8OH'
|
19
|
+
option :user_pool_id, 'eu-west-1_TKWveIcYu'
|
19
20
|
option :aws_region, 'eu-west-1'
|
21
|
+
option :jwt_leeway, 60
|
20
22
|
|
21
23
|
uid do
|
22
|
-
|
24
|
+
id_token['sub']
|
23
25
|
end
|
24
26
|
|
25
27
|
info do
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
32
|
-
end
|
28
|
+
{
|
29
|
+
given_name: id_token['given_name'],
|
30
|
+
email: id_token['email'],
|
31
|
+
phone: id_token['phone_number'],
|
32
|
+
}
|
33
33
|
end
|
34
34
|
|
35
35
|
credentials do
|
36
|
-
{ token: access_token.token }
|
37
|
-
|
38
|
-
hash[:
|
39
|
-
hash[:
|
40
|
-
hash[:id_token] = id_token if id_token
|
36
|
+
hash = { token: access_token.token }
|
37
|
+
if access_token.expires?
|
38
|
+
hash[:refresh_token] = access_token.refresh_token if access_token.refresh_token
|
39
|
+
hash[:expires_at] = access_token.expires_at
|
41
40
|
end
|
41
|
+
hash[:expires] = access_token.expires?
|
42
|
+
hash[:id_token] = access_token['id_token'] if access_token['id_token']
|
43
|
+
hash
|
42
44
|
end
|
43
45
|
|
44
46
|
extra do
|
45
|
-
{
|
47
|
+
{
|
48
|
+
raw_info: id_token.reject { |key| %w[iss aud exp iat token_use].include?(key) },
|
49
|
+
premium_status: premium_status,
|
50
|
+
is_premium: premium?,
|
51
|
+
}
|
46
52
|
end
|
47
53
|
|
48
54
|
private
|
49
55
|
|
50
|
-
|
51
|
-
|
52
|
-
def build_access_token
|
53
|
-
client.auth_code.get_token(
|
54
|
-
request.params['code'],
|
55
|
-
{ redirect_uri: callback_url.split('?').first }.merge(token_params.to_hash(symbolize_keys: true)),
|
56
|
-
deep_symbolize(options.auth_token_params)
|
57
|
-
)
|
56
|
+
def callback_url
|
57
|
+
full_host + script_name + callback_path
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
61
|
-
access_token
|
62
|
-
end
|
63
|
-
|
64
|
-
def parsed_id_token
|
65
|
-
return nil unless id_token
|
66
|
-
|
67
|
-
@parsed_id_token ||= JWT.decode(
|
68
|
-
id_token,
|
69
|
-
nil,
|
70
|
-
false,
|
71
|
-
verify_iss: options[:aws_region] && options[:user_pool_id],
|
72
|
-
iss: "https://cognito-idp.#{options[:aws_region]}.amazonaws.com/#{options[:user_pool_id]}",
|
73
|
-
verify_aud: true,
|
74
|
-
aud: options[:client_id],
|
75
|
-
verify_sub: true,
|
76
|
-
verify_expiration: true,
|
77
|
-
verify_not_before: true,
|
78
|
-
verify_iat: true,
|
79
|
-
verify_jti: false,
|
80
|
-
leeway: options[:jwt_leeway]
|
81
|
-
).first
|
60
|
+
def raw_id_token
|
61
|
+
access_token['id_token']
|
82
62
|
end
|
83
63
|
end
|
84
64
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal:true
|
2
|
+
|
3
|
+
require 'omniauth/fishbrain/verifies_id_token'
|
4
|
+
require 'omniauth/fishbrain/premium_status'
|
5
|
+
|
6
|
+
module OmniAuth
|
7
|
+
module Strategies
|
8
|
+
class FishbrainId
|
9
|
+
include OmniAuth::Strategy
|
10
|
+
include OmniAuth::Fishbrain::VerifiesIdToken
|
11
|
+
include OmniAuth::Fishbrain::PremiumStatus
|
12
|
+
|
13
|
+
option :name, 'fishbrain_id'
|
14
|
+
option :user_pool_id, 'eu-west-1_TKWveIcYu'
|
15
|
+
option :client_id, nil
|
16
|
+
option :aws_region, 'eu-west-1'
|
17
|
+
option :jwt_leeway, 60
|
18
|
+
|
19
|
+
uid do
|
20
|
+
id_token['sub']
|
21
|
+
end
|
22
|
+
|
23
|
+
info do
|
24
|
+
{
|
25
|
+
given_name: id_token['given_name'],
|
26
|
+
email: id_token['email'],
|
27
|
+
phone: id_token['phone_number'],
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
extra do
|
32
|
+
{
|
33
|
+
raw_info: id_token.reject { |key| %w[iss aud exp iat token_use].include?(key) },
|
34
|
+
premium_status: premium_status,
|
35
|
+
is_premium: premium?,
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def callback_phase
|
40
|
+
if id_token.empty?
|
41
|
+
fail! :missing_id_token
|
42
|
+
else
|
43
|
+
super
|
44
|
+
end
|
45
|
+
rescue JWT::ExpiredSignature
|
46
|
+
fail! :invalid_id_token
|
47
|
+
end
|
48
|
+
|
49
|
+
def request_phase
|
50
|
+
redirect callback_url
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def raw_id_token
|
56
|
+
request.params['id_token']
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-fishbrain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Dalen
|
8
|
+
- Fishbrain AB
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2020-
|
12
|
+
date: 2020-05-28 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: jwt
|
@@ -38,27 +39,22 @@ dependencies:
|
|
38
39
|
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '1.6'
|
41
|
-
description:
|
42
|
-
with your ruby app.
|
42
|
+
description:
|
43
43
|
email:
|
44
44
|
- erik.dalen@fishbrain.com
|
45
|
+
- developer@fishbrain.com
|
45
46
|
executables: []
|
46
47
|
extensions: []
|
47
48
|
extra_rdoc_files: []
|
48
49
|
files:
|
49
|
-
- ".gitignore"
|
50
50
|
- LICENSE
|
51
|
-
- README.
|
52
|
-
- examples/sinatra/Gemfile
|
53
|
-
- examples/sinatra/fishbrain_example.rb
|
54
|
-
- examples/sinatra/views/auth_failure.haml
|
55
|
-
- examples/sinatra/views/callback.haml
|
56
|
-
- examples/sinatra/views/index.haml
|
51
|
+
- README.markdown
|
57
52
|
- lib/omniauth-fishbrain.rb
|
58
|
-
- lib/omniauth/
|
59
|
-
- lib/omniauth/fishbrain/
|
53
|
+
- lib/omniauth-fishbrain/version.rb
|
54
|
+
- lib/omniauth/fishbrain/premium_status.rb
|
55
|
+
- lib/omniauth/fishbrain/verifies_id_token.rb
|
60
56
|
- lib/omniauth/strategies/fishbrain.rb
|
61
|
-
- omniauth
|
57
|
+
- lib/omniauth/strategies/fishbrain_id.rb
|
62
58
|
homepage: https://github.com/fishbrain/omniauth-fishbrain
|
63
59
|
licenses:
|
64
60
|
- MIT
|
@@ -71,16 +67,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
67
|
requirements:
|
72
68
|
- - ">="
|
73
69
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
70
|
+
version: '0'
|
75
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
72
|
requirements:
|
77
73
|
- - ">="
|
78
74
|
- !ruby/object:Gem::Version
|
79
75
|
version: '0'
|
80
76
|
requirements: []
|
81
|
-
|
82
|
-
rubygems_version: 2.7.6
|
77
|
+
rubygems_version: 3.1.2
|
83
78
|
signing_key:
|
84
79
|
specification_version: 4
|
85
|
-
summary:
|
80
|
+
summary: OmniAuth strategy for Fishbrain
|
86
81
|
test_files: []
|
data/.gitignore
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
/.config
|
4
|
-
/coverage/
|
5
|
-
/InstalledFiles
|
6
|
-
/pkg/
|
7
|
-
/spec/reports/
|
8
|
-
/spec/examples.txt
|
9
|
-
/test/tmp/
|
10
|
-
/test/version_tmp/
|
11
|
-
/tmp/
|
12
|
-
|
13
|
-
# Used by dotenv library to load environment variables.
|
14
|
-
# .env
|
15
|
-
|
16
|
-
# Ignore Byebug command history file.
|
17
|
-
.byebug_history
|
18
|
-
|
19
|
-
## Specific to RubyMotion:
|
20
|
-
.dat*
|
21
|
-
.repl_history
|
22
|
-
build/
|
23
|
-
*.bridgesupport
|
24
|
-
build-iPhoneOS/
|
25
|
-
build-iPhoneSimulator/
|
26
|
-
|
27
|
-
## Specific to RubyMotion (use of CocoaPods):
|
28
|
-
#
|
29
|
-
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
-
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
-
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
-
#
|
33
|
-
# vendor/Pods/
|
34
|
-
|
35
|
-
## Documentation cache and generated files:
|
36
|
-
/.yardoc/
|
37
|
-
/_yardoc/
|
38
|
-
/doc/
|
39
|
-
/rdoc/
|
40
|
-
|
41
|
-
## Environment normalization:
|
42
|
-
/.bundle/
|
43
|
-
/vendor/bundle
|
44
|
-
/lib/bundler/man/
|
45
|
-
|
46
|
-
# for a library or gem, you might want to ignore these files since the code is
|
47
|
-
# intended to run in multiple environments; otherwise, check them in:
|
48
|
-
# Gemfile.lock
|
49
|
-
# .ruby-version
|
50
|
-
# .ruby-gemset
|
51
|
-
|
52
|
-
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
-
.rvmrc
|
54
|
-
|
55
|
-
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
-
# .rubocop-https?--*
|
data/README.md
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# omniauth-fishbrain
|
2
|
-
|
3
|
-
OmniAuth strategy for authenticating with Fishbrain
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add to your `Gemfile`:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'omniauth-google-oauth2'
|
11
|
-
```
|
12
|
-
|
13
|
-
Then `bundle install`.
|
14
|
-
|
15
|
-
## Usage
|
16
|
-
|
17
|
-
Add something like the following to add the fishbrain authentication stategy.
|
18
|
-
|
19
|
-
```
|
20
|
-
use OmniAuth::Builder do
|
21
|
-
provider :fishbrain, ENV.fetch('FISHBRAIN_CLIENT_ID'), ENV.fetch('FISHBRAIN_CLIENT_SECRET')
|
22
|
-
end
|
23
|
-
```
|
24
|
-
|
25
|
-
See `/examples` for a full example using Sinatra & Omniauth.
|
data/examples/sinatra/Gemfile
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'sinatra/base'
|
5
|
-
require 'omniauth'
|
6
|
-
require 'omniauth-fishbrain'
|
7
|
-
require 'pp'
|
8
|
-
|
9
|
-
# Example Sinatra+Omniauth+Fishbrain app
|
10
|
-
class FishbrainExample < Sinatra::Application
|
11
|
-
configure do
|
12
|
-
set :sessions, true
|
13
|
-
set :haml, format: :html5
|
14
|
-
end
|
15
|
-
use OmniAuth::Builder do
|
16
|
-
provider :fishbrain,
|
17
|
-
ENV.fetch('FISHBRAIN_CLIENT_ID'),
|
18
|
-
ENV.fetch('FISHBRAIN_CLIENT_SECRET')
|
19
|
-
end
|
20
|
-
|
21
|
-
get '/' do
|
22
|
-
haml :index
|
23
|
-
end
|
24
|
-
|
25
|
-
get '/auth/failure' do
|
26
|
-
haml :auth_failure
|
27
|
-
end
|
28
|
-
|
29
|
-
get '/auth/:provider/callback' do
|
30
|
-
haml :callback
|
31
|
-
end
|
32
|
-
|
33
|
-
run! if app_file == $PROGRAM_NAME
|
34
|
-
end
|
data/lib/omniauth/fishbrain.rb
DELETED
data/omniauth-fishbrain.gemspec
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require File.expand_path(
|
4
|
-
File.join('..', 'lib', 'omniauth', 'fishbrain', 'version'),
|
5
|
-
__FILE__
|
6
|
-
)
|
7
|
-
|
8
|
-
Gem::Specification.new do |gem|
|
9
|
-
gem.name = 'omniauth-fishbrain'
|
10
|
-
gem.version = OmniAuth::Fishbrain::VERSION
|
11
|
-
gem.license = 'MIT'
|
12
|
-
gem.summary = %(A Fishbrain strategy for OmniAuth 1.x)
|
13
|
-
gem.description = %(A Fishbrain strategy for OmniAuth 1.x. This allows you to login to Fishbrain with your ruby app.)
|
14
|
-
gem.authors = ['Erik Dalen']
|
15
|
-
gem.email = ['erik.dalen@fishbrain.com']
|
16
|
-
gem.homepage = 'https://github.com/fishbrain/omniauth-fishbrain'
|
17
|
-
|
18
|
-
gem.files = `git ls-files`.split("\n")
|
19
|
-
gem.require_paths = ['lib']
|
20
|
-
|
21
|
-
gem.required_ruby_version = '>= 2.2'
|
22
|
-
|
23
|
-
gem.add_runtime_dependency 'jwt', '~> 2.0'
|
24
|
-
gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.6'
|
25
|
-
end
|