-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
JWT Error #461
Comments
Recently i use jwt based the example , What i have is a json file generated from google credential(service account)
I put the private key the one file named key.pem var authClient = new google.auth.JWT(
'REDACTED@developer.gserviceaccount.com',
'./server/key.pem',
'REDACTED',
['https://www.googleapis.com/auth/drive.readonly'],
// User to impersonate (leave empty if no impersonation needed)
'REDACTED.apps.googleusercontent.com'); but
I have google a lot , but still have no solution , Could you help with this ? Steven Xu |
Hmm.. I suspect it is how you are generating your .pem file. It seems like the format of it is not what the client is expecting. |
@nonumber1989 Please for your sake, don't post your private keys on GitHub! I redacted them from your comment. If you're using a var google = require('googleapis');
var key = require('/path/to/key.json');
var authClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
[/**scopes go here*/],
null
);
authClient.authorize(function (err, tokens) {
// do something
}); Closing as this does not appear to be an issue. If you are convinced that this is really a bug, please feel free to re-open the issue and add more information such as:
Or, consider opening a Pull Request. Otherwise, support questions are handled on Stack Overflow. |
I am trying to fetch all emails under our domain. I have all admin rights anda I created service account with Domain wide delegation. This is my code: const google = require('googleapis');
const gmail = google.gmail('v1');
const directory = google.admin('directory_v1');
const scopes = [
'https://www.googleapis.com/auth/gmail.readonly',
'https://www.googleapis.com/auth/admin.directory.user.readonly'
];
const key = require('./service_key.json');
var authClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
scopes,
null
);
authClient.authorize(function(err, tokens){
if (err) {
console.log(err);
return;
}
directory.users.list(
{
auth: authClient,
customer: 'my_customer',
maxResults: 250,
orderBy: 'email'
}, (err, resp) => {
if (err) {
console.log(err);
return;
}
console.log(resp);
})
}) and I still get error
|
Getting the same error as @kunokdev even though having authorized my client for 'https://www.googleapis.com/auth/admin.directory.user' in the admin console at https://admin.google.com. |
@kumikoda @dfahlander do you find a solution to fix the error? |
@yoyeung can you show example code where you are getting error and what kind of authorization do you want to achieve at the end? This library works fine, some things are just easy to misunderstand or less popular examples are hard to find. // auth.js
Resolved object is used as auth param in your API calls. Make sure you always use 'me' as param for user id, because auth object is actually param that detects which user is authorized. |
@kunokdev here you are.
this is the response
|
@yoyeung , // users.js
and this is how I use it with auth method from above:
Can you check if you are giving it proper params? User email I give it is email of admin user. Btw, reason why is last param exposed to be param to give is because of reusability for other types of auths. |
@kunokdev For my case...this email is not an admin user. |
This is method for authorizing users, see comment above (it's file where something gone wrong, probably). I added filenames before code, so you know which file is which. The reason why I expose last param is because of reusability, because in our domain we have multiple admins and each has different rights. So basically this is method from comment above, ( |
@kunokdev Finally i find the issue. Also thanks for ur help. it's working well!!!! |
that's great! It's like I mentioned above:
|
I am still facing this issue. let google = require('googleapis');
let privatekey = require("./oauth2test-d48d715ddb90");
var googleAuth = require('google-auth-library');
// configure a JWT auth client
let jwtClient = new google.auth.JWT(
privatekey.client_email,
null,
privatekey.private_key, [
'https://www.googleapis.com/auth/admin.directory.user'
]);
//authenticate request
jwtClient.authorize(function (err, tokens) {
if (err) {
console.log(err);
return;
} else {
console.log(tokens);
listUsers(jwtClient);
console.log("Successfully connected!");
}
});
function listUsers(auth) {
var service = google.admin('directory_v1');
service.users.list({
auth: auth,
customer: 'my_customer',
maxResults: 100,
orderBy: 'email'
}, function (err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
var users = response.users;
if (users.length == 0) {
console.log('No users in the domain.');
} else {
console.log('Users:');
for (var i = 0; i < users.length; i++) {
var user = users[i];
console.log(user);
console.log('%s (%s)', user.primaryEmail, user.name.fullName);
}
}
});
} I enabled the I if use the authorisation_code flow with my admin credentials it works fine, if I use the service account I am getting error.
|
found working example : https://stackoverflow.com/a/47241705/1124447 |
The 'domain not found' error can also happen if you do not select a user to impersonate for the service account call.
|
Hello,
I am currently getting the error:
When trying to use the calendar api using JWT. I am struggling to find this error message and how to debug this online. Please help! My code is the following:
The call works when i authorize via auth.OAuth2...
The text was updated successfully, but these errors were encountered: