我有以下代码,希望将访问令牌值从一个请求传递到另一个请求
let tokenUrl = 'https://login.microsoft.com/<tenantid>/oauth2/v2.0/token';
const getTokenRequest = {
method: 'POST',
url: tokenUrl,
body: {
mode: 'formdata',
formdata: [
{'key':'client_id', 'value':'<client_id>'},
{'key':'client_secret', 'value':'<client_secret>'},
{'key':'scope', 'value':'<api_scope>'},
{'key':'grant_type', 'value':'password'},
{'key':'username', 'value':'<usr_name>'},
{'key':'password', 'value':'<password>'}
]
},
};
pm.sendRequest(getTokenRequest, (err, response) => {
const jsonResponse = response.json();
const newAccessToken = jsonResponse.access_token;
//console.log("------->",newAccessToken);
pm.variables.set('GRAPHTOKEN', newAccessToken);
pm.environment.set("GRAPHTOKEN", "newAccessToken");
pm.globals.set("GRAPHTOKEN", "newAccessToken");
if (err){
console.log(err)
}
});
let createGroupIDURL = "https://localhost/api/groups";
const getGroupIDRequest = {
'method': 'POST',
'url': createGroupIDURL,
'body': `{"displayName": "MI-GroupInv-GRP-PERFweNf","description": "MI-GroupInv-GRP-PERFweNf"}`,
'headers': {
'Content-Type': `application/json;odata.metadata=minimal;odata.streaming=true`,
'Authorization': `Bearer {{newAccessToken}}`
}
};
pm.sendRequest(getGroupIDRequest, (err, response) => {
const jsonResponseBody = response.json();
const groupd = jsonResponseBody.id;
console.log("------->",groupd);
if (err){
console.log(err)
}
});
我遇到的错误:不记名令牌没有正确传递任何线索如何修复或我做错了什么?
1条答案
按热度按时间yhived7q1#
发现您需要修复代码中的几行,