Skip to content

PassportJs Strategy implementation for Zalo - A common social messaging app in Vietnam

Notifications You must be signed in to change notification settings

gugugiyu/passport-zalo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Passport Zalo

Static Badge Static Badge

Note: This is the forked version to bump up the API to the up-to-date Zalo v4 (More info here) from longldktmm's project and this will be a LTS project from me.

Installation

I haven't npm'ed it yet, so you'll have to pull the whole lib and setup it yourself

mkdir passport-zalo
cd passport-zalo
git init
git pull https://github.com/gugugiyu/passport-zalo.git

Documentations

Prerequisites

With the introduction of PKCE verification in the new OAuth API, the library will now make use of express-session to store the pkce pair generated per session, and crypto to generate the pkce verfier. So you'll to npm that as well

npm i express-session crypto
Configuring the strategy

Like other strategies of PassportJs, the config are pretty much the same:

// Make sure you imported it
var ZaloStrategy = require("../path/to/lib/passport-zalo/index").Strategy;

passport.use(new ZaloStrategy(
    {
    appId: process.env.ZALO_CLIENT_ID,
    appSecret: process.env.ZALO_CLIENT_SECRET,
    callbackURL: 'YOUR_CALL_BACK_URL',
     /* This is required to prevent csrf attacks, will be sent back with the auth code */
     state: "test",
    },
    (accessToken, refreshToken, profile, session, cb) => {
        /* Handle logics here */
        cb(null, user);
    }
)
);
Authenticating users
// Main authentication endpoint
app.get("/auth/zalo", passport.authenticate("zalo"));

// Callback
app.get("/auth/zalo/callback", passport.authenticate("zalo", {failureRedirect: `/login`,}),
  (req, res) => {
    /* Success, handle the logic here */
    res.redirect('/home');
  } 
);

FAQs

How can I require custom fields ?

The default profile includes the following:

  • Id (platform-unique ID)
  • Birthday
  • Name
  • Gender
  • Picture

But you can overwrite it here

// Callback
app.get("/auth/zalo/callback", passport.authenticate("zalo", 
{
    failureRedirect: `/login`,
    fields: ["extra", "custom", "fields"]
}),
  (req, res) => {
    /* Success, handle the logic here */
    res.redirect('/home');
  } 
);
What exactly is PKCE?

Contributions

Just file up a pull request, and (hopefully) I'll take a look at your ideas!

About

PassportJs Strategy implementation for Zalo - A common social messaging app in Vietnam

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%