Permalink
...
Comparing changes
Open a pull request
- 4 commits
- 2 files changed
- 0 commit comments
- 2 contributors
Unified
Split
Showing
with
8 additions
and 62 deletions.
- +7 −59 lib/passport-tistory/strategy.js
- +1 −3 package.json
View
66
lib/passport-tistory/strategy.js
@@ -1,12 +1,7 @@ | ||
var util = require('util'), | ||
profile = require('./profile'), | ||
- querystring= require('querystring'), | ||
OAuth2Strategy = require('passport-oauth2'); | ||
- | ||
-var http = require('follow-redirects').http; | ||
-var https = require('follow-redirects').https; | ||
- | ||
/** | ||
* TistoryStrategy 생성자.<br/> | ||
* | ||
@@ -19,62 +14,17 @@ function TistoryStrategy(options, verify) { | ||
var oauthHost = 'https://www.tistory.com'; | ||
options = options || {}; | ||
options.authorizationURL = options.authorizationURL || oauthHost + '/oauth/authorize'; | ||
- options.tokenURL = options.tokenURL || oauthHost + '/oauth/access_token'; | ||
+ options.tokenURL = options.tokenURL || oauthHost + '/oauth/access_token/'; | ||
options.customHeaders = options.customHeaders || {}; | ||
- | ||
if (!options.customHeaders['User-Agent']) { | ||
options.customHeaders['User-Agent'] = options.userAgent || 'passport-tistory'; | ||
} | ||
- | ||
OAuth2Strategy.call(this, options, verify); | ||
this.name = 'tistory'; | ||
this._userProfileURL = 'https://www.tistory.com/apis/blog/info?output=json'; | ||
- | ||
- this._oauth2._chooseHttpLibrary= function( parsedUrl ) { | ||
- var http_library= https; | ||
- if( parsedUrl.protocol != "https:" ) { | ||
- http_library= http; | ||
- } | ||
- return http_library; | ||
- }; | ||
- | ||
- this._oauth2.getOAuthAccessToken= function(code, params, callback) { | ||
- var params= params || {}; | ||
- params['client_id'] = this._clientId; | ||
- params['client_secret'] = this._clientSecret; | ||
- var codeParam = (params.grant_type === 'refresh_token') ? 'refresh_token' : 'code'; | ||
- params[codeParam]= code; | ||
- | ||
- | ||
- var url = this._getAccessTokenUrl() + "?" + querystring.stringify(params); | ||
- | ||
- this._request("GET", url, {}, "", null, function(error, data, response) { | ||
- if( error ) callback(error); | ||
- else { | ||
- var results; | ||
- try { | ||
- // As of http://tools.ietf.org/html/draft-ietf-oauth-v2-07 | ||
- // responses should be in JSON | ||
- results= JSON.parse( data ); | ||
- } | ||
- catch(e) { | ||
- // .... However both Facebook + Github currently use rev05 of the spec | ||
- // and neither seem to specify a content-type correctly in their response headers :( | ||
- // clients of these services will suffer a *minor* performance cost of the exception | ||
- // being thrown | ||
- results= querystring.parse( data ); | ||
- } | ||
- var access_token= results["access_token"]; | ||
- var refresh_token= results["refresh_token"]; | ||
- delete results["refresh_token"]; | ||
- callback(null, access_token, refresh_token, results); // callback results =-= | ||
- } | ||
- }); | ||
- } | ||
- | ||
} | ||
/** | ||
@@ -99,15 +49,14 @@ util.inherits(TistoryStrategy, OAuth2Strategy); | ||
* @param {Function} done | ||
*/ | ||
TistoryStrategy.prototype.userProfile = function(accessToken, done) { | ||
- console.log("accessToken" + accessToken); | ||
- | ||
- this._oauth2.get(this._userProfileURL, accessToken, function (err, body, res) { | ||
- if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); } | ||
+ this._oauth2.get(this._userProfileURL, accessToken, function(err, body, res) { | ||
+ if (err) { | ||
+ return done(new InternalOAuthError('failed to fetch user profile', err)); | ||
+ } | ||
try { | ||
var json = JSON.parse(body); | ||
-// var profile = { provider: 'tistory' }; | ||
profile.status = json.tistory.status; | ||
profile.id = json.tistory.id; | ||
profile.userId = json.tistory.userId; | ||
@@ -118,14 +67,13 @@ TistoryStrategy.prototype.userProfile = function(accessToken, done) { | ||
done(null, profile); | ||
- } catch(e) { | ||
+ } catch (e) { | ||
done(e); | ||
} | ||
}); | ||
} | ||
- | ||
/** | ||
* Expose `TistoryStrategy`. | ||
*/ | ||
-module.exports = TistoryStrategy; | ||
+module.exports = TistoryStrategy; |
View
4
package.json
@@ -15,9 +15,7 @@ | ||
"main": "./lib/passport-tistory", | ||
"dependencies": { | ||
"passport": "~0.2.0", | ||
- "passport-oauth2":"~1.1.2", | ||
- "follow-redirects":"~0.0.3", | ||
- "querystring":"~0.2.0" | ||
+ "passport-oauth2":"~1.1.2" | ||
}, | ||
"licenses": [ { | ||
"type": "MIT", | ||