Azure AD B2C,AADSTS9002313:无效请求。请求畸形或无效

发布于 2025-01-25 15:43:52 字数 2582 浏览 1 评论 0 原文

正如标题所说,我有问题从令牌API中恢复访问令牌, 我还尝试使用MSAL/节点库提供的方法。

我注意到我从重定向URI 中获得的代码很奇怪,在URL中,我得到 client_info 而不是 code> code image> image-

uri“

我正在尝试3种不同的方法获取令牌。

在第一个中,我会收到标题中包含的错误,在其他两个中,我会收到以下错误 - serverrorr:invalid_grant:undefined-- [undefined]:AADB2C90090:提供的JWE不是有效的5段标记

我的代码 -

const getAuthentication = (azureConfig, azureAuthCode, confidentialClientApplication) => {
   //prepare the request for authentication    
   debugger    
   tokenRequest.code = azureAuthCode
   tokenRequest.grant_type = 'authorization_code';
   tokenRequest.scope = [`${azureConfig.b2c._scopes.ScheduleAppointments}`];
   tokenRequest.client_id = process.env.APP_CLIENT_ID;
   tokenRequest.client_secret = process.env.APP_CLIENT_SECRET,
   

   console.log(tokenRequest)

方法一号------

错误返回-AADSTS9002313:无效请求。请求是畸形或无效的

request({
    url: `https://login.microsoftonline.com/${process.env.TENANT_NAME}/oauth2/v2.0/token`,
    method: "POST",
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
    body: tokenRequest,
}, (req, res) => {console.log(res)})

方法两个-----

错误返回-ServerRorr:Invalid_grant:undefined-- [Undefined]:AADB2C90090:提供的JWE不是有效的5段tok token token

// try {
//  const response = await confidentialClientApplication.acquireTokenByCode(tokenRequest)
//  request.req.session.sessionParams = {user: response.account, idToken: response.idToken};
//  console.log("\nAuthToken: \n" + JSON.stringify(response));
//  res.render('getPatientAppointments',{showSignInButton: false, givenName: response.account.idTokenClaims.given_name});
//   } catch (error) {
//  console.log("\nErrorAtLogin: \n" + error);
//   }

方法三

-------------------------------------------------- :未定义 - [未定义]:AADB2C90090:提供的JWE不是有效的5个段令牌

//    confidentialClientApplication.acquireTokenByCode(tokenRequest).then((response)=>{
   
//    req.session.sessionParams = {user: response.account, idToken: response.idToken};
//    console.log("\nAuthToken: \n" + JSON.stringify(response));
//    res.render('getPatientAppointments',{showSignInButton: false, givenName: response.account.idTokenClaims.given_name});
//    }).catch((error)=>{
//     console.log("\nErrorAtLogin: \n" + error);
//    });

}

As the title says, I have a problem get the access token back from the token API,
I also tried using the method provided by the msal/node library.

I noticed something weird about the code I get from the redirect uri I provided, In the url I get client_info and not code image -

Taken from the redirect Uri

Im trying 3 different methods to fetch the tokens.

In the first one I get the error included in the title, in the other two I get the following error - ServerError: invalid_grant: undefined - [undefined]: AADB2C90090: The provided JWE is not a valid 5 segment token

My Code -

const getAuthentication = (azureConfig, azureAuthCode, confidentialClientApplication) => {
   //prepare the request for authentication    
   debugger    
   tokenRequest.code = azureAuthCode
   tokenRequest.grant_type = 'authorization_code';
   tokenRequest.scope = [`${azureConfig.b2c._scopes.ScheduleAppointments}`];
   tokenRequest.client_id = process.env.APP_CLIENT_ID;
   tokenRequest.client_secret = process.env.APP_CLIENT_SECRET,
   

   console.log(tokenRequest)

METHOD ONE -----

ERROR RETURNED - AADSTS9002313: Invalid request. Request is malformed or invalid

request({
    url: `https://login.microsoftonline.com/${process.env.TENANT_NAME}/oauth2/v2.0/token`,
    method: "POST",
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
    body: tokenRequest,
}, (req, res) => {console.log(res)})

METHOD TWO -----

ERROR RETURNED - ServerError: invalid_grant: undefined - [undefined]: AADB2C90090: The provided JWE is not a valid 5 segment token

// try {
//  const response = await confidentialClientApplication.acquireTokenByCode(tokenRequest)
//  request.req.session.sessionParams = {user: response.account, idToken: response.idToken};
//  console.log("\nAuthToken: \n" + JSON.stringify(response));
//  res.render('getPatientAppointments',{showSignInButton: false, givenName: response.account.idTokenClaims.given_name});
//   } catch (error) {
//  console.log("\nErrorAtLogin: \n" + error);
//   }

METHOD THREE -----

ERROR RETURNED - ServerError: invalid_grant: undefined - [undefined]: AADB2C90090: The provided JWE is not a valid 5 segment token

//    confidentialClientApplication.acquireTokenByCode(tokenRequest).then((response)=>{
   
//    req.session.sessionParams = {user: response.account, idToken: response.idToken};
//    console.log("\nAuthToken: \n" + JSON.stringify(response));
//    res.render('getPatientAppointments',{showSignInButton: false, givenName: response.account.idTokenClaims.given_name});
//    }).catch((error)=>{
//     console.log("\nErrorAtLogin: \n" + error);
//    });

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文