onelogin 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0b09f92686da99fbe19429f8ae65da9962f97a0
4
- data.tar.gz: 8fe313cf382979cc481a5bb26961ca4091a615d3
3
+ metadata.gz: 891448f2f234475b2f392acef115af5b20424599
4
+ data.tar.gz: 7ebc413eef700591b78c3654d194595994e5d5a6
5
5
  SHA512:
6
- metadata.gz: feaa630f6e10bbeaac2f783dfa4af64fb19afabbe4c6781745be745dce0f5fe52863d9ce7e7202f8be86b61d286ec211074c524b54475d7ae178a26f90b65207
7
- data.tar.gz: 9276fb49aa63b3d9f2cc04ff089eeb5decd8c6b5329d7fe57bbd70e371c3b1f4784bf8a5cc486c4abbf2baaa487487240904a22feabc59e56c1d7d117141ea22
6
+ metadata.gz: 01f1f2c8dae4fcfc8606ae68bd8c18d8d1a664fc857da76af5fe7a5f04eb2a7e46c25cab9b1643016d893dbf5bae065c0c1e7a2348e7eb72f818ef3a1d2d63d6
7
+ data.tar.gz: b3fd44cb52795b239704b1879dd3d6695880705e52d32d6e7c52c2a9f37a260e3ede5ba36975d5d182ba57d8fccff72ce9edb65447a9aaaa3bfc50e4043a0b77
@@ -61,3 +61,15 @@ body {
61
61
  text-align: center;
62
62
  }
63
63
 
64
+ form.edit div {
65
+ padding: 10px;
66
+ }
67
+
68
+ table.list {
69
+ width: 100%;
70
+ }
71
+
72
+ table.list tr td {
73
+ padding: 5px;
74
+ border-bottom: 1px #ccc solid;
75
+ }
@@ -0,0 +1,86 @@
1
+ class UsersController < ApplicationController
2
+
3
+ before_action :require_current_user
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
+ @user = User.new
20
+ end
21
+
22
+ # GET /users/1/edit
23
+ def edit
24
+ end
25
+
26
+ # POST /users
27
+ # POST /users.json
28
+ def create
29
+ @user = User.new(user_params)
30
+
31
+ respond_to do |format|
32
+ if @user.save
33
+ format.html { redirect_to @user, notice: 'User was successfully created.' }
34
+ format.json { render :show, status: :created, location: @user }
35
+ else
36
+ format.html { render :new }
37
+ format.json { render json: @user.errors, status: :unprocessable_entity }
38
+ end
39
+ end
40
+ end
41
+
42
+ # PATCH/PUT /users/1
43
+ # PATCH/PUT /users/1.json
44
+ def update
45
+ # update the user
46
+ api_client.update_user(params[:id], user_params)
47
+
48
+ # update custom attributes
49
+ api_client.set_custom_attribute_to_user(params[:id], custom_user_params)
50
+
51
+ respond_to do |format|
52
+ unless api_client.error
53
+ format.html { redirect_to user_path(params[:id]), notice: 'User was successfully updated.' }
54
+ format.json { render :show, status: :ok, location: @user }
55
+ else
56
+ format.html { render :edit }
57
+ format.json { render json: @user.errors, status: :unprocessable_entity }
58
+ end
59
+ end
60
+ end
61
+
62
+ # DELETE /users/1
63
+ # DELETE /users/1.json
64
+ def destroy
65
+ @user.destroy
66
+ respond_to do |format|
67
+ format.html { redirect_to users_url, notice: 'User was successfully destroyed.' }
68
+ format.json { head :no_content }
69
+ end
70
+ end
71
+
72
+ private
73
+ # Use callbacks to share common setup or constraints between actions.
74
+ def set_user
75
+ @user = api_client.get_user(params[:id])
76
+ end
77
+
78
+ # Never trust parameters from the scary internet, only allow the white list through.
79
+ def user_params
80
+ params.permit(:firstname, :lastname, :email, :phone, :custom_field)
81
+ end
82
+
83
+ def custom_user_params
84
+ params.permit(:custom_field)
85
+ end
86
+ end
@@ -0,0 +1,2 @@
1
+ module UsersHelper
2
+ end
@@ -5,7 +5,7 @@
5
5
  </p>
6
6
 
7
7
  <p>
8
- <a href="/logout">Log Out</a>
8
+ <a href="/users">List Users</a> | <a href="/logout">Log Out</a>
9
9
  </p>
10
10
 
11
11
  <h2>Apps</h2>
@@ -0,0 +1,2 @@
1
+ json.extract! user, :id, :created_at, :updated_at
2
+ json.url user_url(user, format: :json)
@@ -0,0 +1,27 @@
1
+ <h1>Editing User</h1>
2
+
3
+ <%= form_tag update_user_path, method: "patch", class: "edit" do %>
4
+
5
+ <div>
6
+ First Name: <input type="text" name="firstname" value="<%= @user.firstname%>">
7
+ </div>
8
+ <div>
9
+ Last Name: <input type="text" name="lastname" value="<%= @user.lastname%>">
10
+ </div>
11
+ <div>
12
+ Email: <input type="text" name="email" value="<%= @user.email%>">
13
+ </div>
14
+ <div>
15
+ Phone: <input type="text" name="phone" value="<%= @user.phone%>">
16
+ </div>
17
+ </div>
18
+ <div>
19
+ Custom Field: <input type="text" name="custom_field" value="<%= @user.custom_attributes['custom_field']%>">
20
+ </div>
21
+
22
+ <div class="actions">
23
+ <%= submit_tag %>
24
+ </div>
25
+ <% end %>
26
+
27
+ <%= link_to 'Back', users_path %>
@@ -0,0 +1,30 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <h1>Users</h1>
4
+
5
+ <table class="list">
6
+ <thead>
7
+ <tr>
8
+ <th>Name</th>
9
+ <th>Email</th>
10
+ <th>Phone</th>
11
+ <th>Custom Field</th>
12
+ <th colspan="2"></th>
13
+ </tr>
14
+ </thead>
15
+
16
+ <tbody>
17
+ <% @users.each do |user| %>
18
+ <tr>
19
+ <td><%= user.firstname %> <%= user.lastname %></td>
20
+ <td><%= user.email %></td>
21
+ <td><%= user.phone %></td>
22
+ <td><%= user.custom_attributes["custom_field"] if user.custom_attributes.is_a?(Hash) %></td>
23
+ <td><%= link_to 'Show', user_path(user.id) %></td>
24
+ <td><%= link_to 'Edit', edit_user_path(user.id) %></td>
25
+ </tr>
26
+ <% end %>
27
+ </tbody>
28
+ </table>
29
+
30
+ <br>
@@ -0,0 +1 @@
1
+ json.array! @users, partial: 'users/user', as: :user
@@ -0,0 +1,5 @@
1
+ <h1>New User</h1>
2
+
3
+ <%= render 'form', user: @user %>
4
+
5
+ <%= link_to 'Back', users_path %>
@@ -0,0 +1,12 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <%= link_to 'Edit', edit_user_path(@user.id) %> |
4
+ <%= link_to 'Back', users_path %>
5
+
6
+ <h2>Profile</h2>
7
+
8
+ <%@user.instance_values.symbolize_keys.each do |k, v|%>
9
+ <div class="row">
10
+ <span><%= k%>:</span> <%= v%>
11
+ </div>
12
+ <%end%>
@@ -0,0 +1 @@
1
+ json.partial! "users/user", user: @user
@@ -7,6 +7,11 @@ Rails.application.routes.draw do
7
7
 
8
8
  get 'dashboard', to: 'dashboard#index'
9
9
 
10
+ get 'users', to: 'users#index'
11
+ get 'users/:id', to: 'users#show', as: 'user'
12
+ get 'users/:id/edit', to: 'users#edit', as: 'edit_user'
13
+ patch 'users/:id', to: 'users#update', as: 'update_user'
14
+
10
15
  root 'home#index'
11
16
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
12
17
  end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ class UsersControllerTest < ActionDispatch::IntegrationTest
4
+ setup do
5
+ @user = users(:one)
6
+ end
7
+
8
+ test "should get index" do
9
+ get users_url
10
+ assert_response :success
11
+ end
12
+
13
+ test "should get new" do
14
+ get new_user_url
15
+ assert_response :success
16
+ end
17
+
18
+ test "should create user" do
19
+ assert_difference('User.count') do
20
+ post users_url, params: { user: { } }
21
+ end
22
+
23
+ assert_redirected_to user_url(User.last)
24
+ end
25
+
26
+ test "should show user" do
27
+ get user_url(@user)
28
+ assert_response :success
29
+ end
30
+
31
+ test "should get edit" do
32
+ get edit_user_url(@user)
33
+ assert_response :success
34
+ end
35
+
36
+ test "should update user" do
37
+ patch user_url(@user), params: { user: { } }
38
+ assert_redirected_to user_url(@user)
39
+ end
40
+
41
+ test "should destroy user" do
42
+ assert_difference('User.count', -1) do
43
+ delete user_url(@user)
44
+ end
45
+
46
+ assert_redirected_to users_url
47
+ end
48
+ end
@@ -110,15 +110,17 @@ module OneLogin
110
110
 
111
111
  def handle_saml_endpoint_response(response)
112
112
  content = JSON.parse(response.body)
113
- if content && content.has_key?('status') && content.has_key?('data') && content['status'].has_key?('message') && content['status'].has_key?('type')
113
+ if content && content.has_key?('status') && content['status'].has_key?('message') && content['status'].has_key?('type')
114
114
  status_type = content['status']['type']
115
115
  status_message = content['status']['message']
116
116
  saml_endpoint_response = OneLogin::Api::Models::SAMLEndpointResponse.new(status_type, status_message)
117
- if status_message == 'Success'
118
- saml_endpoint_response.saml_response = content['data']
119
- else
120
- mfa = OneLogin::Api::Models::MFA.new(content['data'][0])
121
- saml_endpoint_response.mfa = mfa
117
+ if content.has_key?('data')
118
+ if status_message == 'Success'
119
+ saml_endpoint_response.saml_response = content['data']
120
+ else
121
+ mfa = OneLogin::Api::Models::MFA.new(content['data'][0])
122
+ saml_endpoint_response.mfa = mfa
123
+ end
122
124
  end
123
125
 
124
126
  return saml_endpoint_response
@@ -731,6 +733,45 @@ module OneLogin
731
733
  false
732
734
  end
733
735
 
736
+ # Set User State
737
+ #
738
+ # @param id [Integer] Id of the user to be modified
739
+ # @param state [Integer] Set to the state value. [Unapproved: 0, Approved (licensed): 1, Rejected: 2, Unlicensed: 3]
740
+ #
741
+ # @return [Boolean] if the action succeed
742
+ #
743
+ # @see {https://developers.onelogin.com/api-docs/1/users/set-state Set User State documentation}
744
+ def set_state_to_user(user_id, state)
745
+ clean_error
746
+ prepare_token
747
+
748
+ begin
749
+ url = url_for(SET_USER_STATE_URL, user_id)
750
+
751
+ data = {
752
+ 'state' => state
753
+ }
754
+
755
+ response = HTTParty.put(
756
+ url,
757
+ headers: authorized_headers,
758
+ body: data.to_json
759
+ )
760
+
761
+ if response.code == 200
762
+ return handle_operation_response(response)
763
+ else
764
+ @error = response.code.to_s
765
+ @error_description = extract_error_message_from_response(response)
766
+ end
767
+ rescue Exception => e
768
+ @error = '500'
769
+ @error_description = e.message
770
+ end
771
+
772
+ false
773
+ end
774
+
734
775
  # Set Custom Attribute Value
735
776
  #
736
777
  # @param user_id [Integer] Id of the user
@@ -5,7 +5,7 @@ module OneLogin
5
5
  class User
6
6
 
7
7
  attr_accessor :id, :external_id, :email, :username, :firstname, :lastname, :distinguished_name,
8
- :phone, :company, :department, :status, :member_of, :samaccountname, :userprincipalname,
8
+ :phone, :company, :department, :status, :state, :member_of, :samaccountname, :userprincipalname,
9
9
  :group_id, :role_ids, :custom_attributes, :openid_name, :locale_code, :comment, :directory_id,
10
10
  :title, :manager_ad_id, :trusted_idp_id, :activated_at, :created_at, :updated_at,
11
11
  :password_changed_at, :invitation_sent_at, :invalid_login_attempts, :last_login, :locked_until
@@ -23,6 +23,7 @@ module OneLogin
23
23
  @department = data['department'].to_s
24
24
  @title = data['title'].to_s
25
25
  @status = data['status']
26
+ @state = data['state']
26
27
  @member_of = data['member_of'].to_s
27
28
  @samaccountname = data['samaccountname'].to_s
28
29
  @userprincipalname = data['userprincipalname'].to_s
@@ -66,6 +67,7 @@ module OneLogin
66
67
  user_data.department = @department
67
68
  user_data.title = @title
68
69
  user_data.status = @status
70
+ user_data.state = @state
69
71
  user_data.member_of = @member_of
70
72
  user_data.samaccountname = @samaccountname
71
73
  user_data.userprincipalname = @userprincipalname
@@ -110,6 +112,7 @@ module OneLogin
110
112
  "department"=> self.department,
111
113
  "title"=> self.title,
112
114
  "status"=> self.status,
115
+ "state"=> self.state,
113
116
  "member_of"=> self.member_of,
114
117
  "samaccountname"=> self.samaccountname,
115
118
  "invalid_login_attempts"=> self.invalid_login_attempts,
@@ -5,7 +5,7 @@ module OneLogin
5
5
  class UserData
6
6
 
7
7
  attr_accessor :id, :external_id, :email, :username, :firstname, :lastname, :distinguished_name,
8
- :phone, :company, :department, :status, :member_of, :samaccountname, :userprincipalname,
8
+ :phone, :company, :department, :status, :state, :member_of, :samaccountname, :userprincipalname,
9
9
  :title, :openid_name, :locale_code, :directory_id, :manager_ad_id, :trusted_idp_id
10
10
  end
11
11
  end
@@ -10,7 +10,7 @@ module OneLogin
10
10
  # OAuth2 Tokens URLs
11
11
  TOKEN_REQUEST_URL = "https://api.%s.onelogin.com/auth/oauth2/v2/token"
12
12
  TOKEN_REFRESH_URL = "https://api.%s.onelogin.com/auth/oauth2/v2/token"
13
- TOKEN_REVOKE_URL = "https://api.%s.onelogin.com/auth/oauth2/v2/revoke"
13
+ TOKEN_REVOKE_URL = "https://api.%s.onelogin.com/auth/oauth2/revoke"
14
14
  GET_RATE_URL = "https://api.%s.onelogin.com/auth/rate_limit"
15
15
 
16
16
  # User URLs
@@ -30,6 +30,7 @@ module OneLogin
30
30
  SET_PW_CLEARTEXT = "https://api.%s.onelogin.com/api/1/users/set_password_clear_text/%s"
31
31
  SET_PW_SALT = "https://api.%s.onelogin.com/api/1/users/set_password_using_salt/%s"
32
32
  SET_CUSTOM_ATTRIBUTE_TO_USER_URL = "https://api.%s.onelogin.com/api/1/users/%s/set_custom_attributes"
33
+ SET_USER_STATE_URL = "https://api.%s.onelogin.com/api/1/users/%s/set_state"
33
34
  LOG_USER_OUT_URL = "https://api.%s.onelogin.com/api/1/users/%s/logout"
34
35
  LOCK_USER_URL = "https://api.%s.onelogin.com/api/1/users/%s/lock_user"
35
36
 
@@ -1,3 +1,3 @@
1
1
  module OneLogin
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onelogin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OneLogin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-16 00:00:00.000000000 Z
11
+ date: 2018-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -131,10 +131,12 @@ files:
131
131
  - examples/rails-custom-login-page/app/controllers/dashboard_controller.rb
132
132
  - examples/rails-custom-login-page/app/controllers/home_controller.rb
133
133
  - examples/rails-custom-login-page/app/controllers/sessions_controller.rb
134
+ - examples/rails-custom-login-page/app/controllers/users_controller.rb
134
135
  - examples/rails-custom-login-page/app/helpers/application_helper.rb
135
136
  - examples/rails-custom-login-page/app/helpers/dashboard_helper.rb
136
137
  - examples/rails-custom-login-page/app/helpers/home_helper.rb
137
138
  - examples/rails-custom-login-page/app/helpers/sessions_helper.rb
139
+ - examples/rails-custom-login-page/app/helpers/users_helper.rb
138
140
  - examples/rails-custom-login-page/app/jobs/application_job.rb
139
141
  - examples/rails-custom-login-page/app/mailers/application_mailer.rb
140
142
  - examples/rails-custom-login-page/app/models/application_record.rb
@@ -144,6 +146,14 @@ files:
144
146
  - examples/rails-custom-login-page/app/views/layouts/application.html.erb
145
147
  - examples/rails-custom-login-page/app/views/layouts/mailer.html.erb
146
148
  - examples/rails-custom-login-page/app/views/layouts/mailer.text.erb
149
+ - examples/rails-custom-login-page/app/views/users/_form.html.erb
150
+ - examples/rails-custom-login-page/app/views/users/_user.json.jbuilder
151
+ - examples/rails-custom-login-page/app/views/users/edit.html.erb
152
+ - examples/rails-custom-login-page/app/views/users/index.html.erb
153
+ - examples/rails-custom-login-page/app/views/users/index.json.jbuilder
154
+ - examples/rails-custom-login-page/app/views/users/new.html.erb
155
+ - examples/rails-custom-login-page/app/views/users/show.html.erb
156
+ - examples/rails-custom-login-page/app/views/users/show.json.jbuilder
147
157
  - examples/rails-custom-login-page/bin/bundle
148
158
  - examples/rails-custom-login-page/bin/rails
149
159
  - examples/rails-custom-login-page/bin/rake
@@ -190,6 +200,7 @@ files:
190
200
  - examples/rails-custom-login-page/test/controllers/dashboard_controller_test.rb
191
201
  - examples/rails-custom-login-page/test/controllers/home_controller_test.rb
192
202
  - examples/rails-custom-login-page/test/controllers/sessions_controller_test.rb
203
+ - examples/rails-custom-login-page/test/controllers/users_controller_test.rb
193
204
  - examples/rails-custom-login-page/test/fixtures/.keep
194
205
  - examples/rails-custom-login-page/test/fixtures/files/.keep
195
206
  - examples/rails-custom-login-page/test/helpers/.keep