+ Start a Discussion

Using named credentials with Google's G-Suite

I am trying to use Named Credentials to get a list of users from Google's G-Suite.
So I created an app on the Google console and gave it a scope of https://www.googleapis.com/auth/admin.directory.user.readonly
I confirmed with Google's API explorer that both the scope and the URL I was going to make the request on were correct 
Then I created an Auth Provider and Named Credential leaving the Scope blank. But when I run this code in anonymous apex, I get an error "Insufficent Permission" returned from Google:
HttpRequest req = new HttpRequest();
Http http = new Http();
HTTPResponse res = http.send(req);

so I tried adding the scope to the Named Credential and the Auth Provider, but then I get  and error Missing_id_token when I try to save the Named Credential.
Has anyone got something similar working I could look at?
Found it - when creating the Auth Provider - I used the Google as the provider type, I should have choosen Open ID Connect