gamora 0.6.0 → 0.6.1

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: dac3585239f26c73703bedba78b8fb157fcae96e795606833510820dcc541635
4
- data.tar.gz: b12bd007f45d5b97861254c0e7418faa14554eadc31fc0b7fa196932abb8915d
3
+ metadata.gz: aa6a4fbbe3e75fdacdc78a5cf6635e0859cc459e4319446e65de3893b9c17959
4
+ data.tar.gz: 78182a8c53dd683fba71650fa5af83ec3637251903b1343722e27146aec5c042
5
5
  SHA512:
6
- metadata.gz: 4b824e97d834065f0beb2d0a6d30d343f02edb70d1cecbc7bcd598166474a32e71849b45e46289745ce2d279166a810ed9572cfe6688e48c0e6a9f496cb7e6dd
7
- data.tar.gz: 6fd882d104aa35374d94e40f1b98b9dc708e26689da28ec9a0736ad4f7b7cba6bf177ecc18ddc8e0c8c5303a087404ec95ead3a20cf8cc2405be0eb49128594b
6
+ metadata.gz: c5d719440c65a62611fddbc9153a5d0f64585d1f67d45a3b29b9eba82d02940ce63f776092f829c0a1b3a55c292b4fe94a8515a38ef9126d150e705c44b7799d
7
+ data.tar.gz: d6de59c853d9fd0b8369ac583aa0235007c4576f7684431441620e3da2e2ee16d6a1def3b5718eaceef443a7e2a1fb2188b7bad4bbaf471f3bad6ee061ef59af
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2022 Alejandro Gutiérrez
3
+ Copyright (c) 2023 Alejandro Gutiérrez
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -38,6 +38,41 @@ end
38
38
  To see the full list of configuration options please check your gamora
39
39
  initializer.
40
40
 
41
+ ## Mount Gamora Engine
42
+
43
+ In order to have the authorization and callback endpoints mount the
44
+ engine in the `config/routes.rb` file:
45
+
46
+ ```ruby
47
+ Rails.application.routes.draw do
48
+ ...
49
+ mount Gamora::Engine => "/auth"
50
+
51
+ ...
52
+ end
53
+ ```
54
+
55
+ This will enable the following routes in the parent application:
56
+
57
+ #### `gamora.authorization_path`
58
+
59
+ This endpoint will redirect users to the IDP generating url and query
60
+ params based on the configuration. This endpoint is called automatically
61
+ when the user is not logged in and the application requires users to be
62
+ authenticated.
63
+
64
+ #### `gamora.logout_path`
65
+
66
+ This endpoint allows users to be logged out from the application and the
67
+ IDP. It removes the access and refresh tokens and redirects to IDP in order
68
+ to force users to authenticate again.
69
+
70
+ #### `gamora.callback_path`
71
+
72
+ This endpoint is the responsible to received the auth code provided by
73
+ the IDP and generate and access token. This endpoint is called automatically
74
+ once the user authenticates successfully in the IDP.
75
+
41
76
  ## User authentication
42
77
 
43
78
  ### Web-based applications
@@ -1,7 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Gamora
2
4
  module AuthorizationUrl
3
5
  def authorization_url(params, extra_params = {})
4
- default_params = {
6
+ data =
7
+ default_params
8
+ .merge(extra_params)
9
+ .merge(authorization_params(params))
10
+ .compact_blank
11
+
12
+ Client.from_config.auth_code.authorize_url(data)
13
+ end
14
+
15
+ private
16
+
17
+ def default_params
18
+ {
5
19
  scope: Configuration.default_scope,
6
20
  theme: Configuration.default_theme,
7
21
  prompt: Configuration.default_prompt,
@@ -9,18 +23,8 @@ module Gamora
9
23
  branding: Configuration.default_branding,
10
24
  ui_locales: Configuration.ui_locales.call
11
25
  }
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
26
  end
21
27
 
22
- private
23
-
24
28
  def authorization_params(params)
25
29
  params.permit(
26
30
  :scope,
@@ -6,8 +6,8 @@ module Gamora
6
6
 
7
7
  def show
8
8
  redirect_to authorization_url(params),
9
- allow_other_host: true,
10
- status: :see_other
9
+ allow_other_host: true,
10
+ status: :see_other
11
11
  end
12
12
  end
13
13
  end
@@ -7,7 +7,6 @@ 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
-
11
10
  rescue OAuth2::Error
12
11
  render plain: "Invalid authorization code"
13
12
  end
@@ -9,8 +9,8 @@ module Gamora
9
9
  session[:refresh_token] = nil
10
10
 
11
11
  redirect_to authorization_url(params, { max_age: 0 }),
12
- allow_other_host: true,
13
- status: :see_other
12
+ allow_other_host: true,
13
+ status: :see_other
14
14
  end
15
15
  end
16
16
  end
@@ -47,6 +47,7 @@ module Gamora
47
47
 
48
48
  def resource_owner_claims(access_token)
49
49
  return {} if access_token.blank?
50
+
50
51
  resource_owner_claims!(access_token)
51
52
  end
52
53
 
@@ -9,6 +9,7 @@ module Gamora
9
9
 
10
10
  def validate_authentication!
11
11
  return if current_user.present?
12
+
12
13
  user_authentication_failed!
13
14
  end
14
15
 
@@ -16,6 +17,7 @@ module Gamora
16
17
  pattern = /^Bearer /
17
18
  header = request.headers["Authorization"]
18
19
  return unless header&.match(pattern)
20
+
19
21
  header.gsub(pattern, "")
20
22
  end
21
23
 
@@ -13,6 +13,7 @@ module Gamora
13
13
 
14
14
  def validate_authentication!
15
15
  return if current_user.present?
16
+
16
17
  session["gamora.origin"] = request.original_url
17
18
  user_authentication_failed!
18
19
  end
data/lib/gamora/client.rb CHANGED
@@ -2,10 +2,18 @@
2
2
 
3
3
  module Gamora
4
4
  class Client < OAuth2::Client
5
- def self.from_config
6
- new(
7
- Configuration.client_id,
8
- Configuration.client_secret,
5
+ class << self
6
+ def from_config
7
+ new(
8
+ Configuration.client_id,
9
+ Configuration.client_secret,
10
+ client_options
11
+ )
12
+ end
13
+
14
+ private
15
+
16
+ def client_options
9
17
  {
10
18
  site: Configuration.site,
11
19
  token_url: Configuration.token_url,
@@ -14,7 +22,7 @@ module Gamora
14
22
  userinfo_url: Configuration.userinfo_url,
15
23
  authorize_url: Configuration.authorize_url
16
24
  }
17
- )
25
+ end
18
26
  end
19
27
 
20
28
  def userinfo(access_token)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gamora
4
- VERSION = "0.6.0"
4
+ VERSION = "0.6.1"
5
5
  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.6.0
4
+ version: 0.6.1
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: 2023-01-11 00:00:00.000000000 Z
11
+ date: 2023-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  requirements: []
94
- rubygems_version: 3.3.7
94
+ rubygems_version: 3.4.17
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: OpenID Connect Relying Party for rails apps.