Nighttime Pachinko Marathon
Miss any of our Open RFC calls?Watch the recordings here! »

passport-typetalk

1.0.7 • Public • Published

passport-typetalk

Build Status Coverage Status npm version chat on gitter

Passport strategy for authenticating with Typetalk using the OAuth 2.0 API.

Install

$ npm install passport-typetalk

Usage

Express example

const TypetalkStrategy = require("passport-typetalk").Strategy,
    config = require("./config"),
    express = require("express"),
    passport = require("passport");
 
const PORT = 3000,
    app = express();
 
passport.use(new TypetalkStrategy({
    "callbackURL": "http://localhost:3000/auth/typetalk/callback",
    "clientID": config.clientID,
    "clientSecret": config.clientSecret,
    "scope": [
        "my",
        "topic.read"
    ]
}, (accessToken, refreshToken, profile, cb) => cb(null, profile)));
 
passport.serializeUser((user, cb) => {
    cb(null, user);
});
 
passport.deserializeUser((obj, cb) => {
    cb(null, obj);
});
 
app.use(require("morgan")("combined"));
app.use(require("cookie-parser")());
app.use(require("body-parser").urlencoded({"extended": true}));
app.use(require("express-session")({
    "resave": true,
    "saveUninitialized": true,
    "secret": "keyboard cat"
}));
 
app.use(passport.initialize());
app.use(passport.session());
 
app.get("/", (req, res) => {
    res.send('<a href="/auth/typetalk">Login with Typetalk</a>');
});
 
app.get("/profile", (req, res) => {
    res.send(`<p>ID: ${req.user.id}</p><p>Name: ${req.user.name}</p>`);
});
 
app.get(
    "/auth/typetalk",
    passport.authenticate("typetalk")
);
 
app.get(
    "/auth/typetalk/callback",
    passport.authenticate("typetalk", {"failureRedirect": "/"}),
    (req, res) => {
        res.redirect("/profile");
    }
);
 
app.listen(PORT);

For working example, see this repository

API Documents

Here.

Install

npm i passport-typetalk

DownloadsWeekly Downloads

1

Version

1.0.7

License

MIT

Unpacked Size

1.21 MB

Total Files

55

Last publish

Collaborators

  • avatar