Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impersonate user (domain-wide delegation) #395

Open
rttll opened this issue Sep 8, 2022 · 1 comment
Open

Impersonate user (domain-wide delegation) #395

rttll opened this issue Sep 8, 2022 · 1 comment

Comments

@rttll
Copy link

rttll commented Sep 8, 2022

Can this library be used to impersonate a Google Workspace user?

The python version of this library has a method to initiate service-account credentials, and assign a specific user using the with_subject method.
Docs.
with_subject

I have a service account and have set up domain-wide delegation for it.
Here's my code so far:

# service account key
key_file = Rails.application.credentials.oauth[:domain].deep_transform_keys! { |k| k.to_s }
io = StringIO.new(JSON.generate(key_file))
@auth = Google::Auth::ServiceAccountCredentials.make_creds(
  json_key_io: io,
  scope: [Drive::AUTH_DRIVE, Drive::AUTH_DRIVE_FILE]
)

drive = Google::Apis::DriveV3.new
drive.authorization = @auth

# this will fail because not authorized for a user
files = drive.list_files(q: "title contains 'hello' ")

I've looked throughout all the classes here and can't find a way to do this.

My next step will be to do it manually as outlined here if there's no better option.

@haffla
Copy link

haffla commented Mar 6, 2023

It's outlined in the README on how to do this. https://github.com/googleapis/google-auth-library-ruby#3-legged-oauth-with-a-service-account

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants