yeojz / otplib

:key: One Time Password (OTP) / 2FA for Node.js and Browser - Supports HOTP, TOTP and Google Authenticator

Home Page:https://otplib.yeojz.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cant set algorithm in TypeScript

andr00w opened this issue · comments

Describe the bug
It does not possible to set the algorithm that is typed by the enum HashAlgorithms:

  • When using a valid string, e.g. 'SHA1' it says "TS2322: Type '"SHA1"' is not assignable to type 'HashAlgorithms'."
  • When using HashAlgorithms the import throws an error: "Cannot find module '@otplib/core/utils' from 'myservice.ts"

To Reproduce

    import { authenticator } from 'otplib';

    authenticator.options = {
      algorithm: 'sha1',
    };

OR:

    import { authenticator } from 'otplib';
    import { HashAlgorithms } from '@otplib/core/utils';

    authenticator.options = {
      algorithm: HashAlgorithms.SHA1,
    };

It's not exactly the right way to do, but you can use it like this ->

authenticator.options = { algorithm: 'sha1' as any, }

@andr00w A working solution for me is to import from @otplib/core

Anything other than sha1 is not working with Google Authenticator

@andr00w A working solution for me is to import from @otplib/core

Yes this work for me as well but other than SHA1 is not working with Google Authenticator and OKTA.

import { authenticator } from 'otplib';
import { HashAlgorithms } from '@otplib/core';


// Configure otplib to use SHA512
authenticator.options = {
  algorithm: HashAlgorithms.SHA256,
}

Anything other than sha1 is not working with Google Authenticator

Have you found any solutions?