Giter Club home page Giter Club logo

unsplash-auth's Introduction

Sign in with Unsplash for Passport JS

Follow @neerajp99

Passport Strategy for the sign in with Unsplash, with profile information !

Installation

Install the package via npm / yarn: npm install --save unsplash-passport

You will also need to install & configure body-parser if using Express: npm install --save body-parser

const bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: true }));

Next, you need to configure your Unsplash Developer account by creating OAuth applications here: https://unsplash.com/developers

Usage

The Unsplash authentication strategy authenticates users via Unsplash user account and OAuth 2.0 token(s). An Unsplash API Client ID, secret and redirect URL must be supplied when using this strategy. The strategy also requires a verify callback, which receives the access token and an optional refresh token, as well as a profile which contains the authenticated Unsplash user's profile. The verify callback must also call cb or done providing a user to complete the authentication.

Initialize the strategy as follows:

const UnsplasgStrategy = require('unsplash-passport').Strategy;
let scopes = ['public', 'read_user'];
passport.use(new UnsplashStrategy({
    clientID: "",
    clientSecret: "",
    callbackURL: "",
    scope: scopes
}, function(accessToken, refreshToken, profile, done) {
    // asynchronous verification, for effect...
    process.nextTick(function () {
    return done(null, profile);
}));

Authenticate Requests

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

On successful authentication, add the callback route and handle the response.

For example, as route middleware in an Express application:

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

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

Examples

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

Questions / Contributing

Feel free to open issues and pull requests. If you would like to be one of the core creators of this library, message me on twitter @neerajp99!

Created with ❤️ by Neeraj Pandey

unsplash-auth's People

Contributors

neerajp99 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.