zaikio-oauth_client 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35a2d3f9ebe6c1f7eadc74624d9f9f1f0f8cd34aefb6ce9fff5cccb7b5fd5bd9
4
- data.tar.gz: 075dde605bc8835dc73cdfab45cf16181ab79af764105ab37a61d520d7bb2692
3
+ metadata.gz: 0ff245bb6a309f304b580e81ad30acc9a91916919697b2df717fdb884d3e4a25
4
+ data.tar.gz: c8db756a72615d02de42a58804e23b597f095e709506a6055008a8682cc72bbd
5
5
  SHA512:
6
- metadata.gz: 6ecc782ef623fee48306b46e348d06225e37eaae4f02444072a79f1477ca73394a5dce80628f16ccd374bb589cd588c249312981aec17d71349660ababe72428
7
- data.tar.gz: 4327a4b1f59e38fd290654485d3ab535ccb2acc9e4cc395d117025dc6865df8d2e49f1a7e9f5a29458270df26bed65d14835229199047ed218c90d4b3529fc02
6
+ metadata.gz: 45d03fc98118ae5c283139628d0b8b9eaf1dd9a5ddcf22a02f1a57d8052365190907627831992976d8607329e404a021516403000b54ee072fbd9bc155bb9a89
7
+ data.tar.gz: 6ecae0a7e65289cad9c6691dcdaf3179694db40df26cedefe93cecaf7b16b999617f7931cbbc112116744e418b333c787b4b5e426baf6f6db0591ff6a399e6e7
data/README.md CHANGED
@@ -36,32 +36,34 @@ mount Zaikio::OAuthClient::Engine => "/zaikio"
36
36
 
37
37
  ```rb
38
38
  # config/initializers/zaikio_oauth_client.rb
39
- Zaikio::OAuthClient.configure do |config|
40
- config.environment = :sandbox
41
-
42
- config.register_client :warehouse do |warehouse|
43
- warehouse.client_id = "52022d7a-7ba2-41ed-8890-97d88e6472f6"
44
- warehouse.client_secret = "ShiKTnHqEf3M8nyHQPyZgbz7"
45
- warehouse.default_scopes = %w[directory.person.r]
46
-
47
- warehouse.register_organization_connection do |org|
48
- org.default_scopes = %w[directory.organization.r]
39
+ Rails.application.reloader.to_prepare do
40
+ Zaikio::OAuthClient.configure do |config|
41
+ config.environment = :sandbox
42
+
43
+ config.register_client :warehouse do |warehouse|
44
+ warehouse.client_id = "52022d7a-7ba2-41ed-8890-97d88e6472f6"
45
+ warehouse.client_secret = "ShiKTnHqEf3M8nyHQPyZgbz7"
46
+ warehouse.default_scopes = %w[directory.person.r]
47
+
48
+ warehouse.register_organization_connection do |org|
49
+ org.default_scopes = %w[directory.organization.r]
50
+ end
49
51
  end
50
- end
51
52
 
52
- config.register_client :warehouse_goods_call_of do |warehouse_goods_call_of|
53
- warehouse_goods_call_of.client_id = "12345-7ba2-41ed-8890-97d88e6472f6"
54
- warehouse_goods_call_of.client_secret = "secret"
55
- warehouse_goods_call_of.default_scopes = %w[directory.person.r]
53
+ config.register_client :warehouse_goods_call_of do |warehouse_goods_call_of|
54
+ warehouse_goods_call_of.client_id = "12345-7ba2-41ed-8890-97d88e6472f6"
55
+ warehouse_goods_call_of.client_secret = "secret"
56
+ warehouse_goods_call_of.default_scopes = %w[directory.person.r]
56
57
 
57
- warehouse_goods_call_of.register_organization_connection do |org|
58
- org.default_scopes = %w[directory.organization.r]
58
+ warehouse_goods_call_of.register_organization_connection do |org|
59
+ org.default_scopes = %w[directory.organization.r]
60
+ end
59
61
  end
60
- end
61
62
 
62
- config.around_auth do |access_token, block|
63
- Zaikio::Hub.with_token(access_token.token) do
64
- block.call(access_token)
63
+ config.around_auth do |access_token, block|
64
+ Zaikio::Hub.with_token(access_token.token) do
65
+ block.call(access_token)
66
+ end
65
67
  end
66
68
  end
67
69
  end
data/Rakefile CHANGED
@@ -35,9 +35,7 @@ require 'rubocop/rake_task'
35
35
 
36
36
  namespace :test do
37
37
  desc 'Runs RuboCop on specified directories'
38
- RuboCop::RakeTask.new(:rubocop) do |task|
39
- task.fail_on_error = false
40
- end
38
+ RuboCop::RakeTask.new(:rubocop)
41
39
  end
42
40
 
43
41
  Rake::Task[:test].enhance ['test:rubocop']
@@ -3,7 +3,6 @@ module Zaikio
3
3
  class SubscriptionsController < ConnectionsController
4
4
  def new
5
5
  opts = params.permit(:client_name, :state, :plan, :organization_id)
6
- opts[:redirect_with_error] = 1
7
6
  opts[:state] ||= session[:state] = SecureRandom.urlsafe_base64(32)
8
7
 
9
8
  plan = opts.delete(:plan)
@@ -5,7 +5,7 @@ module Zaikio
5
5
  class AccessToken < ApplicationRecord
6
6
  self.table_name = "zaikio_access_tokens"
7
7
 
8
- def self.build_from_access_token(access_token, requested_scopes: nil) # rubocop:disable Metrics/AbcSize
8
+ def self.build_from_access_token(access_token, requested_scopes: nil)
9
9
  payload = JWT.decode(access_token.token, nil, false).first rescue {} # rubocop:disable Style/RescueModifier
10
10
  scopes = access_token.params["scope"].split(",")
11
11
  new(
@@ -37,7 +37,7 @@ module Zaikio
37
37
  where("expires_at <= :now AND created_at > :created_at_max",
38
38
  now: Time.current,
39
39
  created_at_max: Time.current - refresh_token_valid_for)
40
- .where("refresh_token IS NOT NULL")
40
+ .where.not(refresh_token: nil)
41
41
  .where.not(id: Zaikio::JWTAuth.revoked_token_ids)
42
42
  }
43
43
  scope :by_bearer, lambda { |bearer_id:, requested_scopes: [], bearer_type: "Person"|
@@ -49,7 +49,7 @@ module Zaikio
49
49
  get_access_token(**options_or_access_token)
50
50
  end
51
51
 
52
- return unless block_given?
52
+ return unless block
53
53
 
54
54
  if configuration.around_auth_block
55
55
  configuration.around_auth_block.call(access_token, block)
@@ -82,7 +82,7 @@ module Zaikio
82
82
 
83
83
  # Finds the best usable access token. Note that this token may have expired and
84
84
  # would require refreshing.
85
- def find_usable_access_token(client_name:, bearer_type:, bearer_id:, requested_scopes:)
85
+ def find_usable_access_token(client_name:, bearer_type:, bearer_id:, requested_scopes:) # rubocop:disable Metrics/MethodLength
86
86
  configuration.logger.debug "Try to fetch token for client_name: #{client_name}, "\
87
87
  "bearer #{bearer_type}/#{bearer_id}, requested_scopes: #{requested_scopes}"
88
88
 
@@ -117,9 +117,9 @@ module Zaikio
117
117
 
118
118
  def get_plain_scopes(scopes)
119
119
  regex = /^((Org|Per)\.)?(.*)$/
120
- scopes.map do |scope|
120
+ scopes.filter_map do |scope|
121
121
  (regex.match(scope) || [])[3]
122
- end.compact
122
+ end
123
123
  end
124
124
 
125
125
  private
@@ -4,8 +4,7 @@ module Zaikio
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  def new
7
- opts = params.permit(:client_name, :show_signup, :force_login, :state, :lang)
8
- opts[:redirect_with_error] = 1
7
+ opts = params.permit(:client_name, :show_signup, :prompt, :force_login, :state, :lang)
9
8
  opts[:lang] ||= I18n.locale if defined?(I18n)
10
9
  client_name = opts.delete(:client_name)
11
10
  opts[:state] ||= session[:state] = SecureRandom.urlsafe_base64(32)
@@ -17,7 +16,7 @@ module Zaikio
17
16
  )
18
17
  end
19
18
 
20
- def approve
19
+ def approve # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
21
20
  if params[:error].present?
22
21
  redirect_to send(
23
22
  respond_to?(:error_path_for) ? :error_path_for : :default_error_path_for,
@@ -20,7 +20,7 @@ module Zaikio
20
20
  client_secret,
21
21
  authorize_url: "oauth/authorize",
22
22
  token_url: "oauth/access_token",
23
- connection_opts: { headers: { "Accept": "application/json" } },
23
+ connection_opts: { headers: { Accept: "application/json" } },
24
24
  site: Zaikio::OAuthClient.configuration.host
25
25
  )
26
26
 
@@ -3,7 +3,7 @@ module Zaikio
3
3
  module TestHelper
4
4
  extend ActiveSupport::Concern
5
5
 
6
- class TestSessionController < ActionController::Base
6
+ class TestSessionController < ActionController::Base # rubocop:disable Rails/ApplicationController
7
7
  def show
8
8
  if session[params[:key]].nil?
9
9
  head :no_content
@@ -1,5 +1,5 @@
1
1
  module Zaikio
2
2
  module OAuthClient
3
- VERSION = "0.13.0".freeze
3
+ VERSION = "0.14.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zaikio-oauth_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zaikio GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-28 00:00:00.000000000 Z
11
+ date: 2021-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack