googleapis / googleapis/google-api-nodejs-client

directory api users.insert Request parameter construction error

Offen
#3,138 0 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @sofisl Auf GitHub ansehen
priority: p2 type: bug
Vorherrschende Sprache
TypeScript
Sterne
12.2k
Forks
2k
Ø Merge
1 T. 9 Std.
Gemergte PRs (30 T.)
24

Beschreibung

node: v16.17.0
The rest of the databases are all up to date

```
const fs = require('fs').promises;
const path = require('path');
const process = require('process');
const {authenticate} = require('@google-cloud/local-auth');
const {google} = require('googleapis');

// If modifying these scopes, delete token.json.
const SCOPES = ['https://www.googleapis.com/auth/admin.directory.user'];
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
const TOKEN_PATH = path.join(process.cwd(), 'token.json');
const CREDENTIALS_PATH = path.join(process.cwd(), 'credentials.json');

/**
* Reads previously authorized credentials from the save file.
*
* @return {Promise}
*/
async function loadSavedCredentialsIfExist() {
try {
const content = await fs.readFile(TOKEN_PATH);
const credentials = JSON.parse(content);
return google.auth.fromJSON(credentials);
} catch (err) {
return null;
}
}

/**
* Serializes credentials to a file comptible with GoogleAUth.fromJSON.
*
* @param {OAuth2Client} client
* @return {Promise}
*/
async function saveCredentials(client) {
const content = await fs.readFile(CREDENTIALS_PATH);
const keys = JSON.parse(content);
const key = keys.installed || keys.web;
const payload = JSON.stringify({
type: 'authorized_user',
client_id: key.client_id,
client_secret: key.client_secret,
refresh_token: client.credentials.refresh_token,
});
await fs.writeFile(TOKEN_PATH, payload);
}

/**
* Load or request or authorization to call APIs.
*
*/
async function authorize() {
let client = await loadSavedCredentialsIfExist();
if (client) {
return client;
}
client = await authenticate({
scopes: SCOPES,
keyfilePath: CREDENTIALS_PATH,
});
if (client.credentials) {
await saveCredentials(client);
}
return client;
}

/**
* Lists the first 10 users in the domain.
*
* @param {google.auth.OAuth2} auth An authorized OAuth2 client.
*/
async function createUser(auth) {
const service = google.admin({version: 'directory_v1', auth});
const res = await service.users.insert({
primaryEmail: 'test@xx.com',
name: {
givenName: "te",
familyName: "st"
},
password: 'Test2023',
suspended: false,
orgUnitPath: "/",
})
console.log(res)
const users = res.data.users;
}
authorize().then(createUser).catch(console.error);
```

Through checking the request, it is found that the body data is not sent in json, but spliced into the url

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.