Skip to content

Commit 1c3cd25

Browse files
author
Aleksei Burlakov
committed
Dev: add a new route /internal/auth to check if authenticated
The newer versions of hawk-apiserver need to check if the sessions is still logged in.
1 parent cc351d7 commit 1c3cd25

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2025 Aleksei Burlakov <aburlakov@suse.com>
2+
# See COPYING for license.
3+
4+
class InternalAuthController < ApplicationController
5+
# internal endpoint; no CSRF and no redirects
6+
skip_before_action :verify_authenticity_token
7+
8+
def show
9+
return head :forbidden unless request.local?
10+
11+
if logged_in?
12+
render json: { ok: true, user: current_user }, status: 200
13+
else
14+
render json: { ok: false }, status: 403
15+
end
16+
end
17+
end

hawk/config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@
191191
end
192192
end
193193

194+
get "/internal/auth", to: "internal_auth#show"
195+
194196
if Rails.env.production?
195197
match '*path' => 'errors#not_found', via: :all # if nothing else matches
196198
end

0 commit comments

Comments
 (0)