Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

passport-snapchat

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

passport-snapchat

Snapchat (OAuth 2.0) authorization strategy for Passport.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.3K
increased by6.36%
Maintainers
1
Weekly downloads
 
Created
Source

passport-snapchat

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

This module lets you authenticate using Snapchat in your Node.js applications. By plugging into Passport, Snapchat authorization can easily and unobtrusively be integrated into any application or framework that supports Connect-style middleware, including Express.

Install

$ npm install passport-snapchat

API Reference

Usage

Create an Application

Before using passport-snapchat, you must register an application with Snapchat. If you have not already done so, a new application can be created within the Snap Kit Developer Portal. Your application will be issued an app ID and app secret, which need to be provided to the strategy. You will also need to configure a redirect URI which matches the route in your application.

Configure Strategy

The Snapchat authorization strategy authenticates users using a Snapchat account and OAuth 2.0 tokens. The app ID and secret obtained when creating an application are supplied as options when creating the strategy. The strategy also requires a verify callback, which receives the access token and optional refresh token, as well as profile which contains the authenticated user's Snapchat profile. The verify callback must call cb providing a user to complete authorization.

passport.use(new SnapchatStrategy({
    clientID: snapchat_APP_ID,
    clientSecret: snapchat_APP_SECRET,
    callbackURL: "http://localhost:3000/auth/snapchat/callback"
  },
  function(accessToken, refreshToken, profile, cb) {
    User.findOrCreate({ snapchatId: profile.id }, function (err, user) {
      return cb(err, user);
    });
  }
));
Authenticate Requests

Use passport.authenticate(), specifying the 'snapchat' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get('/auth/snapchat',
  passport.authenticate('snapchat'));

app.get('/auth/snapchat/callback',
  passport.authenticate('snapchat', { failureRedirect: '/login' }),
  function(req, res) {
    // Successful authorization, redirect home.
    res.redirect('/');
  });

Examples

Developers using the popular Express web framework can refer to an example as a starting point for their own web applications.

FAQ

How do I ask a user for additional permissions?

If you need additional permissions from the user, the permissions can be requested via the scope option to passport.authenticate().

app.get('/auth/snapchat',
  passport.authenticate('snapchat', { scope: ['user.display_name', 'user.bitmoji.avatar'] }));

Refer to permissions with Snapchat Login for further details.

How do I obtain a user profile with specific fields?

The Snapchat profile contains information about a user. By default, NO fields in a profile are returned. The fields needed by an application can be indicated by setting the profileFields option.

new SnapchatStrategy({
  clientID: snapchat_APP_ID,
  clientSecret: snapchat_APP_SECRET,
  callbackURL: "http://localhost:3000/auth/snapchat/callback",
  profileFields: ['id', 'displayName', 'bitmoji']
}), ...)

Refer to the Login Kit section of the docs for the complete set of available fields.

Contributing

Tests

The test suite is located in the test/ directory. All new features are expected to have corresponding test cases. Ensure that the complete test suite passes by executing:

$ npm test

License

The MIT License

Copyright (c) 2018 Snap Inc.

Keywords

FAQs

Package last updated on 28 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc