Skip to content
代码片段 群组 项目
提交 c0057a9d 编辑于 作者: Pavel Shutsin's avatar Pavel Shutsin
浏览文件

Add bearer authorization to ActionCable

It can be used for API access when
session is not available
上级 d54b3894
No related branches found
No related tags found
无相关合并请求
......@@ -3,13 +3,14 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
include Logging
include Gitlab::Auth::AuthFinders
identified_by :current_user
public :request
def connect
self.current_user = find_user_from_session_store
self.current_user = find_user_from_bearer_token || find_user_from_session_store
end
private
......
......@@ -43,6 +43,16 @@
end
end
context 'when bearer header is provided' do
let(:user_pat) { create(:personal_access_token) }
it 'finds user by PAT' do
connect(ActionCable.server.config.mount_path, headers: { Authorization: "Bearer #{user_pat.token}" })
expect(connection.current_user).to eq(user_pat.user)
end
end
context 'when session cookie is not set' do
it 'sets current_user to nil' do
connect
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册