-
Notifications
You must be signed in to change notification settings - Fork 56
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
Service account authentification doesn't work #160
Comments
Hi @jennybc & @jimhester, A Service account is created on a standard/non-workspace Google account and the json is downloaded. I've attempted to authorize with the following code derived from the docs here:
I get this error message from and this from
I created an Oauth consent for testing as I thought that may be an issue: I've tried passing the Service Account json directly to
but this results in the following error: If one of y'all has some time could you provide some guidance for myself and others on this thread (or whoever may encounter it) as to how to get a service account and Thanks in advance, R Session Info``` R version 4.1.0 (2021-05-18) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19042)Matrix products: default locale: attached base packages: loaded via a namespace (and not attached):
|
Hi This allowed me to start sending requests to the API. I tried to send a test email and received the following error message:
I went ahead and enabled the Gmail API and tried again. I think we might need to enable gmail domain-wide and delegate permissions to the Service Account for the Gmail API to resolve this. We're going to try this. I am wondering if we're barking up the right tree here though? |
Hi @yogat3ch, thank you very much for this post.
Please also include in the gm_auth() function, the "subject" parameter as well to allow a service account to impersonate a given Gmail Workspace account. Here is how I made it work, using @yogat3ch's hack:
In order to grant domain-wide authority, you need to have an administrator Google Workspace account:
|
@alexquant1993 thanks for the excellent post. I had been troubleshooting this issue for a while and your solution worked perfectly. |
Yeah @alexquant1993 I agree with your diagnosis. The early unqualified call to I'm curious: are you successfully sending email as someone other than the service account this way? This has been reported as "not working" in gargle and I've never truly dug into it because I am not allowed to grant a service account domain wide delegation at my workplace, which makes it really hard to investigate. I have formed a hypothesis is that the problem is specifying the subject's email address vs. an id. What does |
A slightly less "exciting" adaptation of @alexquant1993's workaround is more like (warning: code untested): # decoy oauth app that we won't actually use
gm_auth_configure(key = "PLACEHOLDER", secret = "PLACEHOLDER")
# Get token given the service account credentials
token <- gargle::credentials_service_account(
scopes = "https://mail.google.com/",
path = "path/to/the/json/for/the/service/account.json",
subject = "??" # specifying the subject
)
gm_auth(token = token) Update: I tried to test that and all of the above works. But I can't truly test it by, say, sending an email, since I don't have a service account with domain wide authority. And I'm almost certain that a service account must be acting on behalf of a subject with the Gmail API. |
Even simpler workaround (again: not completely tested since I can't grant a service account domain wide authority) gm_auth_configure(key = "PLACEHOLDER", secret = "PLACEHOLDER")
gm_auth(
path = "path/to/the/json/for/the/service/account.json",
subject = "??" # specify the subject
) Update: in hindsight, this can't work because |
I'm still trying to figure out exactly what to do here. Jotting down some analysis and notes for myself. Overall, the magical If we could reliably tell what sort of auth the user wants, it would be possible to determine whether an OAuth client is required. But that's pretty opposed to the design of As it stands, the unconditional call to
I have the impression that it's not possible to send email as a service account. Quoting from (googleapis/google-api-nodejs-client#2322 (comment)):
So I think the only Gmail-using scenario where a service account is relevant is when one is also passing the Therefore, the title of thread is basically true ("Service account authentification doesn't work"), although the root cause isn't really this call to |
With dev gmailr, here is the current best pre-emptive workaround for (theoretically) using one of the auth methods other than fake_client <- gargle::gargle_oauth_client(
id = "PLACEHOLDER",
secret = "PLACEHOLDER"
)
gm_auth_configure(fake_client) This is necessary, for example, to use |
* Stop requiring a configured oauth client prior to `token_fetch()` Fixes #160 * Work on the NEWS
Hi,
Thanks for this great package.
I tried to configure
gmailr
using a service account token likegm_auth(path = "my_token.json")
but it send me this error :I know my token is good because when I use it with
googledrive
orgooglesheets4
, it works.I can create an app using OAuth, but I would like to use service account token here.
Thanks
The text was updated successfully, but these errors were encountered: