Skip to content

Precis-Digital/passport-pinterest

 
 

Repository files navigation

passport-pinterest

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

CI

Supports the Pinterest v5 API. Plugs into Passport for seamless integration with any Connect-style middleware, including Express.

Installation

npm install passport-pinterest

Usage

TypeScript

import { Strategy as PinterestStrategy, Profile } from "passport-pinterest";

passport.use(
  new PinterestStrategy(
    {
      clientID: process.env.PINTEREST_CLIENT_ID!,
      clientSecret: process.env.PINTEREST_CLIENT_SECRET!,
      callbackURL: "https://example.com/auth/pinterest/callback",
      scope: ["user_accounts:read"],
    },
    (accessToken: string, refreshToken: string, profile: Profile, done) => {
      User.findOrCreate({ pinterestId: profile.id }, (err, user) => {
        done(err, user);
      });
    },
  ),
);

JavaScript

const { Strategy: PinterestStrategy } = require("passport-pinterest");

passport.use(
  new PinterestStrategy(
    {
      clientID: process.env.PINTEREST_CLIENT_ID,
      clientSecret: process.env.PINTEREST_CLIENT_SECRET,
      callbackURL: "https://example.com/auth/pinterest/callback",
      scope: ["user_accounts:read"],
    },
    function (accessToken, refreshToken, profile, done) {
      User.findOrCreate({ pinterestId: profile.id }, function (err, user) {
        done(err, user);
      });
    },
  ),
);

Routes

app.get("/auth/pinterest", passport.authenticate("pinterest"));

app.get(
  "/auth/pinterest/callback",
  passport.authenticate("pinterest", { failureRedirect: "/login" }),
  function (req, res) {
    res.redirect("/");
  },
);

Profile

The profile object passed to the verify callback:

Field Type Description
id string Pinterest user ID
displayName string Username, or "<business_name> <username> (Business)" for business accounts
_json object Full raw response from the Pinterest API
_raw string Raw JSON string from the Pinterest API

Scopes

See the Pinterest scopes reference for the full list. Common values:

Scope Description
user_accounts:read Read access to the user's account
pins:read Read access to the user's pins
boards:read Read access to the user's boards

Note: Pinterest only allows HTTPS callback URLs in production.

Contributing

git clone https://github.com/analog-nico/passport-pinterest.git
cd passport-pinterest
npm install
Script Description
npm test Run tests
npm run lint Lint with oxlint
npm run lint:fix Lint and auto-fix
npm run fmt Format with oxfmt
npm run fmt:check Check formatting without modifying files
npm run typecheck TypeScript type validation
npm run test:coverage Run tests with coverage report
npm run ci Run all checks (fmt + lint + typecheck + test)

License (ISC)

See the LICENSE file for details.

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 83.0%
  • TypeScript 17.0%