├── .npmignore ├── README.md ├── .gitignore ├── lib └── passport-imgur │ ├── index.js │ └── strategy.js ├── package.json └── LICENSE /.npmignore: -------------------------------------------------------------------------------- 1 | *.md 2 | .DS_Store 3 | .git* 4 | Makefile 5 | docs/ 6 | examples/ 7 | support/ 8 | test/ 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | passport-imgur 2 | ============== 3 | 4 | Passport strategy for authenticating with imgur's API using the OAuth 2.0 API. 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | npm-debug.log 15 | -------------------------------------------------------------------------------- /lib/passport-imgur/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Module dependencies. 3 | */ 4 | var Strategy = require('./strategy'); 5 | 6 | 7 | /** 8 | * Framework version. 9 | */ 10 | exports.version = '0.0.1'; 11 | 12 | /** 13 | * Expose constructors. 14 | */ 15 | exports.Strategy = Strategy; 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "passport-imgur", 3 | "version": "0.0.1", 4 | "description": "Imgur API authentication strategy for Passport.", 5 | "author": "Monday Freelem ", 6 | "repository": { 7 | "type": "git", 8 | "url": "http://github.com/mindfreakthemon/passport-imgur.git" 9 | }, 10 | "main": "./lib/passport-imgur", 11 | "dependencies": { 12 | "passport-oauth": ">= 0.1.0" 13 | }, 14 | "engines": { "node": ">= 0.4.0" }, 15 | "keywords": ["passport", "imgur", "oauth", "oauth2", "auth", "authentication", "identity"] 16 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Vitalii 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /lib/passport-imgur/strategy.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Module dependencies. 3 | */ 4 | var util = require('util'), 5 | OAuth2Strategy = require('passport-oauth').OAuth2Strategy, 6 | InternalOAuthError = require('passport-oauth').InternalOAuthError; 7 | 8 | 9 | /** 10 | * `Strategy` constructor. 11 | * 12 | * The Imgur API authentication strategy authenticates requests by delegating to 13 | * Imgur API using the OAuth 2.0 protocol. 14 | * 15 | * Applications must supply a `verify` callback which accepts an `accessToken`, 16 | * `refreshToken` and service-specific `profile`, and then calls the `done` 17 | * callback supplying a `user`, which should be set to `false` if the 18 | * credentials are not valid. If an exception occured, `err` should be set. 19 | * 20 | * Options: 21 | * - `clientID` your Imgur API application's App ID 22 | * - `clientSecret` your Imgur API application's App Secret 23 | * - `callbackURL` URL to which Imgur API will redirect the user after granting authorization 24 | * 25 | * Examples: 26 | * 27 | * passport.use(new ImgurStrategy({ 28 | * clientID: '123-456-789', 29 | * clientSecret: 'shhh-its-a-secret', 30 | * callbackURL: 'https://www.example.net/auth/imgur/callback' 31 | * }, 32 | * function(accessToken, refreshToken, profile, done) { 33 | * User.findOrCreate(..., function (err, user) { 34 | * done(err, user); 35 | * }); 36 | * } 37 | * )); 38 | * 39 | * @param {Object} options 40 | * @param {Function} verify 41 | * @api public 42 | */ 43 | function Strategy(options, verify) { 44 | options = options || {}; 45 | options.authorizationURL = options.authorizationURL || 'https://api.imgur.com/oauth2/authorize'; 46 | options.tokenURL = options.tokenURL || 'https://api.imgur.com/oauth2/token'; 47 | 48 | OAuth2Strategy.call(this, options, verify); 49 | this.name = 'imgur'; 50 | } 51 | 52 | /** 53 | * Inherit from `OAuth2Strategy`. 54 | */ 55 | util.inherits(Strategy, OAuth2Strategy); 56 | 57 | /** 58 | * Retrieve user profile from Imgur. 59 | * 60 | * This function constructs a normalized profile, with the following properties: 61 | * 62 | * - `provider` always set to `imgur` 63 | * - `id` The account id for the username requested. 64 | * - `url` The account username, will be the same as requested in the URL 65 | * - `bio` A basic description the user has filled out 66 | * - `reputation` The reputation for the account, in it's numerical format. 67 | * - `created` The epoch time of account creation 68 | * 69 | * @param {String} accessToken 70 | * @param {Function} done 71 | * @api protected 72 | */ 73 | Strategy.prototype.userProfile = function (accessToken, done) { 74 | this._oauth2.useAuthorizationHeaderforGET(true); 75 | this._oauth2.get('https://api.imgur.com/3/account/me/', accessToken, function (err, body, res) { 76 | if (err) { 77 | return done(new InternalOAuthError('failed to fetch user profiles', err)); 78 | } 79 | 80 | try { 81 | var json = JSON.parse(body); 82 | 83 | var profile = { provider: 'imgur' }; 84 | profile.id = json.data.id; 85 | profile.url = json.data.url; 86 | profile.bio = json.data.bio; 87 | profile.reputation = json.data.reputation; 88 | profile.created = json.data.created; 89 | 90 | profile._raw = body; 91 | profile._json = json; 92 | 93 | done(null, profile); 94 | } catch (e) { 95 | done(e); 96 | } 97 | }); 98 | }; 99 | 100 | 101 | /** 102 | * Expose `Strategy`. 103 | */ 104 | module.exports = Strategy; --------------------------------------------------------------------------------