All Projects → JMPerez → Passport Spotify

JMPerez / Passport Spotify

Licence: mit
Spotify authentication strategy for Passport and Node.js.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Passport Spotify

react-redux-passport-uikit-express-boiler
A React+Redux boilerplate using Express as backend, UIKit for frontend, MongoDB for storage & Passport for auth.
Stars: ✭ 59 (-77.82%)
Mutual labels:  passport, passportjs
Mern Stack Authentication
Secure MERN Stack CRUD Web Application using Passport.js Authentication
Stars: ✭ 60 (-77.44%)
Mutual labels:  passport, passportjs
Node Express Mongoose Passport Jwt Rest Api Auth
Node, express, mongoose, passport and JWT REST API authentication example
Stars: ✭ 146 (-45.11%)
Mutual labels:  passport, passportjs
passport-42
Passport strategy for authenticating with 42 using the OAuth 2.0 API
Stars: ✭ 26 (-90.23%)
Mutual labels:  passport, passportjs
ExpressJS-SocketIO-Boilerplate
📦 Simple Express.js & Socket.io Boilerplate
Stars: ✭ 31 (-88.35%)
Mutual labels:  passport, passportjs
node-express-mongo-passport-jwt-typescript
A Node.js back end web application with REST API, user JWT authentication and MongoDB data storage using TypeScript
Stars: ✭ 51 (-80.83%)
Mutual labels:  passport, passportjs
react-node-twitter-login
Demo application that shows how to enable Twitter login with React on frontend and Node.js/Express on backend
Stars: ✭ 34 (-87.22%)
Mutual labels:  passport, passportjs
passport-examples
A variety of examples using PassportJS with ExpressJS and ReactJS applications
Stars: ✭ 44 (-83.46%)
Mutual labels:  spotify, passportjs
ypc
Convert text/spotify/deezer albums/playlists to youtube urls and audio/video files.
Stars: ✭ 17 (-93.61%)
Mutual labels:  spotify
spotify-url-info
Get metadata from Spotify URL.
Stars: ✭ 34 (-87.22%)
Mutual labels:  spotify
api-old
The official API for the Spotistats app (Android + iOS) 💚
Stars: ✭ 33 (-87.59%)
Mutual labels:  spotify
nest-js-boilerplate
Nest.js boilerplate
Stars: ✭ 79 (-70.3%)
Mutual labels:  passport
spoti-vote
Web application to vote the next Song in Spotify Queue
Stars: ✭ 14 (-94.74%)
Mutual labels:  spotify
Spotify-Song-Recommendation-ML
UC Berkeley team's submission for RecSys Challenge 2018
Stars: ✭ 70 (-73.68%)
Mutual labels:  spotify
Passport Auth0
Auth0 authentication strategy for Passport.js
Stars: ✭ 256 (-3.76%)
Mutual labels:  passport
Easify-iOS
An iOS application to test out Spotify API. It uses SwiftUI and Combine.
Stars: ✭ 15 (-94.36%)
Mutual labels:  spotify
nestjs-auth-starter-kit
NestJS Auth Starter Kit (typescript / typeorm / swagger / passport / bcrypt)
Stars: ✭ 37 (-86.09%)
Mutual labels:  passport
Passport
Laravel Passport provides OAuth2 server support to Laravel.
Stars: ✭ 2,936 (+1003.76%)
Mutual labels:  passport
clipinc
A browser extension to record Spotify songs as you listen to them.
Stars: ✭ 17 (-93.61%)
Mutual labels:  spotify
larafy
Larafy is a Laravel package for Spotify API. It is more like a wrapper for the Spotify API.
Stars: ✭ 53 (-80.08%)
Mutual labels:  spotify

Passport-Spotify

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

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

For more information about Spotify's OAuth 2.0 implementation, check their Web API Authorization Guide.

Installation

$ npm install passport-spotify

Usage

Configure Strategy

The Spotify authentication strategy authenticates users using a Spotify account and OAuth 2.0 tokens. The strategy requires a verify callback, which accepts these credentials and calls done providing a user, as well as options specifying a client ID, client secret, and callback URL.

const SpotifyStrategy = require('passport-spotify').Strategy;

passport.use(
  new SpotifyStrategy(
    {
      clientID: client_id,
      clientSecret: client_secret,
      callbackURL: 'http://localhost:8888/auth/spotify/callback',
    },
    function (accessToken, refreshToken, expires_in, profile, done) {
      User.findOrCreate({spotifyId: profile.id}, function (err, user) {
        return done(err, user);
      });
    }
  )
);

Authenticate Requests

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

For example, as route middleware in an Express application:

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

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

Using scopes

Depending on the data you want to fetch, you may want to specify custom scopes. For more information about scopes in the Spotify Web API check their developer site.

By default, no scope is passed. That means that you won't fetch information such as display name, picture or email. You can get those by using these scopes:

  • user-read-email: Returns the email address of the user on Spotify, if it exists.
  • user-read-private: Returns private information about the user such as display name and picture, if they are set.

You can specify the parameters in the authenticate call:

app.get(
  '/auth/spotify',
  passport.authenticate('spotify', {
    scope: ['user-read-email', 'user-read-private'],
  })
);

Forcing login dialog

You can force the login dialog using the showDialog parameter when authenticating:

app.get(
  '/auth/spotify',
  passport.authenticate('spotify', {
    scope: ['user-read-email', 'user-read-private'],
    showDialog: true,
  })
);

Examples

For a complete, working example, refer to the login example.

You can get your keys on Spotify - My Applications.

Tests

$ npm install --dev
$ npm test

Build and Coverage Status

Actions Status

License

The MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].