google_directory 0.2.3 → 0.2.4

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
  SHA256:
3
- metadata.gz: 8d686d850e36f8f0ca476fa18866bfd73fb913de0e8b134a2fdca08b580a2187
4
- data.tar.gz: faa84394c013ca04239bd3f9a5659cf82129f90a8f5750a4cd8b8b2c1a66e07d
3
+ metadata.gz: ad3d45be79a46c765d3e286620049175179c317083042a816acd730751a00ebc
4
+ data.tar.gz: 2032dcf141e7f8c93d23cee5262c1104fbb902de6bcab02aff8f031b03c8091a
5
5
  SHA512:
6
- metadata.gz: 9f4af38fd52d322d6a2a4844e29c3c013c88f74af7e1a3c91e7fe5d540dbbbb28e973eb142f44ff97f46c0b35451a0fa008970c7ac4653e8fb075fe9f1e3ed45
7
- data.tar.gz: b70dc522431b30f6cdd4edc57bc3053090e2694e3ee8569f4ac54bd6cb137bbc88450da4d031e3376b551e1bd1bd9184a67090ff39ec746255b4dd030ad61050
6
+ metadata.gz: db8d3e223648271045ae7ede6b39e2ff6b6ac4ffbf0979a88338bbe86c408a2e6cb0366328d9723cd03db536e226e85c2839f8ca0e474208ed732733c9a9e6a5
7
+ data.tar.gz: 39e9c27cd74a021935569401113c71fd3814db24bfd7813977d5460b74fc4bde218b3fb23b3c4666687eec1e7addb781d3903e70cc76be66db16a3526c2d82b0
@@ -1,8 +1,6 @@
1
- require 'google/apis/admin_directory_v1'
2
1
  require 'googleauth'
3
- require 'googleauth/stores/file_token_store'
2
+ require 'google/apis/admin_directory_v1'
4
3
  require 'fileutils'
5
-
6
4
  require "google_directory/version"
7
5
  require "google_directory/user_commands"
8
6
 
@@ -19,17 +17,17 @@ module GoogleDirectory
19
17
  include GoogleDirectory::UserCommands
20
18
 
21
19
  # default settings from google for all users
22
- OOB_URI = ENV['OOB_URI'] || 'urn:ietf:wg:oauth:2.0:oob'
23
- CREDENTIALS_PATH = ENV['CREDENTIALS_PATH'] || File.join( Dir.home, '.credentials', "admin-directory_v1-ruby-accounts.yaml")
20
+ CREDENTIALS_PATH = ENV['CREDENTIALS_JSON_PATH']
21
+ SUB_ACCOUNT = ENV['SUB_ACCOUNT_NAME']
24
22
 
25
23
  # Get info the Google Cloud Admin
26
24
  # https://console.cloud.google.com/apis/ or
27
25
  # build using: https://developers.google.com/api-client-library/ruby/guide/aaa_client_secrets
28
- CLIENT_SECRETS_PATH = ENV['CLIENT_SECRETS_PATH'] || 'client_secret.json'
26
+ # CLIENT_SECRETS_PATH = ENV['CLIENT_SECRETS_PATH'] || 'client_secret.json'
29
27
 
30
28
  # Scope options - https://www.googleapis.com/auth/admin.directory.user
31
29
  # https://developers.google.com/admin-sdk/directory/v1/guides/authorizing
32
- SCOPE = Google::Apis::AdminDirectoryV1::AUTH_ADMIN_DIRECTORY_USER
30
+ # SCOPE = Google::Apis::AdminDirectoryV1::AUTH_ADMIN_DIRECTORY_USER
33
31
  # SCOPE = 'https://www.googleapis.com/auth/admin.directory.user'
34
32
 
35
33
  # Initialize the API
@@ -39,9 +37,7 @@ module GoogleDirectory
39
37
  # @note make connection to google directory services
40
38
  # @param service [Class] the default is: Google::Apis::AdminDirectoryV1::DirectoryService
41
39
  def initialize( service: Google::Apis::AdminDirectoryV1::DirectoryService )
42
- app_name ||= ENV['APPLICATION_NAME'] || 'google_cloud_app_name'
43
40
  @service = service.new
44
- @service.client_options.application_name = app_name
45
41
  @service.authorization = authorize
46
42
  end
47
43
 
@@ -49,8 +45,6 @@ module GoogleDirectory
49
45
  VERSION
50
46
  end
51
47
 
52
- # @note Run a command against Google Directory
53
- #
54
48
  # @param command [Symbol] choose command to perform these include: :user_get, :user_exists? (t/f), :user_create, :user_delete, :user_update & convience commands :user_suspend, :user_reactivate, :user_change_password
55
49
  # @param attributes [Hash] attributes needed to perform command
56
50
  # @return [Hash] formatted as: `{success: {command: :command, attributes: {primary_email: "user@domain"}, response: GoogleAnswer} }`
@@ -78,32 +72,15 @@ module GoogleDirectory
78
72
 
79
73
  private
80
74
  attr_reader :service
81
- ##
82
- # FROM:
83
- # https://www.rubydoc.info/github/google/google-api-ruby-client/Google/Apis/AdminDirectoryV1/DirectoryService
84
- # Ensure valid credentials, either by restoring from the saved credentials
85
- # files or intitiating an OAuth2 authorization. If authorization is required,
86
- # the user's default browser will be launched to approve the request.
87
- # @return [Google::Auth::UserRefreshCredentials] OAuth2 credentials
88
- def authorize
89
- FileUtils.mkdir_p(File.dirname(CREDENTIALS_PATH))
90
75
 
91
- client_id = Google::Auth::ClientId.from_file(CLIENT_SECRETS_PATH)
92
- token_store = Google::Auth::Stores::FileTokenStore.new(file: CREDENTIALS_PATH)
93
- authorizer = Google::Auth::UserAuthorizer.new( client_id, SCOPE, token_store )
94
- user_id = 'default'
95
- credentials = authorizer.get_credentials(user_id)
96
- if credentials.nil?
97
- url = authorizer.get_authorization_url(
98
- base_url: OOB_URI)
99
- puts "Open the following URL in the browser and enter the " +
100
- "resulting code after authorization"
101
- puts url
102
- code = gets
103
- credentials = authorizer.get_and_store_credentials_from_code(
104
- user_id: user_id, code: code, base_url: OOB_URI)
105
- end
106
- credentials
76
+ def authorize
77
+ scope = ['https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/admin.directory.user.security']
78
+ authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
79
+ json_key_io: File.open(CREDENTIALS_PATH),
80
+ scope: scope)
81
+ authorizer.update!(sub: SUB_ACCOUNT)
82
+ authorizer.fetch_access_token!
83
+ return authorizer
107
84
  end
108
85
  end
109
86
  end
@@ -1,5 +1,5 @@
1
1
  module GoogleDirectory
2
2
  module Version
3
- VERSION = "0.2.3"
3
+ VERSION = "0.2.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_directory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bill Tihen
8
8
  - Lee Weisbecker
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-06-14 00:00:00.000000000 Z
12
+ date: 2023-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-api-client
@@ -17,70 +17,70 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0.21'
20
+ version: '0.37'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '0.21'
27
+ version: '0.37'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: bundler
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '1.16'
34
+ version: '2.1'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '1.16'
41
+ version: '2.1'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '10.0'
48
+ version: '13.0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '10.0'
55
+ version: '13.0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rspec
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '3.0'
62
+ version: '3.9'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '3.0'
69
+ version: '3.9'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: pry
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '0.11'
76
+ version: '0.12'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '0.11'
83
+ version: '0.12'
84
84
  description: Authenticate, list, make, check, suspend and activate google users.
85
85
  email:
86
86
  - btihen@gmail.com
@@ -98,7 +98,7 @@ homepage: https://github.com/LAS-IT/google_directory
98
98
  licenses:
99
99
  - MIT
100
100
  metadata: {}
101
- post_install_message:
101
+ post_install_message:
102
102
  rdoc_options: []
103
103
  require_paths:
104
104
  - lib
@@ -113,9 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.7.6
118
- signing_key:
116
+ rubygems_version: 3.1.6
117
+ signing_key:
119
118
  specification_version: 4
120
119
  summary: Simple ruby wrapper to manage google accounts - using oauth2.
121
120
  test_files: []