simpleokta 0.1.5

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.
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http'
4
+ require 'json'
5
+ require 'erb'
6
+ require 'simpleokta/apps'
7
+ require 'simpleokta/auth_servers'
8
+ require 'simpleokta/groups'
9
+ require 'simpleokta/constants'
10
+ require 'simpleokta/users'
11
+
12
+ module Simpleokta
13
+ class Client
14
+ include Apps
15
+ include AuthServers
16
+ include Groups
17
+ include Constants
18
+ include Users
19
+
20
+ attr_accessor :api_token, :base_api_url
21
+
22
+ # Initialize using passed in config hash
23
+ # @param config [Hash]
24
+ def initialize(config)
25
+ @api_token = config[:api_token]
26
+ @base_api_url = config[:base_api_url]
27
+ @http ||= HTTP::Client.new
28
+ end
29
+
30
+ # This method will add our api_token to each authorization header to keep our code D.R.Y
31
+ # @param action [String] the HTTP verb we are sending our request with.
32
+ # IE: 'get', 'post', 'put', 'delete'
33
+ # @param url [String] the URL to send the request to.
34
+ # @param body [Hash] the request body, set to an empty hash by default.
35
+ # Each request may require a different body schema.
36
+ def call_with_token(action, url, body = {})
37
+ uri = @base_api_url + url
38
+ @http
39
+ .headers(accept: 'application/json', content: 'application/json')
40
+ .auth("SSWS #{@api_token}")
41
+ .send(action, uri, { json: body })
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Simpleokta
4
+ class Client
5
+ module Constants
6
+ API_BASE_PATH = '/api/v1'
7
+ USER_API_BASE_PATH = "#{API_BASE_PATH}/users"
8
+ APP_API_BASE_PATH = "#{API_BASE_PATH}/apps"
9
+ AUTH_SERVER_API_BASE_PATH = "#{API_BASE_PATH}/authorizationServers"
10
+ GROUP_API_BASE_PATH = "#{API_BASE_PATH}/groups"
11
+ SYSTEM_LOG_API_BASE_PATH = "#{API_BASE_PATH}/logs"
12
+ ORG_API_BASE_PATH = "#{API_BASE_PATH}/org"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Simpleokta
4
+ class Client
5
+ module Groups
6
+ # GROUP METHODS
7
+
8
+ # Return a specific Group in the okta instance.
9
+ # @return [Hash<Group Object>]
10
+ # @param group_id [String] the unique identifier of the group
11
+ # @see https://developer.okta.com/docs/reference/api/groups/#group-object Group Object
12
+ def group(group_id)
13
+ response = call_with_token('get', "#{Constants::GROUP_API_BASE_PATH}/#{group_id}")
14
+ JSON.parse(response.body)
15
+ end
16
+
17
+ # Return all Groups in the okta instance.
18
+ # @return [Array<Group Object>]
19
+ # @see https://developer.okta.com/docs/reference/api/groups/#group-object Group Object
20
+ def groups
21
+ response = call_with_token('get', Constants::GROUP_API_BASE_PATH)
22
+ JSON.parse(response.body)
23
+ end
24
+
25
+ # Return all applications members of a group have automatically assigned to them.
26
+ # @param group_id [String] the unique identifier of the group
27
+ # @return [Array<Group Object>]
28
+ # @see https://developer.okta.com/docs/reference/api/apps/#application-object Application Object
29
+ def apps_assigned_to_group(group_id)
30
+ response = call_with_token('get', "#{Constants::GROUP_API_BASE_PATH}/#{group_id}/apps")
31
+ JSON.parse(response.body)
32
+ end
33
+
34
+ # Set an application to be automatically assigned to members of a group
35
+ # @param app_id [String] the unique id of the application
36
+ # @param group_id [String] the unique identifier of the group
37
+ # @return [Hash<Application Group Object>]
38
+ # @see https://developer.okta.com/docs/reference/api/apps/#assign-group-to-application Assign Group to Application
39
+ # @see https://developer.okta.com/docs/reference/api/apps/#application-key-credential-object Application Group Object
40
+ def assign_group_to_application(app_id, group_id)
41
+ response = call_with_token('put', "#{Constants::APP_API_BASE_PATH}/#{app_id}/groups/#{group_id}")
42
+ JSON.parse(response.body)
43
+ end
44
+
45
+ # Set an application to no longer be automatically assigned to members of a group
46
+ # @param app_id [String] the unique id of the application
47
+ # @param group_id [String] the unique identifier of the group
48
+ # @return [Group Assignment]
49
+ # @see https://developer.okta.com/docs/reference/api/apps/#response-example-34 Group Assignment Response
50
+ # @see https://developer.okta.com/docs/reference/api/apps/#assign-group-to-application Assign Group To Application
51
+ def remove_group_from_application(app_id, group_id)
52
+ call_with_token('delete', "#{Constants::APP_API_BASE_PATH}/#{app_id}/groups/#{group_id}")
53
+ end
54
+
55
+ # Returns an application group assignment
56
+ # @param app_id [String] the unique id of the application
57
+ # @param group_id [String] the unique identifier of the group
58
+ # @return [Group Assignment]
59
+ # @see https://developer.okta.com/docs/reference/api/apps/#response-example-34 Group Assignment Response
60
+ def get_assigned_group_for_application(app_id, group_id)
61
+ response = call_with_token('get', "#{Constants::APP_API_BASE_PATH}/#{app_id}/groups/#{group_id}")
62
+ JSON.parse(response.body)
63
+ end
64
+
65
+ # Update a group in the okta instance.
66
+ # @param group_id [String] the unique identifier of the group
67
+ # @param group_data [Hash] the data you want the group to contain
68
+ # @return [Hash<Group Object>]
69
+ # @see https://developer.okta.com/docs/reference/api/apps/#application-object Application Object
70
+ # @see https://developer.okta.com/docs/reference/api/groups/#update-group Update Group
71
+ def update_group(group_id, group_data)
72
+ response = call_with_token('put', "#{Constants::GROUP_API_BASE_PATH}/#{group_id}", group_data)
73
+ JSON.parse(response.body)
74
+ end
75
+
76
+ # Remove a group from your org.
77
+ # @param group_id [String] the unique identifier of the group
78
+ # @return 204 No Content
79
+ # @see https://developer.okta.com/docs/reference/api/apps/#application-object Application Object
80
+ # @see https://developer.okta.com/docs/reference/api/groups/#remove-group Remove Group
81
+ def remove_group(group_id)
82
+ call_with_token('delete', "#{Constants::GROUP_API_BASE_PATH}/#{group_id}")
83
+ end
84
+
85
+ # Get all members assigned to a group
86
+ # @param group_id [String] the unique identifier of the group
87
+ # @return 204 No Content
88
+ # @see https://developer.okta.com/docs/reference/api/groups/#list-group-members List Group Members
89
+ def group_members(group_id)
90
+ response = call_with_token('get', "#{Constants::GROUP_API_BASE_PATH}/#{group_id}/users")
91
+ JSON.parse(response.body)
92
+ end
93
+
94
+ # Add a user to a group
95
+ # @param group_id [String] the unique identifier of the group
96
+ # @param user_id [String] the unique identifier of the user
97
+ # @return 204 No Content
98
+ # @see https://developer.okta.com/docs/reference/api/groups/#add-user-to-group
99
+ def add_user_to_group(group_id, user_id)
100
+ call_with_token('put', "#{Constants::GROUP_API_BASE_PATH}/#{group_id}/users/#{user_id}")
101
+ end
102
+
103
+ # Remove a user from a group
104
+ # @param group_id [String] the unique identifier of the group
105
+ # @param user_id [String] the unique identifier of the user
106
+ # @return 204 No Content
107
+ # @see https://developer.okta.com/docs/reference/api/groups/#remove-user-from-group Add User To Group
108
+ def remove_user_from_group(group_id, user_id)
109
+ call_with_token('delete', "#{Constants::GROUP_API_BASE_PATH}/#{group_id}/users/#{user_id}")
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,173 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Simpleokta
4
+ class Client
5
+ module Users
6
+ # USER METHODS
7
+
8
+ # Return all users in an okta instance
9
+ # @return [Array<User>]
10
+ # @see https://developer.okta.com/docs/reference/api/users/#user-object User Object
11
+ def users
12
+ response = call_with_token('get', Constants::USER_API_BASE_PATH)
13
+ JSON.parse(response.body)
14
+ end
15
+
16
+ # Return a specific user in an okta instance
17
+ # @param user_id [String] the unique id of a user in the okta instance
18
+ # @return [Hash<User>]
19
+ # @see https://developer.okta.com/docs/reference/api/users/#user-object User Object
20
+ def user(user_id)
21
+ response = call_with_token('get', "#{Constants::USER_API_BASE_PATH}/#{user_id}")
22
+ JSON.parse(response.body)
23
+ end
24
+
25
+ # Return a specific user in an okta instance
26
+ # @param login [String] the login email of the user
27
+ # @return [Hash<User>]
28
+ # @see https://developer.okta.com/docs/reference/api/users/#user-object User Object
29
+ def user_from_login(login)
30
+ response = call_with_token('get', "#{Constants::USER_API_BASE_PATH}/#{ERB::Util.url_encode(login)}")
31
+ JSON.parse(response.body)
32
+ end
33
+
34
+ # Create a user in the okta instance without credentials
35
+ # @param user_profile_data [Hash] the required fields to create a user in okta.
36
+ # At minimum, this should contain the Profile object.
37
+ # @example Profile Object
38
+ # "profile": {
39
+ # "firstName": "Isaac",
40
+ # "lastName": "Brock",
41
+ # "email": "isaac.brock@example.com",
42
+ # "login": "isaac.brock@example.com",
43
+ # "mobilePhone": "555-415-1337"
44
+ # }
45
+ # @return [Hash<User>]
46
+ # @see https://developer.okta.com/docs/reference/api/users/#create-user Create User
47
+ # @see https://developer.okta.com/docs/reference/api/users/#profile-object Profile Object
48
+ def create_user(user_profile_data)
49
+ response = call_with_token('post', "#{Constants::USER_API_BASE_PATH}?activate=false", user_profile_data)
50
+ JSON.parse(response.body)
51
+ end
52
+
53
+ # Create an activated user in the okta instance without credentials
54
+ # @param user_profile_data [Hash] the required fields to create a user in okta.
55
+ # At minimum, this should contain the Profile object.
56
+ # @return [Hash<User>]
57
+ # @see https://developer.okta.com/docs/reference/api/users/#create-user Create User
58
+ # @see https://developer.okta.com/docs/reference/api/users/#profile-object Profile Object
59
+ def create_and_activate_user(user_profile_data)
60
+ response = call_with_token('post', "#{Constants::USER_API_BASE_PATH}?activate=true", user_profile_data)
61
+ JSON.parse(response.body)
62
+ end
63
+
64
+ # Create a user in the okta insance, and have the user added to groups
65
+ # @param user_profile_data [Hash] the required fields to create a user in okta.
66
+ # At minimum, this should contain the Profile object.
67
+ # @param group_id_array [Array<String>] the group ids the user should be added to
68
+ # @return [Hash<User>]
69
+ # @see https://developer.okta.com/docs/reference/api/users/#user-object User Object
70
+ # @see https://developer.okta.com/docs/reference/api/users/#create-user-in-group Create User in Group
71
+ def create_user_in_group(user_profile_data, group_id_array)
72
+ body = user_profile_data
73
+ body[:groupIds] = group_id_array
74
+ response = call_with_token('post', Constants::USER_API_BASE_PATH, body)
75
+ JSON.parse(response.body)
76
+ end
77
+
78
+ # Delete a user in the okta instance
79
+ # @param user_id [String] the unique id of a user in the okta instance
80
+ # @return [Hash<User>]
81
+ # @see https://developer.okta.com/docs/reference/api/users/#user-object User Object
82
+ def delete_user(user_id)
83
+ response = call_with_token('delete', "#{Constants::USER_API_BASE_PATH}/#{user_id}")
84
+ response
85
+ end
86
+
87
+ # Update a user in the okta instance
88
+ # @param user_id [String] the unique id of a user in the okta instance
89
+ # @param user_profile_data [Hash] the required fields to create a user in okta.
90
+ # At minimum, this should contain the Profile object.
91
+ # Any fields not passed in user_profile_data will be set to null in the user data
92
+ # @return [Hash<User>]
93
+ # @see https://developer.okta.com/docs/reference/api/users/#user-object User Object
94
+ def update_user(user_id, user_profile_data)
95
+ response = call_with_token('put', "#{Constants::USER_API_BASE_PATH}/#{user_id}", user_profile_data)
96
+ JSON.parse(response.body)
97
+ end
98
+
99
+ # Activate a user in the okta instance.
100
+ # Users created are not immediately activated until they log on. This method bypasses that requirement
101
+ # @param user_id [String] the unique id of a user in the okta instance
102
+ # @param send_email [Boolean] whether or not to send an activation email to the user
103
+ # @return [Hash] contains information on activation.
104
+ # If send_email is set to True, returns an empty hash.
105
+ # @see https://developer.okta.com/docs/reference/api/users/#activate-user Activate User
106
+ def activate_user(user_id, send_email)
107
+ response = call_with_token('post',
108
+ "#{Constants::USER_API_BASE_PATH}/#{user_id}/lifecycle/activate?sendEmail=#{send_email}")
109
+ JSON.parse(response.body)
110
+ end
111
+
112
+ # Reactivates a user in the okta instance that was deactivated.
113
+ # @param user_id [String] the unique id of a user in the okta instance
114
+ # @param send_email [Boolean] whether or not to send an activation email to the user
115
+ # @return [Hash] contains information on activation.
116
+ # If send_email is set to True, returns an empty hash.
117
+ # @see https://developer.okta.com/docs/reference/api/users/#reactivate-user Reactivate User
118
+ def reactivate_user(user_id, send_email)
119
+ response = call_with_token('post',
120
+ "#{Constants::USER_API_BASE_PATH}/#{user_id}/lifecycle/reactivate?sendEmail=#{send_email}")
121
+ JSON.parse(response.body)
122
+ end
123
+
124
+ # Deactivates a user in the okta instance.
125
+ # @param user_id [String] the unique id of a user in the okta instance
126
+ # @param send_email [Boolean] whether or not to send an activation email to the user
127
+ # @return [Hash] empty hash
128
+ # @see https://developer.okta.com/docs/reference/api/users/#deactivate-user Deactivate User
129
+ def deactivate_user(user_id, send_email)
130
+ response = call_with_token('post',
131
+ "#{Constants::USER_API_BASE_PATH}/#{user_id}/lifecycle/deactivate?sendEmail=#{send_email}")
132
+ JSON.parse(response.body)
133
+ end
134
+
135
+ # Suspend a user in the okta instance.
136
+ # @param user_id [String] the unique id of a user in the okta instance
137
+ # @return [Hash] empty hash
138
+ # @see https://developer.okta.com/docs/reference/api/users/#suspend-user Suspend User
139
+ def suspend_user(user_id)
140
+ call_with_token('post', "#{Constants::USER_API_BASE_PATH}/#{user_id}/lifecycle/suspend")
141
+ end
142
+
143
+ # Unsuspend a user in the okta instance.
144
+ # Sets the user status to ACTIVE.
145
+ # @param user_id [String] the unique id of a user in the okta instance
146
+ # @return [Hash] empty hash
147
+ # @see https://developer.okta.com/docs/reference/api/users/#unsuspend-user Unsuspend User
148
+ def unsuspend_user(user_id)
149
+ call_with_token('post', "#{Constants::USER_API_BASE_PATH}/#{user_id}/lifecycle/unsuspend")
150
+ end
151
+
152
+ # Unlocks a user in the okta instance.
153
+ # Only available when a user has LOCKED_OUT status.
154
+ # Sets the user status to ACTIVE.
155
+ # @param user_id [String] the unique id of a user in the okta instance
156
+ # @return [Hash] empty hash
157
+ # @see https://developer.okta.com/docs/reference/api/users/#unlock-user Unlock User
158
+ def unlock_user(user_id)
159
+ call_with_token('post', "#{Constants::USER_API_BASE_PATH}/#{user_id}/lifecycle/unlock")
160
+ end
161
+
162
+ # List all applications a user currently has assigned to them.
163
+ # @param user_id [String] the unique id of a user in the okta instance
164
+ # @return [Array<Application Object>]
165
+ # @see https://developer.okta.com/docs/reference/api/apps/#application-object Application Object
166
+ # @see https://developer.okta.com/docs/reference/api/apps/#list-applications-assigned-to-a-user List Applications Assigned to User
167
+ def apps_assigned_to_user(user_id)
168
+ response = call_with_token('get', "#{Constants::APP_API_BASE_PATH}/?filter=user.id+eq+\"#{user_id}\"")
169
+ JSON.parse(response.body)
170
+ end
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Simpleokta
4
+ VERSION = '0.1.5'
5
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/simpleokta/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'simpleokta'
7
+ spec.version = Simpleokta::VERSION
8
+ spec.authors = ['Braden Shipley']
9
+ spec.email = ['simpleokta@gmail.com']
10
+
11
+ spec.summary = 'A Simple Okta Gem that helps perform common Okta Calls.'
12
+ spec.description = 'A Simple Okta Gem that helps perform common Okta Calls.'
13
+ spec.homepage = 'https://github.com/bradenshipley/simpleokta'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
16
+
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/bradenshipley/simpleokta'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/bradenshipley/simpleokta/changelog.md'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+ # Gem Dependencies
32
+ spec.add_dependency('http')
33
+ end
data/solargraph ADDED
@@ -0,0 +1,29 @@
1
+ #!/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by RubyGems.
6
+ #
7
+ # The application 'solargraph' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'rubygems'
12
+
13
+ version = '>= 0.a'
14
+
15
+ str = ARGV.first
16
+ if str
17
+ str = str.b[/\A_(.*)_\z/, 1]
18
+ if str && Gem::Version.correct?(str)
19
+ version = str
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ if Gem.respond_to?(:activate_bin_path)
25
+ load Gem.activate_bin_path('solargraph', 'solargraph', version)
26
+ else
27
+ gem 'solargraph', version
28
+ load Gem.bin_path('solargraph', 'solargraph', version)
29
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simpleokta
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Braden Shipley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A Simple Okta Gem that helps perform common Okta Calls.
28
+ email:
29
+ - simpleokta@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".travis.yml"
37
+ - CODE_OF_CONDUCT.md
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/console
44
+ - bin/setup
45
+ - lib/simpleokta.rb
46
+ - lib/simpleokta/apps.rb
47
+ - lib/simpleokta/auth_servers.rb
48
+ - lib/simpleokta/client.rb
49
+ - lib/simpleokta/constants.rb
50
+ - lib/simpleokta/groups.rb
51
+ - lib/simpleokta/users.rb
52
+ - lib/simpleokta/version.rb
53
+ - simpleokta.gemspec
54
+ - solargraph
55
+ homepage: https://github.com/bradenshipley/simpleokta
56
+ licenses:
57
+ - MIT
58
+ metadata:
59
+ allowed_push_host: https://rubygems.org
60
+ homepage_uri: https://github.com/bradenshipley/simpleokta
61
+ source_code_uri: https://github.com/bradenshipley/simpleokta
62
+ changelog_uri: https://github.com/bradenshipley/simpleokta/changelog.md
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 2.6.0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.2.13
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: A Simple Okta Gem that helps perform common Okta Calls.
82
+ test_files: []