cohesive_marketplace_middleware 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/cohesive_marketplace_middleware/version.rb +1 -1
- data/lib/cohesive_marketplace_middleware.rb +15 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f25619e09f201a527087188d66b5f91ceb0a7070c76cfca92db3a39c6c5d4b8
|
4
|
+
data.tar.gz: 4624f274f1b9f529af6dd91de378dc193f70c1784c253a1d8a20698eb4913e2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05fc7672e47b2245f696d5422a5477c889694a7e1fafedfe091299f480b4ed51275fe08b4df6b09a2d6adc08b4cc58d56a8ad6607440b794d849d06af0f427a4
|
7
|
+
data.tar.gz: e838506ef7409bbe62797c21dc7dc3cd373f6d8ef0261236dd97d080b723a91ce66e48f7bd5e7ef53030cfd434f9532b45165aacd2b8492abacd20a1d97b6abe
|
data/Gemfile.lock
CHANGED
@@ -9,15 +9,19 @@ COHESIVE_MIDDLEWARE_LOGIN_PATH = "COHESIVE_MIDDLEWARE_LOGIN_PATH"
|
|
9
9
|
COHESIVE_MIDDLEWARE_LOGIN_PATH_DEFAULT = "/cohesive_login"
|
10
10
|
|
11
11
|
module CohesiveMarketplaceMiddleware
|
12
|
-
def
|
12
|
+
def self.get_cohesive_auth_details(env)
|
13
13
|
env[AUTH_DETAILS_ENV_KEY]
|
14
14
|
end
|
15
15
|
|
16
|
-
def collect_ignore_paths
|
16
|
+
def self.collect_ignore_paths
|
17
17
|
# Get the path prefixes to ignore from an environment variable.
|
18
18
|
ignore_path_prefix_string = ENV[COHESIVE_MIDDLEWARE_IGNORE_PATH_PREFIX]
|
19
|
-
|
20
|
-
|
19
|
+
result = []
|
20
|
+
if ignore_path_prefix_string && ignore_path_prefix_string != "nil"
|
21
|
+
# Split the prefixes into an array.
|
22
|
+
result = ignore_path_prefix_string.split(",")
|
23
|
+
end
|
24
|
+
|
21
25
|
# Output some information for debugging.
|
22
26
|
puts("Cohesive middleware ignoring paths: ", result)
|
23
27
|
result
|
@@ -31,12 +35,12 @@ module CohesiveMarketplaceMiddleware
|
|
31
35
|
# @return [void]
|
32
36
|
def initialize(app)
|
33
37
|
@app = app
|
34
|
-
@ignore_paths = collect_ignore_paths
|
38
|
+
@ignore_paths = CohesiveMarketplaceMiddleware.collect_ignore_paths
|
35
39
|
end
|
36
40
|
|
37
41
|
def call(env)
|
38
42
|
# Check if the current path should be ignored.
|
39
|
-
if !(@ignore_paths.any? { |prefix| env["REQUEST_PATH"].start_with?(prefix) })
|
43
|
+
if !(@ignore_paths.any? { |prefix| env["REQUEST_PATH"] && env["REQUEST_PATH"].start_with?(prefix) })
|
40
44
|
authorization_header = env["HTTP_AUTHORIZATION"]
|
41
45
|
if authorization_header&.start_with?("Bearer ")
|
42
46
|
token = authorization_header.sub("Bearer ", "")
|
@@ -62,17 +66,17 @@ module CohesiveMarketplaceMiddleware
|
|
62
66
|
# @return [void]
|
63
67
|
def initialize(app)
|
64
68
|
@app = app
|
65
|
-
@ignore_paths = collect_ignore_paths
|
69
|
+
@ignore_paths = CohesiveMarketplaceMiddleware.collect_ignore_paths
|
66
70
|
|
67
71
|
# Get the login redirect URI from an environment variable.
|
68
72
|
@redirect_uri = ENV[COHESIVE_MIDDLEWARE_LOGIN_PATH]
|
69
73
|
# Set a default URI if the environment variable is not set.
|
70
|
-
if @redirect_uri == ""
|
74
|
+
if !@redirect_uri || @redirect_uri == ""
|
71
75
|
@redirect_uri = COHESIVE_MIDDLEWARE_LOGIN_PATH_DEFAULT
|
72
76
|
end
|
73
77
|
|
74
78
|
# Add the login redirect URI to the list of ignored paths.
|
75
|
-
@ignore_paths.append(@redirect_uri)
|
79
|
+
@ignore_paths = @ignore_paths.append(@redirect_uri)
|
76
80
|
|
77
81
|
# Output some information for debugging.
|
78
82
|
puts("Cohesive middleware login redirect: ", @redirect_uri)
|
@@ -85,7 +89,7 @@ module CohesiveMarketplaceMiddleware
|
|
85
89
|
# @return [Array] A Rack-compatible response triplet.
|
86
90
|
def call(env)
|
87
91
|
# Check if the current path should be ignored.
|
88
|
-
if !(@ignore_paths.any? { |prefix| env["REQUEST_PATH"].start_with?(prefix) })
|
92
|
+
if !(@ignore_paths.any? { |prefix| env["REQUEST_PATH"] && prefix && env["REQUEST_PATH"].start_with?(prefix) })
|
89
93
|
# Create a new request object.
|
90
94
|
request = ActionDispatch::Request.new(env)
|
91
95
|
# Get the authentication token from the cookie.
|
@@ -101,7 +105,7 @@ module CohesiveMarketplaceMiddleware
|
|
101
105
|
end
|
102
106
|
else
|
103
107
|
# Redirect the user to the login page if the token is missing.
|
104
|
-
return [301, {"Location" =>
|
108
|
+
return [301, {"Location" => COHESIVE_MIDDLEWARE_LOGIN_PATH_DEFAULT, "Content-Type" => "text/plain"}, ["token not in cookie"]]
|
105
109
|
end
|
106
110
|
end
|
107
111
|
# Call the next middleware or application in the chain.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cohesive_marketplace_middleware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chinmay Relkar
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|