ruby - google admin directory v1 api groups.list insufficient permission error -
i'm trying authorize google admin api , list mailing list users. downloaded key api console , did:
require 'google/api_client' client= google::apiclient.new(application_name: "myapp", application_version: "0.1") groups= client.discovered_api('admin', 'directory_v1') key = google::apiclient::pkcs12.load_key(dir['*.p12'].first, 'notasecret') client.authorization = signet::oauth2::client.new( token_credential_uri: 'https://accounts.google.com/o/oauth2/token', audience: 'https://accounts.google.com/o/oauth2/token', scope: 'https://www.googleapis.com/auth/admin.directory.group.readonly', issuer: '123asdf@developer.gserviceaccount.com', signing_key: key) client.authorization.fetch_access_token! puts client.execute(api_method: groups.users.list, parameters: {}).body i tried adding groupkey: "mygroup@googlegroups.com" tried setting domain: "mysite.com" results in "insufficient permission"
what more have to list users in group?
try like:
require 'google/api_client' ## email of service account # service_account_email = '<some-id>@developer.gserviceaccount.com' ## email account of admin user ## admin_email = 'your-google-admin@yourdomain.com' ## path service account's private key file # service_account_pkcs12_file_path = '/path/to/<public_key_fingerprint>-privatekey.p12' ## # build admin sdk client instance authorized service account # acts on behalf of given user. # # @param [string] user_email # email of user. # @return [google::apiclient] # client instance def build_client(user_email) key = google::apiclient::pkcs12.load_key(service_account_pkcs12_file_path, 'notasecret') asserter = google::apiclient::jwtasserter.new(service_account_email, 'https://www.googleapis.com/auth/admin.directory.group.readonly', key) client = google::apiclient.new client.authorization = asserter.authorize(admin_email) client end this adapted google drive domain-wide authorization document. when using service accounts admin sdk directory api, still need impersonate admin user.
Comments
Post a Comment