Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

authentication object is null for second-factor and third-factor post methods in MfaController in mfa module #344

Open
imtiazShakil opened this issue Jan 13, 2025 · 0 comments

Comments

@imtiazShakil
Copy link

I fail to pass through the second factor and third factor authentication in the mfa module because in the both case the MfaAuthentication authentication is null

Below is more detail explanation:

in /mfa/src/main/java/example/MfaController.java file

	@PostMapping("/second-factor")
	public void processSecondFactor(@RequestParam("code") String code, MfaAuthentication authentication,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
                
                // authentication object is null but if I write it like below, I get the authentication object
		// MfaAuthentication authentication = (MfaAuthentication) SecurityContextHolder.getContext().getAuthentication();

		MfaAuthenticationHandler handler = new MfaAuthenticationHandler("/third-factor");
		...
	}

	@PostMapping("/third-factor")
	public void processThirdFactor(@RequestParam("answer") String answer, MfaAuthentication authentication,
			HttpServletRequest request, HttpServletResponse response) throws Exception {

                // authentication object is null but if I write it like below, I get the authentication object
		// MfaAuthentication authentication = (MfaAuthentication) SecurityContextHolder.getContext().getAuthentication();

		String encodedAnswer = getAnswer(authentication);
		...
	}

Can anyone explain why this is happening? I tried to debug but fail to get any explanation.

@imtiazShakil imtiazShakil changed the title authentication object is null in second-factor and third-factor controller in mfa module authentication object is null for second-factor and third-factor post methods in MfaController in mfa module Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant