omniauth-applicaster 1.9.0 → 2.0.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2082b22a6f4f98d7ffabb53f47c992f357d551fa689692172d4b3c27600c810a
|
4
|
+
data.tar.gz: 46d156b5ede9274f2725a136d2af9658ae1f82d28f737415d0bd273f2a73b886
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b113f436fa3a9474913cf36d757fff9ab04695c4038e91ada024a22c6549f86b454129ac6ab4b5c8a8761f6d83a4362b54b114bddc50807796f47066e057697
|
7
|
+
data.tar.gz: 47260b3abf6278bdaa91bed92b1259c7f85c31fd1dbbe6ff24d197c52c83f02fee6769485e1570919cc1feda4116bcb3c2eba9c341f54b205c1e8a6fc8185760
|
data/README.md
CHANGED
@@ -23,6 +23,7 @@ See [Omniauth](https://github.com/intridea/omniauth) for setting up omniauth.
|
|
23
23
|
Applicaster::Accounts.configure do |config|
|
24
24
|
config.client_id = "my-service-uid"
|
25
25
|
config.client_secret = "my-service-secret"
|
26
|
+
config.request_proc = -> { Thread.current[:request] }
|
26
27
|
|
27
28
|
if Rails.env.development?
|
28
29
|
# Use local accounts service with Pow when in development
|
@@ -49,6 +50,12 @@ projects.
|
|
49
50
|
```ruby
|
50
51
|
class ApplicationController < ActionController::Base
|
51
52
|
include Applicaster::AuthHelpers
|
53
|
+
|
54
|
+
before_action :set_request_in_thread
|
55
|
+
|
56
|
+
def set_request_in_thread
|
57
|
+
Thread.current[:request] = request
|
58
|
+
end
|
52
59
|
end
|
53
60
|
```
|
54
61
|
|
@@ -25,6 +25,8 @@ module Applicaster
|
|
25
25
|
|
26
26
|
attribute :faraday_adapter, nil, default: :excon
|
27
27
|
|
28
|
+
# Add the request_proc attribute
|
29
|
+
attribute :request_proc, Proc, default: proc { nil }
|
28
30
|
|
29
31
|
def default_base_url
|
30
32
|
ENV["ACCOUNTS_BASE_URL"] || "https://accounts.applicaster.com/"
|
data/lib/applicaster/accounts.rb
CHANGED
@@ -45,6 +45,17 @@ module Applicaster
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
def current_request
|
49
|
+
config.request_proc.call if config.request_proc
|
50
|
+
end
|
51
|
+
|
52
|
+
def log_with_request_context(message)
|
53
|
+
request = current_request
|
54
|
+
log_message = "#{message}, IP: #{request&.remote_ip}, User Agent: #{request&.user_agent}"
|
55
|
+
|
56
|
+
Rails.logger.error(log_message)
|
57
|
+
end
|
58
|
+
|
48
59
|
def user_from_token(token)
|
49
60
|
Rails.logger.info("Fetching user with token: #{token}")
|
50
61
|
user = Applicaster::Accounts::User.new(
|
@@ -53,15 +64,15 @@ module Applicaster
|
|
53
64
|
.body
|
54
65
|
)
|
55
66
|
if user.nil?
|
56
|
-
Rails.logger.error("[Login Failed] -
|
67
|
+
Rails.logger.error("[Login Failed] - User fetch failed. Token: #{token}")
|
57
68
|
end
|
58
69
|
user
|
59
70
|
rescue Faraday::ClientError => e
|
60
71
|
if e.response && e.response[:status] == 401
|
61
|
-
|
72
|
+
log_with_request_context("[Login Failed] - Unauthorized access attempt detected. Invalid token: #{token}, Error: #{e.message}")
|
62
73
|
nil
|
63
74
|
else
|
64
|
-
|
75
|
+
log_with_request_context("[Login Failed] - Error fetching user. Token: #{token}, Error: #{e.message}")
|
65
76
|
raise
|
66
77
|
end
|
67
78
|
end
|
@@ -73,7 +84,7 @@ module Applicaster
|
|
73
84
|
.body
|
74
85
|
)
|
75
86
|
rescue Faraday::ResourceNotFound
|
76
|
-
|
87
|
+
log_with_request_context("[Login Failed] - User not found. ID: #{id}, Token: #{token}")
|
77
88
|
nil
|
78
89
|
end
|
79
90
|
|
@@ -110,7 +121,7 @@ module Applicaster
|
|
110
121
|
def user_data_from_omniauth(omniauth_credentials)
|
111
122
|
access_token(omniauth_credentials).get("/api/v1/users/current.json").parsed
|
112
123
|
rescue Faraday::ClientError => e
|
113
|
-
|
124
|
+
log_with_request_context("[Login Failed] - Failed to fetch user data from Omniauth. Error: #{e.message}")
|
114
125
|
raise
|
115
126
|
end
|
116
127
|
|
@@ -137,7 +148,7 @@ module Applicaster
|
|
137
148
|
.client_credentials
|
138
149
|
.get_token
|
139
150
|
rescue OAuth2::Error => e
|
140
|
-
|
151
|
+
log_with_request_context("[Login Failed] - Failed to get client credentials token. Error: #{e.message}")
|
141
152
|
raise
|
142
153
|
end
|
143
154
|
end
|
@@ -7,7 +7,7 @@ module Applicaster
|
|
7
7
|
|
8
8
|
def create
|
9
9
|
session[:omniauth_credentials] = omniauth_credentials
|
10
|
-
Rails.logger.info("Session created successfully for user. IP: #{request.remote_ip}, User Agent: #{request.user_agent}, Params: #{
|
10
|
+
Rails.logger.info("Session created successfully for user. IP: #{request.remote_ip}, User Agent: #{request.user_agent}, Params: #{params[:origin].inspect}")
|
11
11
|
|
12
12
|
redirect_to(session.delete(:path_before_login) || '/')
|
13
13
|
end
|
@@ -17,13 +17,12 @@ module Applicaster
|
|
17
17
|
Rails.logger.info("Session destroyed for user: #{user_email}. IP: #{request.remote_ip}, User Agent: #{request.user_agent}")
|
18
18
|
|
19
19
|
reset_session
|
20
|
-
redirect_to
|
20
|
+
redirect_to "/"
|
21
21
|
end
|
22
22
|
|
23
23
|
def failure
|
24
24
|
Rails.logger.error({
|
25
25
|
message: "[Login Failed] - Omniauth error with strategy '#{params[:strategy]}': #{params[:message]}",
|
26
|
-
origin: params[:origin],
|
27
26
|
IP: request.remote_ip,
|
28
27
|
UserAgent: request.user_agent,
|
29
28
|
Params: params[:origin],
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-applicaster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neer Friedman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|