zaikio-oauth_client 0.10.0 → 0.11.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: 84383fd7b0b03f23cc671489124b6b8f90613cad840bd668080ea04c59a4ff54
4
- data.tar.gz: e7b8f6759983ffad763780b392be0500888affd117c1ccfb9f87449ed1b1a9de
3
+ metadata.gz: c3caeb6fd8b46df684ae2ead61a41965d33d0c8447576ca3dd4472e035917732
4
+ data.tar.gz: 7efeeb1977f82515ac60e41dfeec76a2e03867cead09e4e7bdee225f9e2d7051
5
5
  SHA512:
6
- metadata.gz: caae8092591d3d47a03ddf598d8da76d474cc45ff01e5799f140d8dbad3ca171294217ceddc1e0ffbc364f8efd3153c5222e51711afbd8f17d39daf1f01f409b
7
- data.tar.gz: 2759d26c2826f6cf06aba7c7673eaf2ee7cf30914ca4c965eefe99409efb575916c4fe0cfdde315ed64f95e20720b83712ae2d5bb3a9820dfedb908a9e38e094
6
+ metadata.gz: 49c66d7cee9b78180b46f5f75318e9cdab0e0ea04cf7bf349c09990ac337dc367e32fcf15f70a3728fa524a53ea3a5771e0c436b9902d4f7a023ad72a0b21adb
7
+ data.tar.gz: b82883c6b3b85dabe9759266bd5c5f4b338bb9917c3bd60696412e4651a23c45e73e296a600258aa7072ad5c417dd728742afecdba8a5f14b66a673ff836e0f4
data/README.md CHANGED
@@ -187,6 +187,11 @@ class ApplicationController < ActionController::Base
187
187
 
188
188
  main_app.root_path
189
189
  end
190
+
191
+ def error_path_for(error_code, description: nil)
192
+ # Handle error
193
+ main_app.root_path
194
+ end
190
195
  end
191
196
  ```
192
197
 
@@ -3,6 +3,8 @@ 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
+ opts[:state] ||= cookies.encrypted[:state] = SecureRandom.urlsafe_base64(32)
6
8
 
7
9
  plan = opts.delete(:plan)
8
10
  organization_id = opts.delete(:organization_id)
@@ -0,0 +1,4 @@
1
+ de:
2
+ zaikio:
3
+ oauth_client:
4
+ error_occured: "Beim Login ist ein Fehler aufgetreten: %{error} %{description}. Bitte versuche es nochmal."
@@ -1,6 +1,7 @@
1
1
  en:
2
2
  zaikio:
3
+ oauth_client:
4
+ error_occured: "An error occurred during login: %{error} %{description}. Please try again."
3
5
  forms:
4
6
  optional: Optional
5
7
  learn_more: Learn more
6
-
@@ -1,5 +1,6 @@
1
1
  require "oauth2"
2
2
 
3
+ require "zaikio/oauth_client/error"
3
4
  require "zaikio/oauth_client/engine"
4
5
  require "zaikio/oauth_client/configuration"
5
6
  require "zaikio/oauth_client/authenticatable"
@@ -5,7 +5,9 @@ module Zaikio
5
5
 
6
6
  def new
7
7
  opts = params.permit(:client_name, :show_signup, :force_login, :state)
8
+ opts[:redirect_with_error] = 1
8
9
  client_name = opts.delete(:client_name)
10
+ opts[:state] ||= cookies.encrypted[:state] = SecureRandom.urlsafe_base64(32)
9
11
 
10
12
  redirect_to oauth_client.auth_code.authorize_url(
11
13
  redirect_uri: approve_url(client_name),
@@ -15,6 +17,21 @@ module Zaikio
15
17
  end
16
18
 
17
19
  def approve
20
+ if params[:error].present?
21
+ redirect_to send(
22
+ respond_to?(:error_path_for) ? :error_path_for : :default_error_path_for,
23
+ params[:error],
24
+ description: params[:error_description]
25
+ ) and return
26
+ end
27
+
28
+ if cookies.encrypted[:state].present? && params[:state] != cookies.encrypted[:state]
29
+ return redirect_to send(
30
+ respond_to?(:error_path_for) ? :error_path_for : :default_error_path_for,
31
+ "invalid_state"
32
+ )
33
+ end
34
+
18
35
  access_token = create_access_token
19
36
 
20
37
  origin = cookies.encrypted[:origin]
@@ -31,6 +48,7 @@ module Zaikio
31
48
  def destroy
32
49
  access_token_id = cookies.encrypted[:zaikio_access_token_id]
33
50
  cookies.delete :zaikio_access_token_id
51
+ cookies.delete :state
34
52
 
35
53
  redirect_to send(
36
54
  respond_to?(:after_destroy_path_for) ? :after_destroy_path_for : :default_after_destroy_path_for,
@@ -87,6 +105,16 @@ module Zaikio
87
105
 
88
106
  main_app.root_path
89
107
  end
108
+
109
+ def default_error_path_for(error_code, description: nil)
110
+ raise Zaikio::OAuthClient::InvalidScopesError, description if error_code == "invalid_scope"
111
+
112
+ unless error_code == "access_denied"
113
+ flash[:alert] = I18n.t("zaikio.oauth_client.error_occured", error: error_code, description: description)
114
+ end
115
+
116
+ main_app.root_path
117
+ end
90
118
  end
91
119
  end
92
120
  end
@@ -0,0 +1,5 @@
1
+ module Zaikio
2
+ module OAuthClient
3
+ class InvalidScopesError < StandardError; end
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Zaikio
2
2
  module OAuthClient
3
- VERSION = "0.10.0".freeze
3
+ VERSION = "0.11.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.10.0
4
+ version: 0.11.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-15 00:00:00.000000000 Z
11
+ date: 2021-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -150,6 +150,7 @@ files:
150
150
  - app/jobs/zaikio/cleanup_access_tokens_job.rb
151
151
  - app/models/zaikio/access_token.rb
152
152
  - config/initializers/inflections.rb
153
+ - config/locales/de.yml
153
154
  - config/locales/en.yml
154
155
  - config/routes.rb
155
156
  - db/migrate/20190426155505_enable_postgres_extensions_for_uuids.rb
@@ -162,6 +163,7 @@ files:
162
163
  - lib/zaikio/oauth_client/client_configuration.rb
163
164
  - lib/zaikio/oauth_client/configuration.rb
164
165
  - lib/zaikio/oauth_client/engine.rb
166
+ - lib/zaikio/oauth_client/error.rb
165
167
  - lib/zaikio/oauth_client/test_helper.rb
166
168
  - lib/zaikio/oauth_client/version.rb
167
169
  homepage: https://github.com/zaikio/zaikio-oauth_client