diff --git a/.changeset/nine-radios-tap.md b/.changeset/nine-radios-tap.md new file mode 100644 index 00000000000..a28a9ea79e0 --- /dev/null +++ b/.changeset/nine-radios-tap.md @@ -0,0 +1,5 @@ +--- +"@clerk/clerk-js": patch +--- + +Bug fix: Skip password strategy for users who authenticate with SAML. diff --git a/packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx b/packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx index 187571b5d95..5e325281cc4 100644 --- a/packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx +++ b/packages/clerk-js/src/ui/components/SignIn/SignInStart.tsx @@ -231,18 +231,33 @@ export function _SignInStart(): JSX.Element { const buildSignInParams = (fields: Array>): SignInCreateParams => { const hasPassword = fields.some(f => f.name === 'password' && !!f.value); - if (!hasPassword) { + + /** + * FAPI will return an error when password is submitted but the user's email matches requires SAML authentication. + * We need to strip password from the create request, and reconstruct it later. + */ + if (!hasPassword || userSettings.saml.enabled) { fields = fields.filter(f => f.name !== 'password'); } return { ...buildRequest(fields), - ...(hasPassword && { strategy: 'password' }), + ...(hasPassword && !userSettings.saml.enabled && { strategy: 'password' }), } as SignInCreateParams; }; const signInWithFields = async (...fields: Array>) => { try { - const res = await signIn.create(buildSignInParams(fields)); + const res = await signIn.create(buildSignInParams(fields)).then(signInResource => { + /** + * For SAML enabled instances, perform sign in with password only when it is allowed for the identified user. + */ + const passwordField = fields.find(f => f.name === 'password')?.value; + if (!passwordField || signInResource.supportedFirstFactors.some(ff => ff.strategy === 'saml')) { + return signInResource; + } + return signInResource.attemptFirstFactor({ strategy: 'password', password: passwordField }); + }); + switch (res.status) { case 'needs_identifier': // Check if we need to initiate a saml flow diff --git a/packages/upgrade/package.json b/packages/upgrade/package.json index 4da3d966fd6..61b70823b2e 100644 --- a/packages/upgrade/package.json +++ b/packages/upgrade/package.json @@ -17,6 +17,11 @@ "lint": "eslint src/", "lint:publint": "publint" }, + "repository": { + "type": "git", + "url": "git+https://github.com/clerk/javascript.git", + "directory": "packages/upgrade" + }, "babel": { "presets": [ "@babel/preset-react"