Commit 9028999c933a3db790ef4645474d7b04888a308f
1 parent
0df1cf7f
Exists in
master
and in
4 other branches
Use new OAuth classes
Showing
1 changed file
with
15 additions
and
9 deletions
Show diff stats
app/controllers/omniauth_callbacks_controller.rb
| @@ -18,33 +18,39 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController | @@ -18,33 +18,39 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController | ||
| 18 | def ldap | 18 | def ldap |
| 19 | # We only find ourselves here | 19 | # We only find ourselves here |
| 20 | # if the authentication to LDAP was successful. | 20 | # if the authentication to LDAP was successful. |
| 21 | - @user = Gitlab::LDAP::User.find_or_create(request.env["omniauth.auth"]) | 21 | + @user = Gitlab::LDAP::User.find_or_create(oauth) |
| 22 | @user.remember_me = true if @user.persisted? | 22 | @user.remember_me = true if @user.persisted? |
| 23 | - | ||
| 24 | sign_in_and_redirect(@user) | 23 | sign_in_and_redirect(@user) |
| 25 | end | 24 | end |
| 26 | 25 | ||
| 27 | private | 26 | private |
| 28 | 27 | ||
| 29 | def handle_omniauth | 28 | def handle_omniauth |
| 30 | - oauth = request.env['omniauth.auth'] | ||
| 31 | - provider, uid = oauth['provider'], oauth['uid'] | ||
| 32 | - | ||
| 33 | if current_user | 29 | if current_user |
| 34 | # Change a logged-in user's authentication method: | 30 | # Change a logged-in user's authentication method: |
| 35 | - current_user.extern_uid = uid | ||
| 36 | - current_user.provider = provider | 31 | + current_user.extern_uid = oauth['uid'] |
| 32 | + current_user.provider = oauth['provider'] | ||
| 37 | current_user.save | 33 | current_user.save |
| 38 | redirect_to profile_path | 34 | redirect_to profile_path |
| 39 | else | 35 | else |
| 40 | - @user = User.find_or_new_for_omniauth(oauth) | 36 | + @user = Gitlab::OAuth::User.find(oauth) |
| 37 | + | ||
| 38 | + # Create user if does not exist | ||
| 39 | + # and allow_single_sign_on is true | ||
| 40 | + if Gitlab.config.omniauth['allow_single_sign_on'] | ||
| 41 | + @user ||= Gitlab::OAuth::User.create(oauth) | ||
| 42 | + end | ||
| 41 | 43 | ||
| 42 | if @user | 44 | if @user |
| 43 | - sign_in_and_redirect @user | 45 | + sign_in_and_redirect(@user) |
| 44 | else | 46 | else |
| 45 | flash[:notice] = "There's no such user!" | 47 | flash[:notice] = "There's no such user!" |
| 46 | redirect_to new_user_session_path | 48 | redirect_to new_user_session_path |
| 47 | end | 49 | end |
| 48 | end | 50 | end |
| 49 | end | 51 | end |
| 52 | + | ||
| 53 | + def oauth | ||
| 54 | + @oauth ||= request.env['omniauth.auth'] | ||
| 55 | + end | ||
| 50 | end | 56 | end |