【发布时间】:2022-11-11 05:46:12
【问题描述】:
我正在尝试让身份联合在这篇文章之后工作 https://learn.microsoft.com/en-us/azure/active-directory/develop/workload-identity-federation-create-trust-gcp?tabs=typescript。
上面的链接使用打字稿。 我可以在 Cloud Run 和 Compute Engine 中获取 google 令牌。 我还看到问题与此代码有关:
async function getGoogleIDToken() {
const headers = new Headers();
headers.append("Metadata-Flavor", "Google ");
let aadAudience = "api://AzureADTokenExchange";
const endpoint="http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/identity?audience="+ aadAudience;
const options = {
method: "GET",
headers: headers,
};
return fetch(endpoint, options);
}
上面的代码返回一个响应对象,它将在下面的代码中失败。
return getGoogleIDToken().then((clientAssertion:any)=> {
var msalApp: any;
msalApp = new msal.ConfidentialClientApplication({
auth: {
clientId: this.clientID,
authority: this.aadAuthority + this.tenantID,
clientAssertion: clientAssertion,
}
});
return msalApp.acquireTokenByClientCredential({ scopes })
我在获取 clientAssertion 时遇到了问题,因为它获取了响应对象。 我试图让 googleIDToken 拥有这个:
response = await fetch...;
return await response.json();
这已经失败,并且在调试输出中 clientAssertion 是未定义的。
我知道 await 应该在移动到下一个操作之前等待响应,但它的行为不是那样的。
有什么想法可以强制执行该函数以等待响应返回正确的值吗?
【问题讨论】: