blob: 57006155612c7c159658ff9648c10afee1b45a27 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
class UserSessionsController < ApplicationController
before_filter :authenticate_user!, except: [:new, :callback, :auth]
def show
@user = current_user
end
def new
end
def auth
redirect_to client.auth_code.authorize_url({
redirect_uri: callback_user_sessions_url
})
end
def callback
token = client.auth_code.get_token(params[:code], redirect_uri: callback_user_sessions_url).token
@user_session = UserSession.new
user = @user_session.authenticate(access_token: token)
if user && sign_in(user)
redirect_to root_path
else
@error = 'Invalid credentials'
render :new
end
end
def destroy
sign_out
redirect_to new_user_sessions_path
end
protected
def client
@client ||= ::OAuth2::Client.new(
GitlabCi.config.gitlab_server.app_id,
GitlabCi.config.gitlab_server.app_secret,
{
site: GitlabCi.config.gitlab_server.url,
authorize_url: 'oauth/authorize',
token_url: 'oauth/token'
}
)
end
end
|