gamora 0.1.0 → 0.4.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: 2cd6b80cc6b032dda4a916030c007de815ab7bbe86b9206797310fad36c7a70f
4
- data.tar.gz: aad80d59d2dcf567445aade639916019cbc3e6570d3f9a73bde6bfd4647f26fe
3
+ metadata.gz: f5603bf759444fee16ea4536a746c0aa1b215cc3c07f3e9405513605febeebe6
4
+ data.tar.gz: dba68b8d99573682f59dcc8705594fd698f5bd8e102009864123d56e57fc1ca6
5
5
  SHA512:
6
- metadata.gz: 98b0c4b20abaecc2ed9042e6d04d565325b3fbc71a37f152520aec9f9f56043429843d13dd879415f961593dca7ee6f405b92f08ef85a122fe51813448e203bf
7
- data.tar.gz: 6518ea2fdb5ed87f69afc422bd38ca1a82a3aea6b313ea6abef5adb057366b5d0f6fc16d11b002ca6b8bede834c90cb126f38880b19dc53bcb8d0e67e27584ea
6
+ metadata.gz: 30b06a7d4dfa731b547f9615dbf24082a07e64312db427477768117bf0ec2668901ae3a9905a10abd1ceef827f78d7da1c34f618da7e9c64bc021cc73fb1dc63
7
+ data.tar.gz: c14b734316cbd4a67487744f265684732048443f02112d3361772f44efd8446e4cb73cf95b5ca01fb904a1bb505e2b0c8e2b3d7c72e6902f6f65a7e95f68a7eb
@@ -0,0 +1,37 @@
1
+ module Gamora
2
+ module AuthorizationUrl
3
+ def authorization_url(params, extra_params = {})
4
+ default_params = {
5
+ scope: Configuration.default_scope,
6
+ theme: Configuration.default_theme,
7
+ prompt: Configuration.default_prompt,
8
+ strategy: Configuration.default_strategy,
9
+ branding: Configuration.default_branding,
10
+ ui_locales: Configuration.ui_locales.call
11
+ }
12
+
13
+ data =
14
+ default_params.
15
+ merge(extra_params).
16
+ merge(authorization_params(params)).
17
+ compact_blank
18
+
19
+ Client.from_config.auth_code.authorize_url(data)
20
+ end
21
+
22
+ private
23
+
24
+ def authorization_params(params)
25
+ params.permit(
26
+ :scope,
27
+ :state,
28
+ :theme,
29
+ :prompt,
30
+ :max_age,
31
+ :strategy,
32
+ :branding,
33
+ :ui_locales
34
+ )
35
+ end
36
+ end
37
+ end
@@ -2,30 +2,12 @@
2
2
 
3
3
  module Gamora
4
4
  class AuthenticationController < ApplicationController
5
- def show
6
- redirect_to authorization_url, allow_other_host: true
7
- end
8
-
9
- private
5
+ include AuthorizationUrl
10
6
 
11
- def authorization_url
12
- Client.from_config.auth_code.authorize_url({
13
- scope: Configuration.default_scope,
14
- prompt: Configuration.default_prompt,
15
- strategy: Configuration.default_strategy,
16
- ui_locales: Configuration.ui_locales.call
17
- }.merge(authorization_params).compact_blank)
18
- end
19
-
20
- def authorization_params
21
- params.permit(
22
- :scope,
23
- :state,
24
- :prompt,
25
- :max_age,
26
- :strategy,
27
- :ui_locales
28
- )
7
+ def show
8
+ redirect_to authorization_url(params),
9
+ allow_other_host: true,
10
+ status: :see_other
29
11
  end
30
12
  end
31
13
  end
@@ -7,6 +7,7 @@ module Gamora
7
7
  session[:access_token] = access_token.token
8
8
  session[:refresh_token] = access_token.refresh_token
9
9
  redirect_to session.delete("gamora.origin") || main_app.root_path
10
+
10
11
  rescue OAuth2::Error
11
12
  render plain: "Invalid authorization code"
12
13
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gamora
4
+ class UnauthenticationController < ApplicationController
5
+ include AuthorizationUrl
6
+
7
+ def show
8
+ session[:access_token] = nil
9
+ session[:refresh_token] = nil
10
+
11
+ redirect_to authorization_url(params, { max_age: 0 }),
12
+ allow_other_host: true,
13
+ status: :see_other
14
+ end
15
+ end
16
+ end
data/config/routes.rb CHANGED
@@ -2,5 +2,6 @@
2
2
 
3
3
  Gamora::Engine.routes.draw do
4
4
  get "amco", to: "authentication#show", as: :authentication
5
+ get "logout", to: "unauthentication#show", as: :logout
5
6
  get "amco/callback", to: "callback#show", as: :callback
6
7
  end
@@ -13,6 +13,8 @@ module Gamora
13
13
  mattr_accessor :default_scope, default: "openid profile email"
14
14
  mattr_accessor :default_prompt, default: nil
15
15
  mattr_accessor :default_strategy, default: "default"
16
+ mattr_accessor :default_branding, default: "amco"
17
+ mattr_accessor :default_theme, default: "default"
16
18
  mattr_accessor :ui_locales, default: -> { I18n.locale }
17
19
 
18
20
  def setup
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gamora
4
- VERSION = "0.1.0"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -15,5 +15,7 @@ Gamora.setup do |config|
15
15
  # config.default_scope = "openid profile email"
16
16
  # config.default_prompt = nil
17
17
  # config.default_strategy = "default"
18
+ # config.default_branding = "amco"
19
+ # config.default_theme = "default"
18
20
  # config.ui_locales = -> { I18n.locale }
19
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamora
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alejandro Gutiérrez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-20 00:00:00.000000000 Z
11
+ date: 2022-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2
@@ -49,9 +49,11 @@ files:
49
49
  - MIT-LICENSE
50
50
  - README.md
51
51
  - Rakefile
52
+ - app/controllers/concerns/gamora/authorization_url.rb
52
53
  - app/controllers/gamora/application_controller.rb
53
54
  - app/controllers/gamora/authentication_controller.rb
54
55
  - app/controllers/gamora/callback_controller.rb
56
+ - app/controllers/gamora/unauthentication_controller.rb
55
57
  - app/models/gamora/application_record.rb
56
58
  - config/routes.rb
57
59
  - lib/gamora.rb