package com.ankurm.authdemo.mfa;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.Authentication;

import java.util.Collection;
import java.util.List;

/**
 * A different token TYPE for a different proof: "this already-logged-in user also knows the one-time code".
 * Because it is its own type, only a provider whose supports() accepts it will ever see it.
 */
public class OtpAuthenticationToken extends AbstractAuthenticationToken {

    private final Authentication current; // who is already logged in
    private final String code;

    public OtpAuthenticationToken(Authentication current, String code) {
        super(List.of());
        this.current = current;
        this.code = code;
    }

    public Authentication current() {
        return current;
    }

    @Override
    public Object getCredentials() {
        return code;
    }

    @Override
    public Object getPrincipal() {
        return current.getPrincipal();
    }
}
