Skip to content

Commit

Permalink
Merge pull request #115 from opan/master
Browse files Browse the repository at this point in the history
Update authenticate_cas API
  • Loading branch information
giosakti authored Jul 18, 2018
2 parents 4fd0dcb + 7cf1073 commit 2c89ea3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

def setup_user; end

def render_404
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ def check_signed_in
redirect_to profile_path if signed_in?
end

def index

end
def index; end
end
20 changes: 8 additions & 12 deletions app/controllers/profile_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def regen_auth
redirect_to profile_path
end

def show

end
def show; end

def user_admin
@users = []
Expand Down Expand Up @@ -105,19 +103,20 @@ def authenticate_ms_chap


def authenticate_cas

username = User.authenticate_cas request.env["HTTP_AUTHORIZATION"]
user = User.find_by(user_login_id: username)

## cas-5.1.x expects {"@c":".SimplePrincipal","id":"casuser","attributes":{}}
## cas-5.2.x expects {"@c":".SimplePrincipal","id":"casuser","attributes":{}}
response_map = {
"@class":"org.apereo.cas.authentication.principal.SimplePrincipal",
"id" => username,
"attributes": {"backend": "gate-sso"}
'@class':'org.apereo.cas.authentication.principal.SimplePrincipal',
'id' => username,
'attributes': {'backend': 'gate-sso', 'email': user.try(:email), 'auth_token': user.try(:auth_key), 'admin': user.try(:admin)},
}

if username.present?
render json: response_map, status: :ok
else
response_map['attributes'] = nil
render json: response_map, status: 401
end
end
Expand Down Expand Up @@ -182,10 +181,7 @@ def update
redirect_to user_path
end

def user_edit


end
def user_edit; end

def public_key_update
@user = User.where(id: params[:id]).first
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ def google_oauth2
#
data = request.env['omniauth.auth']
domain = data['info']['email'].split('@').last

unless User.valid_domain? domain
return render text: 'Your domain is unauthorized', status: :unauthorized
end
@user = User.create_user(data.info['name'], data.info['email'])

if @user.persisted?
@user.generate_two_factor_auth
sign_in_and_redirect @user, event: :authentication
Expand Down
Empty file modified config/routes.rb
100755 → 100644
Empty file.

0 comments on commit 2c89ea3

Please sign in to comment.