Skip to content

Commit 7128982

Browse files
committed
feat(sessions_controller): revoke access token passed to logout
1 parent 5b443b4 commit 7128982

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

app/controllers/auth/sessions_controller.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ def destroy
206206
end
207207
remove_session
208208

209+
token = bearer_token
210+
if token.present?
211+
access_token = Doorkeeper::AccessToken.by_token(token)
212+
access_token&.revoke if access_token && !access_token.revoked?
213+
end
214+
209215
# Only whitelisted URLs can redirect externally
210216
redirect_continue(params.permit(:continue)[:continue] || "/") do
211217
uri = current_authority.logout_url
@@ -216,6 +222,12 @@ def destroy
216222

217223
protected
218224

225+
def bearer_token
226+
pattern = /^Bearer /
227+
header = request.authorization
228+
header.gsub(pattern, '') if header&.match(pattern)
229+
end
230+
219231
def safe_params(authinfo)
220232
::ActionController::Parameters.new(authinfo).permit(
221233
:name, :first_name, :last_name, :email, :password, :password_confirmation, :metadata,

0 commit comments

Comments
 (0)