npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

parse-oauth2-sns

v1.3.3

Published

Parse-server module for implementing an OAuth2 Social Media Login with Express in Node.js

Downloads

45

Readme

Parse OAuth2 SNS (Social Media)

npm version

Node.JS & Express module for social media (Facebook, Google, Instagram) auth and login to parse-server. Plus, Korean SNS (Social Media) supports (Naver, Daum, Kakao)

Install

npm install --save parse-oauth2-sns

np How to Use


For Application

  1. Use internal browser (like Android Webview)

  2. Open auth url : /facebook/auth

http://__your_host__/oauth2/facebook/auth
  1. Check url changed to '/callback'

  2. Then url chenged to '/callback', get authdata from body.

// URL : facebook/callback
{"access_token":"...","expiration_date":"..."}

For Web

  1. Open auth url with URL in callback parameter : /facebook/auth?callback=URL
window.location.href =
  "http://__your_host__/oauth2/facebook/auth?callback=" +
  encodeURIComponent("/loginCallback?type=facebook");

| Params | Type | Description | | -------- | ------ | :------------------------------------------------------------------ | | callback | string | callback url. Redirected after authentication | | host | string | If using proxy, can change api url host. ex) host=your_host/api |

  1. Then URL is called, get authdata from querystring.
http://__host__/loginCallback?type=facebook&access_token=...& expiration_date=...

Routes

Facebook Routes

  • /facebook/auth

    • request [get] : callback (url, option), host (url, option)

    • response : redirect to Facebook OAuth page

  • /facebook/callback

    • request : from facebook OAuth page

    • response : json

    {"access_token":"...","expiration_date":"..."}
  • /facebook/login

    • request [post] : json (facebook auth info)
    {"access_token":"...","expiration_date":"..."}
    • response : parse-serve user object (username equal to facebook email)
    {"objectId": "ziJdB2jBul", "username": "__facebook.email__", authData, ...}

Google Routes

  • /google/auth

    • request [get] : callback (url, option), host (url, option)

    • response : redirect to Google OAuth page

  • /google/callback

    • request : from google OAuth page

    • response : json

    {"access_token":"...","expiration_date":"..."}
  • /google/login

    • request [post] : json (google auth info)
    {"access_token":"...","expiration_date":"..."}
    • response : parse-serve user object (username equal to google email)
    {"objectId": "ziJdB2jBul", "username": "__google.email__", authData, ...}

Instagram Routes

  • /instagram/auth

    • request [get] : callback (url, option), host (url, option)

    • response : redirect to Instagram OAuth page

  • /instagram/callback

    • request : from instagram OAuth page

    • response : json

    {"access_token":"...","user":"..."}
  • /instagram/login

    • request [post] : json (instagram auth info)
    {"access_token":"..."}
    • response : parse-server user object (username equal to instagram username)
    {"objectId": "ziJdB2jBul", "username": "__instagram.username__", authData, ...}
  • /instagram/link : parse-server user link to instagram user.

    • request [post] : instagram token and parse-server user info.
    {"access_token":"", "username": "__parse-server user.username__"}
    • response : parse-server user object linked instagram
    {"objectId": "ziJdB2jBul", "username": "__username__", authData, ...}
  • /instagram/recent : get recent post from instagram

    • request [get] : userId (parse-server user.objectId)

    • response : instagram posts

    [{images, caption, comments, ...}, ...]

Naver Routes

  • /naver/auth

    • request [get] : callback (url, option), host (url, option)

    • response : redirect to naver OAuth page

  • /naver/callback

    • request : from naver OAuth page

    • response : json

    {"access_token":"...","expiration_date":"..."}
  • /naver/login

    • request [post] : json (naver auth info)
    {"access_token":"...","expiration_date":"..."}
    • response : parse-serve user object (username equal to naver email)
    {"objectId": "ziJdB2jBul", "username": "__naver.email__", authData, ...}

Daum Routes

  • /daum/auth

    • request [get] : callback (url, option), host (url, option)

    • response : redirect to daum OAuth page

  • /daum/callback

    • request : from daum OAuth page

    • response : json

    {"access_token":"...","expiration_date":"..."}
  • /daum/login

    • request [post] : json (daum auth info)
    {"access_token":"...","expiration_date":"..."}
    • response : parse-server user object (username equal to daum userid, not email provided)
    {"objectId": "ziJdB2jBul", "username": "__daum.userid__", authData, ...}

Kako Routes

  • /kakao/auth

    • request [get] : callback (url, option), host (url, option)

    • response : redirect to kakao OAuth page

  • /kakao/callback

    • request : from kakao OAuth page

    • response : json

    {"access_token":"...","expiration_date":"..."}
  • /kakao/login

    • request [post] : json (kakao auth info)
    {"access_token":"...","expiration_date":"..."}
    • response : parse-server user object (username equal to kakao email or kakao userid)
    {"objectId": "ziJdB2jBul", "username": "__kakao.(kaccount_email||id)__", authData, ...}

Initialize

Setup up process.env

  • It's work with parse-rest-nodejs.

    // Recommend to use 'better-npm-run'.
    process.env.SERVER_URL = "http://__host__:__port__/parse";
    process.env.APP_ID = "__app_id__";
    process.env.MASTER_KEY = "__master_key__";
    process.env.FB_APPIDS = "__fb_key__";
    process.env.FB_SECRETS = "__fb_secret__";
    process.env.GOOGLE_APPIDS = "__google_key__";
    process.env.GOOGLE_SECRETS = "__goole_secret__";
    process.env.INSTA_APPIDS = "__insta_key__";
    process.env.INSTA_SECRETS = "__insta_secret__";
    process.env.NAVER_APPIDS = "__naver_key__";
    process.env.NAVER_SECRETS = "__naver_secret__";
    process.env.DAUM_APPIDS = "__daum_key__";
    process.env.DAUM_SECRETS = "__daum_secret__";
    process.env.KAKAO_RESTKEY = "__kakao_restkey__";
    process.env.KAKAO_SECRETS = "__kakao_secret__";

Router using Express

  • load module

    // es6
    import express from "express";
    import session from "express-session";
    import SocialOAuth2 from "parse-oauth2-sns";
    import bodyParser from "body-parser";
    // es5
    var express = require("express");
    var session = require("session");
    var SocialOAuth2 = require("parse-oauth2-sns").default;
    var bodyParser = require("body-parser");
  • create object

    // for use req.session
    app.use(
      session({
        secret: "___secret_key_for_session___",
        resave: false,
        saveUninitialized: false
        // cookie: { maxAge: 60000 }
      })
    );
    // for use req.body
    app.use(bodyParser.json());
    
    // OAuth2
    app.use("/oauth2", SocialOAuth2.create({ path: "/oauth2" }));
    // OR OAuth2 + userObject Handler
    // Handler is normal function or promise function.
    app.use('/oauth2', SocialOAuth2.create({ path: '/oauth2', userHandler: function(req, user) { ...  return user; } }));
  • Full code is in test.js

Addon Features

User

  • user block/ban

    • if user.isBanned value is setted, user can't login.