在 msalBrowser 中为 loginRedirect 设置自定义 code_challenge
set custom code_challenge for loginRedirect in msalBrowser
我使用 msal-browser 包进行身份验证,并尝试将 code_challenge
设置为我想要的东西,而不是 msal-browser 自动生成的东西。
import * as msal from "@azure/msal-browser";
import pkceChallenge from "pkce-challenge"
const msalConfig = {
auth: {
clientId: "GUID", // This is the ONLY mandatory field; everything else is optional.
authority: "https://{tenant}.b2clogin.com/{tenant}.onmicrosoft.com/B2C_signin_flow", // Choose sign-up/sign-in user-flow as your default.
knownAuthorities: [{authority}], // You must identify your tenant's domain as a known authority.
redirectUri: "http://localhost:6420", // You must register this URI on Azure Portal/App Registration. Defaults to "window.location.href".
}
};
const b2cScopes = ["https://{tenant}.onmicrosoft.com/010eb29e-d42b-4ca3-9c16-1961a528ce67/tasks.read",
"https://{tenant}.onmicrosoft.com/010eb29e-d42b-4ca3-9c16-1961a528de77/tasks.write"];
const myMSALObj = new msal.PublicClientApplication(msalConfig);
const pkce = pkceChallenge();
const loginRequest = {
scopes: ["openid", ...b2cScopes],
codeChallenge: pkce.code_challenge
}
myMSALObj.loginRedirect(loginRequest)
上面的内容似乎不起作用,因为 loginRedirect
的输入参数不希望出现 codeChallenge
属性。
如何设置?
我使用 msal-browser 包进行身份验证,并尝试将 code_challenge
设置为我想要的东西,而不是 msal-browser 自动生成的东西。
import * as msal from "@azure/msal-browser";
import pkceChallenge from "pkce-challenge"
const msalConfig = {
auth: {
clientId: "GUID", // This is the ONLY mandatory field; everything else is optional.
authority: "https://{tenant}.b2clogin.com/{tenant}.onmicrosoft.com/B2C_signin_flow", // Choose sign-up/sign-in user-flow as your default.
knownAuthorities: [{authority}], // You must identify your tenant's domain as a known authority.
redirectUri: "http://localhost:6420", // You must register this URI on Azure Portal/App Registration. Defaults to "window.location.href".
}
};
const b2cScopes = ["https://{tenant}.onmicrosoft.com/010eb29e-d42b-4ca3-9c16-1961a528ce67/tasks.read",
"https://{tenant}.onmicrosoft.com/010eb29e-d42b-4ca3-9c16-1961a528de77/tasks.write"];
const myMSALObj = new msal.PublicClientApplication(msalConfig);
const pkce = pkceChallenge();
const loginRequest = {
scopes: ["openid", ...b2cScopes],
codeChallenge: pkce.code_challenge
}
myMSALObj.loginRedirect(loginRequest)
上面的内容似乎不起作用,因为 loginRedirect
的输入参数不希望出现 codeChallenge
属性。
如何设置?