gamora 0.2.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/gamora/authorization_url.rb +37 -0
- data/app/controllers/gamora/authentication_controller.rb +5 -25
- data/app/controllers/gamora/callback_controller.rb +1 -0
- data/app/controllers/gamora/unauthentication_controller.rb +16 -0
- data/config/routes.rb +1 -0
- data/lib/gamora/authentication/base.rb +15 -1
- data/lib/gamora/configuration.rb +2 -0
- data/lib/gamora/version.rb +1 -1
- data/lib/generators/gamora/templates/gamora.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 563e700187ac79aef45f7d11aad774aee205f7917870f5431d3f1d6d63d7850b
|
4
|
+
data.tar.gz: 9817af7d6c4eb85abb6bdaa76d53efc0f1016f6516df95c674366b89ab920b49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34de3119b475580ec5b65cab413d8f6ca7aed17fe433542ea81c6ef5ba314a67d9a29c384dd2aaafc9a9ff267510efbf6649a33f43fb7d41a15a0d3b7c308661
|
7
|
+
data.tar.gz: 2848933923aee39b310b107e77c6ec219b6642f0bda21c0e61677fbf056f3f80629f0d9bed0dbb81ea2637483d333de77292a871d86a358f19d98e1bade10b69
|
@@ -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,32 +2,12 @@
|
|
2
2
|
|
3
3
|
module Gamora
|
4
4
|
class AuthenticationController < ApplicationController
|
5
|
-
|
6
|
-
redirect_to authorization_url, allow_other_host: true
|
7
|
-
end
|
8
|
-
|
9
|
-
private
|
5
|
+
include AuthorizationUrl
|
10
6
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
prompt: Configuration.default_prompt,
|
16
|
-
strategy: Configuration.default_strategy,
|
17
|
-
ui_locales: Configuration.ui_locales.call
|
18
|
-
}.merge(authorization_params).compact_blank)
|
19
|
-
end
|
20
|
-
|
21
|
-
def authorization_params
|
22
|
-
params.permit(
|
23
|
-
:scope,
|
24
|
-
:state,
|
25
|
-
:theme,
|
26
|
-
:prompt,
|
27
|
-
:max_age,
|
28
|
-
:strategy,
|
29
|
-
:ui_locales
|
30
|
-
)
|
7
|
+
def show
|
8
|
+
redirect_to authorization_url(params),
|
9
|
+
allow_other_host: true,
|
10
|
+
status: :see_other
|
31
11
|
end
|
32
12
|
end
|
33
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
@@ -47,12 +47,26 @@ module Gamora
|
|
47
47
|
|
48
48
|
def resource_owner_claims(access_token)
|
49
49
|
return {} if access_token.blank?
|
50
|
-
|
50
|
+
resource_owner_claims!(access_token)
|
51
|
+
end
|
52
|
+
|
53
|
+
def resource_owner_claims!(access_token)
|
54
|
+
Rails.cache.fetch(cache_key(access_token), cache_options) do
|
55
|
+
oauth_client.userinfo(access_token)
|
56
|
+
end
|
51
57
|
end
|
52
58
|
|
53
59
|
def oauth_client
|
54
60
|
Client.from_config
|
55
61
|
end
|
62
|
+
|
63
|
+
def cache_options
|
64
|
+
{ expires_in: Configuration.userinfo_cache_expires_in }
|
65
|
+
end
|
66
|
+
|
67
|
+
def cache_key(access_token)
|
68
|
+
"userinfo:#{Digest::SHA256.hexdigest(access_token)}"
|
69
|
+
end
|
56
70
|
end
|
57
71
|
end
|
58
72
|
end
|
data/lib/gamora/configuration.rb
CHANGED
@@ -13,8 +13,10 @@ 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"
|
16
17
|
mattr_accessor :default_theme, default: "default"
|
17
18
|
mattr_accessor :ui_locales, default: -> { I18n.locale }
|
19
|
+
mattr_accessor :userinfo_cache_expires_in, default: 0.seconds
|
18
20
|
|
19
21
|
def setup
|
20
22
|
yield(self) if block_given?
|
data/lib/gamora/version.rb
CHANGED
@@ -15,6 +15,8 @@ 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"
|
18
19
|
# config.default_theme = "default"
|
19
20
|
# config.ui_locales = -> { I18n.locale }
|
21
|
+
# config.userinfo_cache_expires_in = 0.seconds
|
20
22
|
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.
|
4
|
+
version: 0.5.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-
|
11
|
+
date: 2022-09-05 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
|