-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added View for SAML Login and Configuration
- Loading branch information
Siddarth R
committed
Jul 24, 2018
1 parent
ca400c8
commit f60b287
Showing
7 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class SamlIdpController < SamlIdp::IdpController | ||
layout false | ||
before_action :setup_saml_configuration | ||
|
||
private | ||
|
||
def idp_authenticate(email, password) | ||
User.find_and_check_user(email, password) ? User.find_active_user_by_email(email) : nil | ||
end | ||
|
||
def idp_make_saml_response(found_user) | ||
encode_response found_user | ||
end | ||
|
||
def idp_logout | ||
# user = User.by_email(saml_request.name_id) | ||
# user.logout | ||
end | ||
|
||
def setup_saml_configuration | ||
slug = params[:slug] | ||
org = Organisation.find_by_slug(slug) | ||
saml_url = "#{Figaro.env.gate_url}/#{slug}/saml" | ||
SamlIdp.configure do |config| | ||
config.x509_certificate = org.cert_key | ||
config.secret_key = org.cert_private_key | ||
config.organization_name = org.name | ||
config.organization_url = org.website | ||
config.base_saml_location = saml_url | ||
config.attribute_service_location = "#{saml_url}/attributes" | ||
config.single_service_post_location = "#{saml_url}/auth" | ||
config.single_logout_service_post_location = "#{saml_url}/logout" | ||
config.single_logout_service_redirect_location = "#{saml_url}/logout" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<!DOCTYPE html> | ||
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"> | ||
<head> | ||
<meta charset="UTF-8"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"/> | ||
<title>GoJek – Single Sign on</title> | ||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"/> | ||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous"> | ||
<style type="text/css"> | ||
#container { margin-top: 50px; } | ||
.login-header { | ||
padding: 20px; | ||
background-color: #d5d5d5; | ||
margin-bottom: 10px; | ||
border-radius: 4px 4px 0px 0px; | ||
} | ||
#login { | ||
background-color: #efefef; | ||
border-radius: 4px; | ||
} | ||
#login .login-header .fa-circle { color: #1190AB; } | ||
#login form { padding: 30px; padding-top: 15px; } | ||
#login_container { width: 100%; max-width: 430px; margin: auto; } | ||
</style> | ||
</head> | ||
<body> | ||
<div id="container" class="container-fluid"> | ||
<div class="row text-center"> | ||
<div id="login_container"> | ||
<%= image_tag("logo.png") %> | ||
<p>Single Sign-on Multifactor Authentication.</p> | ||
<div id="login"> | ||
<div class="login-header"> | ||
<h2>Login</h2> | ||
<span class="fa-stack fa-2x hidden-xs"> | ||
<i class="fa fa-circle fa-stack-2x"></i> | ||
<i class="fa fa-lock fa-stack-1x fa-inverse"></i> | ||
</span> | ||
</div> | ||
<%= form_tag auth_path, class: 'text-left' do %> | ||
<%= hidden_field_tag("SAMLRequest", params[:SAMLRequest]) %> | ||
<%= hidden_field_tag("RelayState", params[:RelayState]) %> | ||
<div class="form-group"> | ||
<%= label_tag :email %> | ||
<%= email_field_tag :email, params[:email], :autocapitalize => "off", :autocorrect => "off", :autofocus => "autofocus", :spellcheck => "false", :size => 30, :class => "email_pwd txt form-control" %> | ||
</div> | ||
<div class="form-group"> | ||
<%= label_tag "Google Authenticator Code" %> | ||
<%= password_field_tag :password, params[:password], :autocapitalize => "off", :autocorrect => "off", :spellcheck => "false", :size => 30, :class => "email_pwd txt form-control" %> | ||
</div> | ||
<%= submit_tag "Sign in", :class => "button big blueish btn btn-primary" %> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
SamlIdp.configure do |config| | ||
config.session_expiry = 86400 | ||
config.name_id.formats = { | ||
email_address: -> (principal) { principal.email_address }, | ||
transient: -> (principal) {principal.user_login_id}, | ||
persistent: -> (principal) {principal.user_login_id}, | ||
name: -> (principal) {principal.name}, | ||
} | ||
config.attributes = { | ||
'eduPersonPrincipalName' => { | ||
'name' => 'urn:oid:1.3.6.1.4.1.5923.1.1.1.6', | ||
'name_format' => 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri', | ||
'getter' => ->(principal) { "#{principal.email}" } | ||
}, | ||
EmailAddress: { getter: :email_address }, | ||
FirstName: { getter: :name }, | ||
LastName: { getter: :name } | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters