Skip to content

Gmail Service Account dont want authenticate #2860

Closed

Description

@NonozgYtb

Hi everyone,
After several long hours, I still cannot use my service account for Gmail. I'm a Google Workspace customer, but whether it's through JWT, OAuth, or other things (some of which the current version no longer supports), nothing helps and I get just errors. I don't really know what to do to be able to access information (via an OAuth client for my account only its walking) on ​​the gmail accounts of my members.
Can I have a (actual) solution ?
Thanks a lot.
PS: sorry for the text pad but it's late and I'm exhausted and quite frustrated with this problem

Activity

  1. NonozgYtb commented on Dec 12, 2021

    @NonozgYtb
    Author

    Hi,
    After a lot of research, I found a solution that works (I use the promises):

    const credentials = require("./credentials.json") // File downloaded with the Service Account Keys
    const getGmailAuth  = async ()=>{
           const auth = (new google.auth.JWT(
                credentials.global.client_email,
                null,
                credentials.global.private_key,
                GMAILSCOPES,
                person
            ))
            await (new Promise((resolve, reject) => {
                auth.authorize((err, tokens) => {
                    if (err) {
                        reject(err);
                    } else {
                        resolve(tokens);
                    }
                });
            }))
            return (auth);
    }

    Good bye !

  2. frozen-a-b commented on Jan 28, 2022

    @frozen-a-b

    Hi @NonozgYtb ,

    I think I ran into a similar issue

    What is person in your code?

  3. NonozgYtb commented on Jan 28, 2022

    @NonozgYtb
    Author

    Hi @NonozgYtb ,

    I think I ran into a similar issue

    What is person in your code?

    person is a string with an email like :

    const person = "firstname.name@mydomain.com";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions