2017-12-14 4 views
0

관리자 디렉토리 인증에 대한 인증 방법을 알아 내려고하고 있습니다. 내 목표는 새로운 GSuite 사용자를 만드는 것입니다.Google 관리자 디렉토리 API 인증

나는이 가이드 https://github.com/jay0lee/GAM/wiki/CreatingClientSecretsFile을 따라 도메인 전체 대표단과 클라이언트/ID 비밀 및 서비스 계정을 설정했습니다.

무기명 토큰을 성공적으로 얻을 수 있지만 엔드 포인트에 요청하면 403이됩니다. GAM을 사용하여 모든 데이터를 성공적으로 가져올 수 있으므로이 엔드 포인트에 인증되어야합니다. 동일한 자격 증명을 사용합니다.

require 'googleauth' 
require 'google/apis/admin_directory_v1' 

scope = ["https://www.googleapis.com/auth/admin.directory.user.readonly", "https://www.googleapis.com/auth/admin.directory.user"] 

authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
    json_key_io: File.open('service_account.json'), 
    scope: scope) 

pload = authorizer.fetch_access_token! 
token = pload["access_token"] 

url = "https://www.googleapis.com/admin/directory/v1/users/[email protected]" 
uri = URI.parse(url) 
request = Net::HTTP::Get.new(uri) 
request.content_type = "application/json" 
request["Authorization"] = "Bearer #{token}" 

req_options = { 
    use_ssl: uri.scheme == "https", 
} 

response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| 
    http.request(request) 
end 

p response #=> <Net::HTTPForbidden 403 Forbidden readbody=true> 
+0

정확히 어떤 오류가 발생합니까? – noogui

답변

0

서비스 계정의 범위가 수정되었으며 모든 것이 정상적으로 작동합니다.