Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ module.exports = function( grunt ) {
unit: {
options: {
require: [ 'chai' ],
reporter: 'spec'
reporter: 'spec',
timeout: 5000
},
src: [ 'tests/unit/*.js' ].concat( getModulePaths( 'tests', 'unit', '*.js' ) )
},
Expand Down
2 changes: 1 addition & 1 deletion lib/config/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
var path = require( 'path' );

module.exports = require( path.resolve( [ __dirname, '..', 'config' ].join( path.sep ) ) + path.sep );
module.exports = require( path.resolve( [ __dirname, '..', '..', 'config' ].join( path.sep ) ) + path.sep );
59 changes: 0 additions & 59 deletions modules/auth/module.js

This file was deleted.

27 changes: 0 additions & 27 deletions modules/auth/package.json

This file was deleted.

21 changes: 21 additions & 0 deletions modules/clever-auth-dropbox/config/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"clever-auth-dropbox": {
"secretKey": "youMustChangeMe",

"redis": {
"host": "localhost",
"port": "6379",
"prefix": "",
"key": ""
},

"dropbox": {
"AppKey": "8hbtahx62cl0x8c",
"AppSecret": "l1cp2c2u3gsll1h",
"redirectURIs": "http://localhost:8080/auth/dropbox/return"
},

"frontendURL": "http://localhost:9000/"

}
}
120 changes: 120 additions & 0 deletions modules/clever-auth-dropbox/controllers/UserDropboxController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
var config = require ( 'config' )[ 'clever-auth-dropbox' ]
, passport = require ( 'passport' )
, qs = require ( 'qs' )
, DropboxOAuth2Strategy = require( 'passport-dropbox-oauth2' ).Strategy;

var state = +new Date() + '';

module.exports = function ( UserDropboxService ) {

passport.serializeUser( function ( user, done ) {
done( null, user );
} );

passport.deserializeUser( function ( user, done ) {
done( null, user )
} );

passport.use( new DropboxOAuth2Strategy(
{
clientID: config.dropbox.AppKey,
clientSecret: config.dropbox.AppSecret,
callbackURL: config.dropbox.redirectURIs,
state: state
},
function ( accessToken, refreshToken, profile, done ) {

UserDropboxService
.findOrCreate( profile, accessToken )
.then( function( gUser ) {
return UserDropboxService.authenticate ( gUser, profile )
})
.then( UserDropboxService.updateAccessedDate )
.then( done.bind( null, null ) )
.fail( done );
}
));


return (require( 'classes' ).Controller).extend (
{
service: UserDropboxService
},
{
listAction: function () {
UserDropboxService.listUsers()
.then( this.proxy( 'handleServiceMessage' ) )
.fail( this.proxy( 'handleException' ) );
},

getAction: function () {
var guId = this.req.params.id;

UserDropboxService
.findUserById( guId )
.then( this.proxy( 'handleServiceMessage' ) )
.fail( this.proxy( 'handleException' ) );
},

deleteAction: function () {
var guId = this.req.params.id;

UserDropboxService.deleteUser( guId )
.then( this.proxy( 'handleServiceMessage' ) )
.fail( this.proxy( 'handleException' ) );
},

loginAction: function () {
var params = {
response_type: "code",
client_id: config.dropbox.AppKey,
redirect_uri: config.dropbox.redirectURIs,
state: state
};

this.send( { url: 'https://www.dropbox.com/1/oauth2/authorize?' + qs.stringify( params ) }, 200 );

},

returnAction: function () {
passport.authenticate( 'dropbox-oauth2', this.proxy( 'handleLocalUser' ) )( this.req, this.res, this.next );
},

handleLocalUser: function ( err, user ) {
if ( err ) return this.handleException( err );

if ( !user ) {
this.res.statusCode = 302;
this.res.setHeader( 'body', {} );
this.res.setHeader( 'Location', config.frontendURL );
this.res.end();
} else {
this.loginUserJson( user );
}
},

loginUserJson: function ( user ) {
this.req.login( user, this.proxy( 'handleLoginJson', user ) );
},

handleLoginJson: function ( user, err ) {
if ( err ) return this.handleException( err );

this.res.statusCode = 302;
this.res.setHeader( 'body', user );
this.res.setHeader( 'Location', config.frontendURL );
this.res.end();
},

handleServiceMessage: function ( obj ) {

if ( obj.statuscode ) {
this.send( obj.message, obj.statuscode );
return;
}

this.send( obj, 200 );
}

} );
};
66 changes: 66 additions & 0 deletions modules/clever-auth-dropbox/models/orm/UserDropboxModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module.exports = function ( sequelize, DataTypes ) {
return sequelize.define( "UserDropbox",
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
validate: {
isEmail: true
}
},
firstname: {
type: DataTypes.STRING,
allowNull: true
},
lastname: {
type: DataTypes.STRING,
allowNull: true
},
dropboxid: {
type: DataTypes.INTEGER,
allowNull: false
},
link: {
type: DataTypes.STRING,
allowNull: true
},
locale: {
type: DataTypes.STRING,
allowNull: true
},
token: {
type: DataTypes.STRING,
allowNull: false
},
accessedAt: {
type: DataTypes.DATE
},
UserId: {
type: DataTypes.INTEGER
}
},
{
paranoid: true,

getterMethods: {
fullName: function () {
return [ this.getDataValue( 'firstname' ), this.getDataValue( 'lastname' )].join( ' ' );
}
},

instanceMethods: {
toJSON: function () {
var values = this.values;
values.fullName = this.fullName;
delete values.token;
return values;
}
}
} );
};
Loading