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

where to register IUserTwoFactorTokenProvider type custom token provider? #36

Open
relatedrhymes opened this issue Nov 21, 2020 · 0 comments

Comments

@relatedrhymes
Copy link

relatedrhymes commented Nov 21, 2020

I have created a custom google authenticator token provider implementing IUserTwoFactorTokenProvider. but I'm not sure where and how do I register this new provider in Startup?

public class GoogleAuthenticatorTokenProvider : IUserTwoFactorTokenProvider<User>
    {
        public GoogleAuthenticatorTokenProvider()
        {
        }

        public Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
        {
            return Task.FromResult(user.IsGoogleAuthenticatorEnabled);
        }

        public Task<string> GenerateAsync(string purpose, UserManager<User> manager, User user)
        {
            return Task.FromResult((string)null);
        }

        public Task<bool> ValidateAsync(string purpose, string token, UserManager<User> manager, User user)
        {
            long timeStepMatched = 0;

            var otp = new Totp(WebEncoders.Base64UrlDecode(user.GoogleAuthenticatorSecretKey));
            bool valid = otp.VerifyTotp(token, out timeStepMatched, new VerificationWindow(2, 2));

            return Task.FromResult(valid);
        }
    }
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