omniauth-fishbrain 0.11.0 → 0.11.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aeee9cc6e162c2f7af87e9e888e5ee6512e3b0733db7e2ea62b36edc3e18f355
4
- data.tar.gz: c7e1e870026535bab621a989e3108065b87361b700b819117fc43422f247407b
3
+ metadata.gz: 1637721816e60eb974b77e438d29b21943e039b2ec6deb97fd621b055ea9b3f9
4
+ data.tar.gz: 7a25399a0f3cdff975adccbdb46fbf2679417978756fad9336be4e9be26fb9af
5
5
  SHA512:
6
- metadata.gz: 1581f15f1c259c32b65918776be71fecb61d8a301684168c6c203671f19fb36f13f246135e940b733412eec27afeb9cb065c70412323505792cd1dd8f1848bf8
7
- data.tar.gz: f2cb803f3e831ee2607c7ba93ac089d48fdfe3d5a3ec39c17bbfa46b5904862dc5d82c75984a6fcac60cd17569cb485a5206706348285133f1046fb88974dd24
6
+ metadata.gz: f54afe7e9de9d46401a3c6c387a63a42e2661ccaf81fe674fdd73c840db162a44360e1f4011020d8faa7b191a65ff9073909ef0c498d15a7e09ae544c3e9b35a
7
+ data.tar.gz: fce1acff0dbc7abbe47f4113c5abb978bd08e8bbc4d6fd59fc62bbe9eaa608caf5175e4490a8369c3f6fa74f81b8e714a5667159e23bbb81ce2e146e5eade613
@@ -30,11 +30,11 @@ In development/test/staging environments:
30
30
  ```ruby
31
31
  use OmniAuth::Builder do
32
32
  provider :fishbrain, ENV['FISHBRAIN_CLIENT_ID'], ENV['FISHBRAIN_CLIENT_SECRET'],
33
- user_pool_id: 'eu-west-1_K2uP41DlP',
33
+ user_pool_id: 'eu-west-1_WlBhbuD6e',
34
34
  client_options: {
35
35
  site: 'https://accounts-staging.fishbrain.com',
36
36
  }
37
- provider :fishbrain_id, user_pool_id: 'eu-west-1_K2uP41DlP'
37
+ provider :fishbrain_id, user_pool_id: 'eu-west-1_WlBhbuD6e'
38
38
  end
39
39
  ```
40
40
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAuth
4
4
  module Fishbrain
5
- VERSION = '0.11.0'
5
+ VERSION = '0.11.5'
6
6
  end
7
7
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'jwt'
5
+
6
+ module OmniAuth
7
+ module Fishbrain
8
+ class DecodeIdToken
9
+ AWS_REGION = 'eu-west-1'
10
+ USER_POOL_ID = 'eu-west-1_TKWveIcYu'
11
+
12
+ attr_reader :client_id, :aws_region, :user_pool_id, :jwt_leeway
13
+
14
+ def initialize(client_id, user_pool_id = USER_POOL_ID, aws_region = AWS_REGION)
15
+ @client_id = client_id
16
+ @user_pool_id = user_pool_id
17
+ @aws_region = aws_region
18
+ @jwt_leeway = 60
19
+ end
20
+
21
+ def decode(raw_id_token)
22
+ JWT.decode(raw_id_token, nil, true, decode_options).first
23
+ end
24
+
25
+ private
26
+
27
+ def decode_options
28
+ {
29
+ iss: iss,
30
+ aud: client_id,
31
+ verify_aud: false,
32
+ verify_expiration: true,
33
+ verify_iat: true,
34
+ verify_iss: true,
35
+ verify_not_before: true,
36
+ leeway: jwt_leeway,
37
+ algorithm: 'RS256',
38
+ jwks: jwks,
39
+ }
40
+ end
41
+
42
+ def iss
43
+ "https://cognito-idp.#{aws_region}.amazonaws.com/#{user_pool_id}"
44
+ end
45
+
46
+ def jwks
47
+ @_jwks ||= "#{iss}/.well-known/jwks.json"
48
+ .yield_self(&URI.method(:parse))
49
+ .yield_self(&Net::HTTP.method(:get))
50
+ .yield_self { |it| JSON.parse(it, symbolize_names: true) }
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'date'
4
3
  require 'json'
5
4
 
6
5
  module OmniAuth
@@ -9,15 +8,14 @@ module OmniAuth
9
8
  def premium_status
10
9
  return {} unless id_token['premium_status']
11
10
 
12
- JSON.parse id_token['premium_status']
11
+ JSON.parse(id_token['premium_status'])
13
12
  rescue JSON::ParserError
14
13
  {}
15
14
  end
16
15
 
17
16
  def premium?
18
- DateTime.rfc3339(premium_status['premium_end_date']) > DateTime.now
17
+ Time.xmlschema(premium_status['end_date']) > Time.new.utc
19
18
  rescue ArgumentError
20
- # if format was wrong
21
19
  false
22
20
  end
23
21
  end
@@ -7,11 +7,11 @@ module OmniAuth
7
7
  module Fishbrain
8
8
  module VerifiesIdToken
9
9
  def id_token
10
- @_id_token ||= begin
11
- return {} unless raw_id_token
12
-
13
- JWT.decode(raw_id_token, nil, true, decode_options).first
14
- end
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
15
  end
16
16
 
17
17
  def decode_options
@@ -16,7 +16,7 @@ module OmniAuth
16
16
  token_url: '/oauth2/token',
17
17
  auth_scheme: :basic_auth
18
18
  option :scope, 'email openid profile'
19
- option :user_pool_id, 'eu-west-1_5r0WbR8OH'
19
+ option :user_pool_id, 'eu-west-1_TKWveIcYu'
20
20
  option :aws_region, 'eu-west-1'
21
21
  option :jwt_leeway, 60
22
22
 
@@ -11,7 +11,7 @@ module OmniAuth
11
11
  include OmniAuth::Fishbrain::PremiumStatus
12
12
 
13
13
  option :name, 'fishbrain_id'
14
- option :user_pool_id, 'eu-west-1_5r0WbR8OH'
14
+ option :user_pool_id, 'eu-west-1_TKWveIcYu'
15
15
  option :client_id, nil
16
16
  option :aws_region, 'eu-west-1'
17
17
  option :jwt_leeway, 60
@@ -37,11 +37,10 @@ module OmniAuth
37
37
  end
38
38
 
39
39
  def callback_phase
40
- if raw_id_token
41
- id_token
42
- super
43
- else
40
+ if id_token.empty?
44
41
  fail! :missing_id_token
42
+ else
43
+ super
45
44
  end
46
45
  rescue JWT::ExpiredSignature
47
46
  fail! :invalid_id_token
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-fishbrain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Dalen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-02-27 00:00:00.000000000 Z
12
+ date: 2020-08-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jwt
@@ -51,6 +51,7 @@ files:
51
51
  - README.markdown
52
52
  - lib/omniauth-fishbrain.rb
53
53
  - lib/omniauth-fishbrain/version.rb
54
+ - lib/omniauth/fishbrain/decode_id_token.rb
54
55
  - lib/omniauth/fishbrain/premium_status.rb
55
56
  - lib/omniauth/fishbrain/verifies_id_token.rb
56
57
  - lib/omniauth/strategies/fishbrain.rb
@@ -67,15 +68,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
68
  requirements:
68
69
  - - ">="
69
70
  - !ruby/object:Gem::Version
70
- version: '0'
71
+ version: 2.5.0
71
72
  required_rubygems_version: !ruby/object:Gem::Requirement
72
73
  requirements:
73
74
  - - ">="
74
75
  - !ruby/object:Gem::Version
75
76
  version: '0'
76
77
  requirements: []
77
- rubyforge_project:
78
- rubygems_version: 2.7.6
78
+ rubygems_version: 3.0.3
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: OmniAuth strategy for Fishbrain