Parse OAuth2 SNS (Social Media)
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
-
Use internal browser (like Android Webview)
-
Open auth url : /facebook/auth
http://__your_host__/oauth2/facebook/auth
-
Check url changed to '/callback'
-
Then url chenged to '/callback', get authdata from body.
// URL : facebook/callback"access_token":"...""expiration_date":"..."
For Web
- Open auth url with URL in callback parameter : /facebook/auth?callback=URL
windowlocationhref = "http://__your_host__/oauth2/facebook/auth?callback=" + ;
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 |
- 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'.processenvSERVER_URL = "http://__host__:__port__/parse";processenvAPP_ID = "__app_id__";processenvMASTER_KEY = "__master_key__";processenvFB_APPIDS = "__fb_key__";processenvFB_SECRETS = "__fb_secret__";processenvGOOGLE_APPIDS = "__google_key__";processenvGOOGLE_SECRETS = "__goole_secret__";processenvINSTA_APPIDS = "__insta_key__";processenvINSTA_SECRETS = "__insta_secret__";processenvNAVER_APPIDS = "__naver_key__";processenvNAVER_SECRETS = "__naver_secret__";processenvDAUM_APPIDS = "__daum_key__";processenvDAUM_SECRETS = "__daum_secret__";processenvKAKAO_RESTKEY = "__kakao_restkey__";processenvKAKAO_SECRETS = "__kakao_secret__";
Router using Express
-
load module
// es6;;;;// es5var express = ;var session = ;var SocialOAuth2 = default;var bodyParser = ; -
create object
// for use req.sessionapp;// for use req.bodyapp;// OAuth2app;// OR OAuth2 + userObject Handler// Handler is normal function or promise function.app; -
Full code is in test.js
Addon Features
User
-
user block/ban
- if user.isBanned value is setted, user can't login.