onelogin 1.6.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +25 -0
- data/.gitignore +1 -0
- data/README.md +47 -5
- data/examples/Gemfile.lock +15 -11
- data/examples/events-to-csv.rb +5 -4
- data/lib/onelogin/api/apiexception.rb +3 -0
- data/lib/onelogin/api/client.rb +68 -3
- data/lib/onelogin/api/cursor.rb +5 -2
- data/lib/onelogin/version.rb +1 -1
- data/onelogin.gemspec +3 -2
- metadata +24 -116
- data/.travis.yml +0 -6
- data/examples/rails-custom-login-page/.gitignore +0 -45
- data/examples/rails-custom-login-page/.ruby-version +0 -1
- data/examples/rails-custom-login-page/Gemfile +0 -57
- data/examples/rails-custom-login-page/Gemfile.lock +0 -212
- data/examples/rails-custom-login-page/README.md +0 -137
- data/examples/rails-custom-login-page/Rakefile +0 -6
- data/examples/rails-custom-login-page/app/assets/config/manifest.js +0 -3
- data/examples/rails-custom-login-page/app/assets/images/.keep +0 -0
- data/examples/rails-custom-login-page/app/assets/javascripts/application.js +0 -18
- data/examples/rails-custom-login-page/app/assets/javascripts/cable.js +0 -13
- data/examples/rails-custom-login-page/app/assets/javascripts/channels/.keep +0 -0
- data/examples/rails-custom-login-page/app/assets/javascripts/dashboard.coffee +0 -3
- data/examples/rails-custom-login-page/app/assets/javascripts/home.coffee +0 -3
- data/examples/rails-custom-login-page/app/assets/javascripts/sessions.coffee +0 -3
- data/examples/rails-custom-login-page/app/assets/stylesheets/application.css +0 -15
- data/examples/rails-custom-login-page/app/assets/stylesheets/dashboard.scss +0 -3
- data/examples/rails-custom-login-page/app/assets/stylesheets/home.scss +0 -3
- data/examples/rails-custom-login-page/app/assets/stylesheets/sessions.scss +0 -3
- data/examples/rails-custom-login-page/app/channels/application_cable/channel.rb +0 -4
- data/examples/rails-custom-login-page/app/channels/application_cable/connection.rb +0 -4
- data/examples/rails-custom-login-page/app/controllers/application_controller.rb +0 -23
- data/examples/rails-custom-login-page/app/controllers/concerns/.keep +0 -0
- data/examples/rails-custom-login-page/app/controllers/dashboard_controller.rb +0 -10
- data/examples/rails-custom-login-page/app/controllers/home_controller.rb +0 -5
- data/examples/rails-custom-login-page/app/controllers/sessions_controller.rb +0 -46
- data/examples/rails-custom-login-page/app/controllers/users_controller.rb +0 -120
- data/examples/rails-custom-login-page/app/helpers/application_helper.rb +0 -2
- data/examples/rails-custom-login-page/app/helpers/dashboard_helper.rb +0 -28
- data/examples/rails-custom-login-page/app/helpers/home_helper.rb +0 -2
- data/examples/rails-custom-login-page/app/helpers/sessions_helper.rb +0 -87
- data/examples/rails-custom-login-page/app/helpers/users_helper.rb +0 -3
- data/examples/rails-custom-login-page/app/jobs/application_job.rb +0 -2
- data/examples/rails-custom-login-page/app/mailers/application_mailer.rb +0 -4
- data/examples/rails-custom-login-page/app/models/application_record.rb +0 -3
- data/examples/rails-custom-login-page/app/models/concerns/.keep +0 -0
- data/examples/rails-custom-login-page/app/views/dashboard/index.html.erb +0 -43
- data/examples/rails-custom-login-page/app/views/home/index.html.erb +0 -272
- data/examples/rails-custom-login-page/app/views/layouts/application.html.erb +0 -31
- data/examples/rails-custom-login-page/app/views/layouts/mailer.html.erb +0 -13
- data/examples/rails-custom-login-page/app/views/layouts/mailer.text.erb +0 -1
- data/examples/rails-custom-login-page/app/views/users/_form.html.erb +0 -1
- data/examples/rails-custom-login-page/app/views/users/_user.json.jbuilder +0 -2
- data/examples/rails-custom-login-page/app/views/users/edit.html.erb +0 -33
- data/examples/rails-custom-login-page/app/views/users/index.html.erb +0 -33
- data/examples/rails-custom-login-page/app/views/users/index.json.jbuilder +0 -1
- data/examples/rails-custom-login-page/app/views/users/new.html.erb +0 -60
- data/examples/rails-custom-login-page/app/views/users/onboard.html.erb +0 -54
- data/examples/rails-custom-login-page/app/views/users/show.html.erb +0 -17
- data/examples/rails-custom-login-page/app/views/users/show.json.jbuilder +0 -1
- data/examples/rails-custom-login-page/bin/bundle +0 -3
- data/examples/rails-custom-login-page/bin/rails +0 -9
- data/examples/rails-custom-login-page/bin/rake +0 -9
- data/examples/rails-custom-login-page/bin/setup +0 -38
- data/examples/rails-custom-login-page/bin/spring +0 -17
- data/examples/rails-custom-login-page/bin/update +0 -29
- data/examples/rails-custom-login-page/bin/yarn +0 -11
- data/examples/rails-custom-login-page/config/application.rb +0 -18
- data/examples/rails-custom-login-page/config/boot.rb +0 -3
- data/examples/rails-custom-login-page/config/cable.yml +0 -10
- data/examples/rails-custom-login-page/config/database.yml +0 -25
- data/examples/rails-custom-login-page/config/environment.rb +0 -5
- data/examples/rails-custom-login-page/config/environments/development.rb +0 -54
- data/examples/rails-custom-login-page/config/environments/production.rb +0 -91
- data/examples/rails-custom-login-page/config/environments/test.rb +0 -42
- data/examples/rails-custom-login-page/config/initializers/application_controller_renderer.rb +0 -8
- data/examples/rails-custom-login-page/config/initializers/assets.rb +0 -14
- data/examples/rails-custom-login-page/config/initializers/backtrace_silencers.rb +0 -7
- data/examples/rails-custom-login-page/config/initializers/cookies_serializer.rb +0 -5
- data/examples/rails-custom-login-page/config/initializers/filter_parameter_logging.rb +0 -4
- data/examples/rails-custom-login-page/config/initializers/inflections.rb +0 -16
- data/examples/rails-custom-login-page/config/initializers/mime_types.rb +0 -4
- data/examples/rails-custom-login-page/config/initializers/onelogin.rb +0 -6
- data/examples/rails-custom-login-page/config/initializers/wrap_parameters.rb +0 -14
- data/examples/rails-custom-login-page/config/locales/en.yml +0 -33
- data/examples/rails-custom-login-page/config/puma.rb +0 -56
- data/examples/rails-custom-login-page/config/routes.rb +0 -23
- data/examples/rails-custom-login-page/config/secrets.yml.sample +0 -38
- data/examples/rails-custom-login-page/config/spring.rb +0 -6
- data/examples/rails-custom-login-page/config.ru +0 -5
- data/examples/rails-custom-login-page/db/seeds.rb +0 -7
- data/examples/rails-custom-login-page/lib/assets/.keep +0 -0
- data/examples/rails-custom-login-page/lib/tasks/.keep +0 -0
- data/examples/rails-custom-login-page/package.json +0 -5
- data/examples/rails-custom-login-page/public/404.html +0 -67
- data/examples/rails-custom-login-page/public/422.html +0 -67
- data/examples/rails-custom-login-page/public/500.html +0 -66
- data/examples/rails-custom-login-page/public/apple-touch-icon-precomposed.png +0 -0
- data/examples/rails-custom-login-page/public/apple-touch-icon.png +0 -0
- data/examples/rails-custom-login-page/public/favicon.ico +0 -0
- data/examples/rails-custom-login-page/public/robots.txt +0 -1
- data/examples/rails-custom-login-page/test/application_system_test_case.rb +0 -5
- data/examples/rails-custom-login-page/test/controllers/.keep +0 -0
- data/examples/rails-custom-login-page/test/controllers/dashboard_controller_test.rb +0 -9
- data/examples/rails-custom-login-page/test/controllers/home_controller_test.rb +0 -9
- data/examples/rails-custom-login-page/test/controllers/sessions_controller_test.rb +0 -7
- data/examples/rails-custom-login-page/test/controllers/users_controller_test.rb +0 -48
- data/examples/rails-custom-login-page/test/fixtures/.keep +0 -0
- data/examples/rails-custom-login-page/test/fixtures/files/.keep +0 -0
- data/examples/rails-custom-login-page/test/helpers/.keep +0 -0
- data/examples/rails-custom-login-page/test/integration/.keep +0 -0
- data/examples/rails-custom-login-page/test/mailers/.keep +0 -0
- data/examples/rails-custom-login-page/test/models/.keep +0 -0
- data/examples/rails-custom-login-page/test/system/.keep +0 -0
- data/examples/rails-custom-login-page/test/test_helper.rb +0 -9
- data/examples/rails-custom-login-page/vendor/.keep +0 -0
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
class UsersController < ApplicationController
|
|
2
|
-
|
|
3
|
-
before_action :require_current_user, except: [:new, :create, :onboard, :activate]
|
|
4
|
-
before_action :set_user, only: [:show, :edit, :update, :destroy]
|
|
5
|
-
|
|
6
|
-
# GET /users
|
|
7
|
-
# GET /users.json
|
|
8
|
-
def index
|
|
9
|
-
@users = api_client.get_users.take(25) # only fetch the first 50 users
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# GET /users/1
|
|
13
|
-
# GET /users/1.json
|
|
14
|
-
def show
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# GET /users/new
|
|
18
|
-
def new
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# GET /users/1/edit
|
|
22
|
-
def edit
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# POST /users
|
|
26
|
-
# POST /users.json
|
|
27
|
-
def create
|
|
28
|
-
# Create a user
|
|
29
|
-
user = api_client.create_user(user_params)
|
|
30
|
-
# Update custom attributes
|
|
31
|
-
api_client.set_custom_attribute_to_user(user.id, custom_user_params)
|
|
32
|
-
# Set status to unactivated
|
|
33
|
-
api_client.update_user(user.id, status: 0)
|
|
34
|
-
|
|
35
|
-
if api_client.error
|
|
36
|
-
puts api_client.error_description
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
redirect_to onboard_path, notice: 'User has been created with status set to unactivated'
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# GET /onboard
|
|
43
|
-
def onboard
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# POST /activate
|
|
47
|
-
def activate
|
|
48
|
-
# Search for a user with this email address
|
|
49
|
-
@user = api_client.get_users(email: user_params[:email]).first
|
|
50
|
-
|
|
51
|
-
unless @user && verify_dob && verify_ssn
|
|
52
|
-
return redirect_to onboard_path, notice: "User #{user_params[:email]} was not verified"
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# Update password
|
|
56
|
-
unless api_client.set_password_using_clear_text(@user.id, user_params[:password], user_params[:password])
|
|
57
|
-
return redirect_to onboard_path, notice: "Password update failed. #{api_client.error_description}"
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# Activate user
|
|
61
|
-
api_client.update_user(@user.id, status: 1)
|
|
62
|
-
|
|
63
|
-
# Redirect to login page
|
|
64
|
-
redirect_to home_index_path
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# Verify dob and ssn match
|
|
68
|
-
def verify_ssn
|
|
69
|
-
@user.custom_attributes["custom_ssn"].eql? (custom_user_params[:custom_ssn])
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def verify_dob
|
|
73
|
-
@user.custom_attributes["custom_dob"].eql? (custom_user_params[:custom_dob])
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# PATCH/PUT /users/1
|
|
77
|
-
# PATCH/PUT /users/1.json
|
|
78
|
-
def update
|
|
79
|
-
# update the user
|
|
80
|
-
api_client.update_user(params[:id], user_params)
|
|
81
|
-
|
|
82
|
-
# update custom attributes
|
|
83
|
-
api_client.set_custom_attribute_to_user(params[:id], custom_user_params)
|
|
84
|
-
|
|
85
|
-
respond_to do |format|
|
|
86
|
-
unless api_client.error
|
|
87
|
-
format.html { redirect_to user_path(params[:id]), notice: 'User was successfully updated.' }
|
|
88
|
-
format.json { render :show, status: :ok, location: @user }
|
|
89
|
-
else
|
|
90
|
-
format.html { render :edit }
|
|
91
|
-
format.json { render json: @user.errors, status: :unprocessable_entity }
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
# DELETE /users/1
|
|
97
|
-
# DELETE /users/1.json
|
|
98
|
-
def destroy
|
|
99
|
-
@user.destroy
|
|
100
|
-
respond_to do |format|
|
|
101
|
-
format.html { redirect_to users_url, notice: 'User was successfully destroyed.' }
|
|
102
|
-
format.json { head :no_content }
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
private
|
|
107
|
-
|
|
108
|
-
def set_user
|
|
109
|
-
@user = api_client.get_user(params[:id])
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
# Never trust parameters from the scary internet, only allow the white list through.
|
|
113
|
-
def user_params
|
|
114
|
-
params.permit(:firstname, :lastname, :email, :phone, :username, :password)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def custom_user_params
|
|
118
|
-
params.permit(:custom_field, :custom_dob, :custom_ssn)
|
|
119
|
-
end
|
|
120
|
-
end
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
module DashboardHelper
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
# Get a list of app for the current user
|
|
5
|
-
#
|
|
6
|
-
def user_apps
|
|
7
|
-
api_client.get_user_apps(current_user_id)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
#
|
|
11
|
-
# Get a list of roles for the current user
|
|
12
|
-
#
|
|
13
|
-
def user_roles
|
|
14
|
-
role_ids = api_client.get_user_roles(current_user_id)
|
|
15
|
-
|
|
16
|
-
roles.map do |role|
|
|
17
|
-
role if role_ids.include?(role.id)
|
|
18
|
-
end.compact
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
#
|
|
22
|
-
# Get a list of all roles in onelogin account
|
|
23
|
-
#
|
|
24
|
-
def roles
|
|
25
|
-
@roles ||= api_client.get_roles
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
end
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
module SessionsHelper
|
|
2
|
-
|
|
3
|
-
def log_in(username, password)
|
|
4
|
-
response = api_client.create_session_login_token({
|
|
5
|
-
'username_or_email' => username,
|
|
6
|
-
'password' => password,
|
|
7
|
-
'subdomain' => ONELOGIN_SUBDOMAIN,
|
|
8
|
-
},
|
|
9
|
-
request.base_url # included for CORS session cookie request
|
|
10
|
-
)
|
|
11
|
-
return { error: api_client.error_description } unless response
|
|
12
|
-
|
|
13
|
-
if response.is_a? OneLogin::Api::Models::SessionTokenMFAInfo
|
|
14
|
-
session[:state_token] = response.state_token
|
|
15
|
-
{
|
|
16
|
-
requires_mfa: true,
|
|
17
|
-
devices: response.devices
|
|
18
|
-
}
|
|
19
|
-
else
|
|
20
|
-
create_session(response.user)
|
|
21
|
-
{
|
|
22
|
-
requires_mfa: false,
|
|
23
|
-
session_token: response.session_token
|
|
24
|
-
}
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def verify_mfa(device_id, otp_token)
|
|
29
|
-
response = api_client.get_session_token_verified(
|
|
30
|
-
device_id,
|
|
31
|
-
session[:state_token],
|
|
32
|
-
otp_token,
|
|
33
|
-
request.base_url
|
|
34
|
-
)
|
|
35
|
-
return nil unless response
|
|
36
|
-
|
|
37
|
-
create_session(response.user)
|
|
38
|
-
{
|
|
39
|
-
session_token: response.session_token
|
|
40
|
-
}
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def create_session(user)
|
|
44
|
-
session[:user] = user
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def log_out
|
|
48
|
-
return unless current_user
|
|
49
|
-
api_client.log_user_out(current_user_id)
|
|
50
|
-
session.delete(:user)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def current_user
|
|
54
|
-
session[:user]
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def current_user_id
|
|
58
|
-
session[:user]['id'] if current_user
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def validate_user(username)
|
|
62
|
-
user = api_client.get_users(username: username).first
|
|
63
|
-
|
|
64
|
-
if user
|
|
65
|
-
session[:user_id] = user.id
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
user
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def get_mfa_devices(user_id)
|
|
72
|
-
devices = api_client.get_enrolled_factors(user_id)
|
|
73
|
-
|
|
74
|
-
# only return devices that dont need a trigger.
|
|
75
|
-
# i.e. this sample does not support push yet
|
|
76
|
-
devices.select {|d| d.needs_trigger == true }
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def verify_token(device_id, mfa_token)
|
|
80
|
-
puts "VERIFY MFA TOKEN User:#{session[:user_id]}, Device:#{device_id}, Token:#{mfa_token}"
|
|
81
|
-
api_client.verify_factor(session[:user_id], device_id, mfa_token)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def set_password(user_id, password)
|
|
85
|
-
api_client.set_password_using_clear_text(user_id, password, password)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
File without changes
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
<div class="jumbotron">
|
|
2
|
-
<h1>Dashboard</h1>
|
|
3
|
-
<p>
|
|
4
|
-
You must be authenticated to see this page so if you're seeing it then
|
|
5
|
-
everything worked as expected 🎉
|
|
6
|
-
</p>
|
|
7
|
-
<p>
|
|
8
|
-
<a href="/users">List Users</a> | <a href="/logout">Log Out</a>
|
|
9
|
-
</p>
|
|
10
|
-
</div>
|
|
11
|
-
|
|
12
|
-
<div class="container">
|
|
13
|
-
<div class="row">
|
|
14
|
-
<div class="col-sm">
|
|
15
|
-
<h2>Apps</h2>
|
|
16
|
-
<ul class="list-group">
|
|
17
|
-
<% url_base = CUSTOM_DOMAIN || ONELOGIN_SUBDOMAIN + ".onelogin.com" %>
|
|
18
|
-
<%@apps.each do |app|%>
|
|
19
|
-
<li class="list-group-item"><a target="_blank" href="https://<%= url_base %>/launch/<%= app.id %>"><%= app.name %></a></li>
|
|
20
|
-
<%end%>
|
|
21
|
-
</ul>
|
|
22
|
-
</div>
|
|
23
|
-
<div class="col-sm">
|
|
24
|
-
<h2>Roles</h2>
|
|
25
|
-
<ul class="list-group">
|
|
26
|
-
<%@roles.each do |role|%>
|
|
27
|
-
<li class="list-group-item"><%= role.name %></li>
|
|
28
|
-
<%end%>
|
|
29
|
-
</ul>
|
|
30
|
-
|
|
31
|
-
<br/>
|
|
32
|
-
|
|
33
|
-
<h2>Profile</h2>
|
|
34
|
-
<ul class="list-group">
|
|
35
|
-
<%current_user.each do |k, v|%>
|
|
36
|
-
<li class="list-group-item">
|
|
37
|
-
<b><%= k%>:</b> <%= v%>
|
|
38
|
-
</li>
|
|
39
|
-
<%end%>
|
|
40
|
-
</ul>
|
|
41
|
-
</div>
|
|
42
|
-
</div>
|
|
43
|
-
</div>
|
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
<div class="jumbotron">
|
|
2
|
-
<p>This is a simple demo of how to authenticate a user and handle MFA when required</p>
|
|
3
|
-
</div>
|
|
4
|
-
|
|
5
|
-
<div class="container">
|
|
6
|
-
<div class="row">
|
|
7
|
-
<div class="col-sm">
|
|
8
|
-
</div>
|
|
9
|
-
<div class="col-sm">
|
|
10
|
-
|
|
11
|
-
<div class="alert alert-danger message" role="alert">
|
|
12
|
-
</div>
|
|
13
|
-
|
|
14
|
-
<% url_base = CUSTOM_DOMAIN || ONELOGIN_SUBDOMAIN + ".onelogin.com" %>
|
|
15
|
-
<% url_create_session = "https://" + url_base + "/session_via_api_token" %>
|
|
16
|
-
|
|
17
|
-
<form action="<%= url_create_session %>" method="post" class="cookie-session-post-form">
|
|
18
|
-
<input type="hidden" id="cookie_session_token" name="session_token" value="">
|
|
19
|
-
<input id="auth_token" type="hidden">
|
|
20
|
-
<button type="submit">Creating Session ...</button>
|
|
21
|
-
</form>
|
|
22
|
-
|
|
23
|
-
<%= form_tag("/login", method: "post", class: 'login-form') do %>
|
|
24
|
-
<div class="form-group">
|
|
25
|
-
<label for="username">Username</label>
|
|
26
|
-
<%= text_field_tag :username, nil, placeholder: 'Enter Username', class: 'form-control' %>
|
|
27
|
-
</div>
|
|
28
|
-
<div class="form-group">
|
|
29
|
-
<label for="password">Password</label>
|
|
30
|
-
<%= password_field_tag :password, nil, placeholder: 'Enter Password', class: 'form-control' %>
|
|
31
|
-
</div>
|
|
32
|
-
<button type="submit" class="btn btn-primary">Login</button>
|
|
33
|
-
<hr/>
|
|
34
|
-
<a href="#" class="forgot">Forgot Password</a> | <a href="/signup">Sign Up</a>
|
|
35
|
-
<% end %>
|
|
36
|
-
|
|
37
|
-
<%= form_tag("/verify_mfa", method: "post", class: 'mfa-form') do %>
|
|
38
|
-
<div class="form-group">
|
|
39
|
-
<label for="device_id">MFA Device</label>
|
|
40
|
-
<%= select_tag :device_id, nil, {:class => 'form-control'} %>
|
|
41
|
-
</div>
|
|
42
|
-
<div class="form-group">
|
|
43
|
-
<label for="otp_token">Token</label>
|
|
44
|
-
<%= text_field_tag :otp_token, nil, placeholder: 'Enter Token', class: 'form-control' %>
|
|
45
|
-
</div>
|
|
46
|
-
<button type="submit" class="btn btn-primary">Verify Token</button>
|
|
47
|
-
<% end %>
|
|
48
|
-
|
|
49
|
-
<%= form_tag("/forgot_password", method: "post", class: 'forgot-password-form') do %>
|
|
50
|
-
<div class="form-group">
|
|
51
|
-
<label for="forgot_username">Username</label>
|
|
52
|
-
<%= text_field_tag :forgot_username, nil, placeholder: 'Enter Username', class: 'form-control' %>
|
|
53
|
-
</div>
|
|
54
|
-
<button type="submit" class="btn btn-primary">Reset Password</button> or <a href="/">Login</a>
|
|
55
|
-
<% end %>
|
|
56
|
-
|
|
57
|
-
<%= form_tag("/reset_password", method: "post", class: 'reset-password-form') do %>
|
|
58
|
-
<div class="form-group">
|
|
59
|
-
<label for="reset_device_id">MFA Device</label>
|
|
60
|
-
<%= select_tag :reset_device_id, nil, {:class => 'form-control'} %>
|
|
61
|
-
</div>
|
|
62
|
-
<div class="form-group">
|
|
63
|
-
<label for="reset_otp_token">Token</label>
|
|
64
|
-
<%= text_field_tag :reset_otp_token, nil, placeholder: 'Enter Token', class: 'form-control' %>
|
|
65
|
-
</div>
|
|
66
|
-
<div class="form-group">
|
|
67
|
-
<label for="new_password">New Password</label>
|
|
68
|
-
<%= password_field_tag :new_password, nil, placeholder: 'Enter New Password', class: 'form-control' %>
|
|
69
|
-
</div>
|
|
70
|
-
<button type="submit" class="btn btn-primary">Save Password</button>
|
|
71
|
-
<% end %>
|
|
72
|
-
|
|
73
|
-
<form method="POST" action="" id="sp"></form>
|
|
74
|
-
|
|
75
|
-
</div>
|
|
76
|
-
<div class="col-sm">
|
|
77
|
-
</div>
|
|
78
|
-
</div>
|
|
79
|
-
</div>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
<script type="text/javascript">
|
|
85
|
-
|
|
86
|
-
var ONELOGIN_SUBDOMAIN = "<%= ONELOGIN_SUBDOMAIN %>";
|
|
87
|
-
var CUSTOM_DOMAIN = "<%= CUSTOM_DOMAIN %>";
|
|
88
|
-
var COOKIE_VIA_POST_FORM = <%= COOKIE_VIA_POST_FORM || false %>;
|
|
89
|
-
|
|
90
|
-
function makeCors(session_token) {
|
|
91
|
-
var xhr = new XMLHttpRequest();
|
|
92
|
-
xhr.withCredentials = true;
|
|
93
|
-
method = "POST";
|
|
94
|
-
if (CUSTOM_DOMAIN) {
|
|
95
|
-
var url = "https://" + CUSTOM_DOMAIN + "/session_via_api_token";
|
|
96
|
-
} else {
|
|
97
|
-
var url = "https://" + ONELOGIN_SUBDOMAIN + ".onelogin.com/session_via_api_token";
|
|
98
|
-
}
|
|
99
|
-
xhr.open(method, url, true);
|
|
100
|
-
xhr.setRequestHeader("Content-Type", "application/json");
|
|
101
|
-
body = {"session_token": session_token};
|
|
102
|
-
xhr.onreadystatechange = function () {
|
|
103
|
-
if(xhr.readyState === 4 && xhr.status === 200) {
|
|
104
|
-
if(getUrlParameter("origin")){
|
|
105
|
-
// If there is an origin SP then redirect to it
|
|
106
|
-
redirectToSP()
|
|
107
|
-
} else{
|
|
108
|
-
// Otherwise redirect to the main dashboard
|
|
109
|
-
window.location.href = '/dashboard';
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
xhr.send(JSON.stringify(body));
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
function sendPostForm(session_token){
|
|
117
|
-
$(".cookie-session-post-form").show();
|
|
118
|
-
$("#cookie_session_token").val(session_token);
|
|
119
|
-
$(".cookie-session-post-form").submit();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function showAlert(type, message){
|
|
123
|
-
$(".message").removeClass("alert-danger").removeClass("alert-success");
|
|
124
|
-
$(".message").addClass("alert-" + type).text(message).show();
|
|
125
|
-
$(".message").show();
|
|
126
|
-
}
|
|
127
|
-
function hideAlert(){
|
|
128
|
-
$(".message").hide();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function getUrlParameter(sParam) {
|
|
132
|
-
var sPageURL = window.location.search.substring(1),
|
|
133
|
-
sURLVariables = sPageURL.split('&'),
|
|
134
|
-
sParameterName,
|
|
135
|
-
i;
|
|
136
|
-
|
|
137
|
-
for (i = 0; i < sURLVariables.length; i++) {
|
|
138
|
-
sParameterName = sURLVariables[i].split('=');
|
|
139
|
-
|
|
140
|
-
if (sParameterName[0] === sParam) {
|
|
141
|
-
return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
function redirectToSP() {
|
|
147
|
-
var origin = getUrlParameter("origin");
|
|
148
|
-
var samlRequest = getUrlParameter("SAMLRequest");
|
|
149
|
-
var url = origin + "&SAMLRequest=" + samlRequest;
|
|
150
|
-
$("#sp").attr("action", url).submit();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
$(function(){
|
|
154
|
-
hideAlert();
|
|
155
|
-
$(".login-form").show();
|
|
156
|
-
$(".cookie-session-post-form").hide();
|
|
157
|
-
$(".mfa-form").hide();
|
|
158
|
-
$(".forgot-password-form").hide();
|
|
159
|
-
$(".reset-password-form").hide();
|
|
160
|
-
|
|
161
|
-
$(".forgot").click(function(e){
|
|
162
|
-
e.preventDefault();
|
|
163
|
-
$(".forgot-password-form").show();
|
|
164
|
-
$(".login-form").hide();
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
$(".login-form").on("submit", function(event){
|
|
168
|
-
$.ajax({
|
|
169
|
-
type: "POST",
|
|
170
|
-
url: this.action,
|
|
171
|
-
data: $(this).serialize(),
|
|
172
|
-
success: function(res, status, xhr) {
|
|
173
|
-
console.log(res);
|
|
174
|
-
if(res.requires_mfa){
|
|
175
|
-
console.log('requires mfa')
|
|
176
|
-
showAlert('danger', 'MFA Required')
|
|
177
|
-
|
|
178
|
-
for(var i=0; i<res.devices.length; i++){
|
|
179
|
-
$('.mfa-form select').append('<option value="' + res.devices[i].id + '">' + res.devices[i].type + '</option>');
|
|
180
|
-
}
|
|
181
|
-
$(".login-form").hide();
|
|
182
|
-
$(".mfa-form").show();
|
|
183
|
-
|
|
184
|
-
} else {
|
|
185
|
-
if (typeof COOKIE_VIA_POST_FORM === 'boolean' && COOKIE_VIA_POST_FORM === true) {
|
|
186
|
-
sendPostForm(res.session_token);
|
|
187
|
-
} else {
|
|
188
|
-
makeCors(res.session_token);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
error: function(xhr, status, err) {
|
|
193
|
-
console.log(err);
|
|
194
|
-
console.log(xhr);
|
|
195
|
-
showAlert('danger', xhr.responseJSON.error);
|
|
196
|
-
$(".login-form input[type=submit]").removeAttr("disabled");
|
|
197
|
-
},
|
|
198
|
-
});
|
|
199
|
-
event.preventDefault();
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
$(".mfa-form").on("submit", function(event){
|
|
203
|
-
$.ajax({
|
|
204
|
-
type: "POST",
|
|
205
|
-
url: this.action,
|
|
206
|
-
data: $(this).serialize(),
|
|
207
|
-
success: function(res, status, xhr) {
|
|
208
|
-
console.log(res);
|
|
209
|
-
|
|
210
|
-
if (typeof COOKIE_VIA_POST_FORM === 'boolean' && COOKIE_VIA_POST_FORM === true) {
|
|
211
|
-
sendPostForm(res.session_token);
|
|
212
|
-
} else {
|
|
213
|
-
makeCors(res.session_token);
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
error: function(xhr, status, err) {
|
|
217
|
-
console.log(err);
|
|
218
|
-
showAlert("danger", "MFA Verification Failed");
|
|
219
|
-
$(".login-form").show();
|
|
220
|
-
$(".mfa-form").hide();
|
|
221
|
-
$(".login-form input[type=submit]").removeAttr("disabled");
|
|
222
|
-
$(".mfa-form input[type=submit]").removeAttr("disabled");
|
|
223
|
-
},
|
|
224
|
-
});
|
|
225
|
-
event.preventDefault();
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
$(".forgot-password-form").on("submit", function(event){
|
|
229
|
-
$.ajax({
|
|
230
|
-
type: "POST",
|
|
231
|
-
url: this.action,
|
|
232
|
-
data: $(this).serialize(),
|
|
233
|
-
success: function(res, status, xhr) {
|
|
234
|
-
console.log(res);
|
|
235
|
-
|
|
236
|
-
for(var i=0; i<res.length; i++){
|
|
237
|
-
$('.reset-password-form select').append('<option value="' + res[i].id + '">' + res[i].auth_factor_name + '</option>');
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
$(".forgot-password-form").hide();
|
|
241
|
-
$(".reset-password-form").show();
|
|
242
|
-
},
|
|
243
|
-
error: function(xhr, status, err) {
|
|
244
|
-
console.log(err);
|
|
245
|
-
showAlert("danger", "User not found");
|
|
246
|
-
},
|
|
247
|
-
});
|
|
248
|
-
event.preventDefault();
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
$(".reset-password-form").on("submit", function(event){
|
|
252
|
-
$.ajax({
|
|
253
|
-
type: "POST",
|
|
254
|
-
url: this.action,
|
|
255
|
-
data: $(this).serialize(),
|
|
256
|
-
success: function(res, status, xhr) {
|
|
257
|
-
console.log(res);
|
|
258
|
-
|
|
259
|
-
$(".login-form").show();
|
|
260
|
-
$(".forgot-password-form").hide();
|
|
261
|
-
$(".reset-password-form").hide();
|
|
262
|
-
showAlert("success", "Password changed");
|
|
263
|
-
},
|
|
264
|
-
error: function(xhr, status, err) {
|
|
265
|
-
console.log(err);
|
|
266
|
-
showAlert("danger", err);
|
|
267
|
-
},
|
|
268
|
-
});
|
|
269
|
-
event.preventDefault();
|
|
270
|
-
});
|
|
271
|
-
})
|
|
272
|
-
</script>
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<title>OneLogin</title>
|
|
5
|
-
<%= csrf_meta_tags %>
|
|
6
|
-
|
|
7
|
-
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
|
|
8
|
-
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
|
|
9
|
-
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
|
|
10
|
-
</head>
|
|
11
|
-
|
|
12
|
-
<body>
|
|
13
|
-
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
|
|
14
|
-
<a class="navbar-brand" href="#">OneLogin Ruby SDK Sample</a>
|
|
15
|
-
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
|
|
16
|
-
<div class="navbar-nav">
|
|
17
|
-
<a class="nav-item nav-link active" href="/">Login</a>
|
|
18
|
-
<a class="nav-item nav-link" href="/signup">Sign Up</a>
|
|
19
|
-
<a class="nav-item nav-link" href="/onboard">Onboard</a>
|
|
20
|
-
</div>
|
|
21
|
-
</div>
|
|
22
|
-
</nav>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
<% flash.each do |key, value| %>
|
|
26
|
-
<div class="alert alert-warning"><%= value %></div>
|
|
27
|
-
<% end %>
|
|
28
|
-
|
|
29
|
-
<%= yield %>
|
|
30
|
-
</body>
|
|
31
|
-
</html>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<%= yield %>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
<div class="container">
|
|
2
|
-
<div class="row">
|
|
3
|
-
<div class="col-sm">
|
|
4
|
-
<p><%= link_to 'Back', users_path %></p>
|
|
5
|
-
|
|
6
|
-
<h2>Edit User</h2>
|
|
7
|
-
|
|
8
|
-
<%= form_tag update_user_path, method: "patch", class: "edit" do %>
|
|
9
|
-
<div class="form-group">
|
|
10
|
-
<label for="firstname">First Name</label>
|
|
11
|
-
<input type="text" name="firstname" value="<%= @user.firstname%>" class="form-control">
|
|
12
|
-
</div>
|
|
13
|
-
<div class="form-group">
|
|
14
|
-
<label for="lastname">Last Name</label>
|
|
15
|
-
<input type="text" name="lastname" value="<%= @user.lastname%>" class="form-control">
|
|
16
|
-
</div>
|
|
17
|
-
<div class="form-group">
|
|
18
|
-
<label for="email">Email</label>
|
|
19
|
-
<input type="text" name="email" value="<%= @user.email%>" class="form-control">
|
|
20
|
-
</div>
|
|
21
|
-
<div class="form-group">
|
|
22
|
-
<label for="email">Phone</label>
|
|
23
|
-
<input type="text" name="phone" value="<%= @user.phone%>" class="form-control">
|
|
24
|
-
</div>
|
|
25
|
-
<div class="form-group">
|
|
26
|
-
<label for="email">Custom Field</label>
|
|
27
|
-
<input type="text" name="custom_field" value="<%= @user.custom_attributes['custom_field'] if @user.custom_attributes.present? %>" class="form-control">
|
|
28
|
-
</div>
|
|
29
|
-
<button type="submit" class="btn btn-primary">Save</button>
|
|
30
|
-
<% end %>
|
|
31
|
-
</div>
|
|
32
|
-
</div>
|
|
33
|
-
</div>
|