otplib icon indicating copy to clipboard operation
otplib copied to clipboard

Cant set algorithm in TypeScript

Open andr00w opened this issue 2 years ago • 5 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,
    };

andr00w avatar Jul 13 '22 14:07 andr00w

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

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

gozetfiliz avatar Sep 22 '22 09:09 gozetfiliz

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

Eazash avatar Sep 23 '22 12:09 Eazash

Anything other than sha1 is not working with Google Authenticator

niksmac avatar Mar 30 '23 08:03 niksmac

@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,
}

santoshshinde2012 avatar May 09 '23 05:05 santoshshinde2012

Anything other than sha1 is not working with Google Authenticator

Have you found any solutions?

santoshshinde2012 avatar May 09 '23 06:05 santoshshinde2012