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

Auth Strategies #1257

Merged
merged 10 commits into from
Feb 28, 2022
Merged

Auth Strategies #1257

merged 10 commits into from
Feb 28, 2022

Conversation

pedroslopez
Copy link
Owner

Cleans up the new local file storage and legacy auth into separate Auth Strategies.

This concept could be used later to add something like S3Auth, for example. It also means users can develop their own auth strategies.

Usage

LocalAuth - Filesystem-based auth that uses puppeteer's userDataDir to persist browser data

const client = new Client({
    authStrategy: new LocalAuth()
});

To customize clientId or dataPath, pass as options to the auth strategy:

const client = new Client({
    authStrategy: new LocalAuth({
        clientId: "example",
        dataPath: "./some/path"
    })
});

LegacySessionAuth - traditional method that pulls tokens from local storage

Not available for MD.
Used by default if a session option is passed to the client, but this is only for backwards compatibility.

const client = new Client({
    session: { } // session data here from wherever you get it from
});

Should be used explicitly to be able to get the payload in the auth event without passing a session:

const client = new Client({
    authStrategy: new LegacySessionAuth({
        session: { } // session data here from wherever you get it from
    })
});

NoAuth - does not provide any auth saving

Used by default if no session option is passed

const client = new Client({
    authStrategy: new NoAuth()
});

@pedroslopez pedroslopez mentioned this pull request Feb 27, 2022
@pedroslopez pedroslopez marked this pull request as ready for review February 27, 2022 23:06
@pedroslopez pedroslopez added the enhancement New feature or request label Feb 28, 2022
@pedroslopez pedroslopez merged commit f6de161 into main Feb 28, 2022
@pedroslopez pedroslopez deleted the auth-strategies branch February 28, 2022 02:02
Belfio pushed a commit to Belfio/whatsapp-web.js that referenced this pull request Jan 9, 2024
* auth strategies

* default to no auth

* rename base auth strategy

* rename base strategy cont.

* refactor auth strategy methods and LocalAuth

* activate old session options even if is falsy value

* move restartOnAuthFail to LegacyAuthStrategy option

* add link to guide item

* update example/shell

* types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant