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

Cant set algorithm in TypeScript #674

Open
andr00w opened this issue Jul 13, 2022 · 5 comments
Open

Cant set algorithm in TypeScript #674

andr00w opened this issue Jul 13, 2022 · 5 comments

Comments

@andr00w
Copy link

andr00w commented Jul 13, 2022

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,
    };
@gozetfiliz
Copy link

gozetfiliz commented Sep 22, 2022

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

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

@Eazash
Copy link

Eazash commented Sep 23, 2022

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

@niksmac
Copy link

niksmac commented Mar 30, 2023

Anything other than sha1 is not working with Google Authenticator

@santoshshinde2012
Copy link

@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
Copy link

Anything other than sha1 is not working with Google Authenticator

Have you found any solutions?

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

5 participants