Permalink
Browse files

Removed old ideas for API to deprecated.js

  • Loading branch information...
bnoguchi committed Apr 5, 2011
1 parent 31e6cb5 commit f6a40e1a85afe05f285488732c91459d1c0ba7db
Showing with 23 additions and 180 deletions.
  1. +0 −69 lib/facebook.alt.js
  2. +23 −111 lib/oauth.alt.js
View
@@ -35,72 +35,3 @@ oauthModule.submodule('facebook')
.define( function (sess, auth) {
})
-
-// Introspection
-console.log( fb.steps );
-
-// Make order of steps explicit
-// fb.seq(...)
-fb.steps.order('authRequest', 'authCallback', 'addToSession');
-
-fb.step('authRequest').steps.order(
- 'handleRequest', 'determineScope',
- 'generateAuthUri', 'redirectToAuthUri');
-// `order(...)` should throw an error if it is missing a step
-
-
-
-
-
-
-
-
-
-
-////////////////////////////////////////
-
-function findUser (cred, fbUserMetadata) {
- var p = new Promise();
- User.find({id: 1}, function (err, user) {
- p.succeed(err, user);
- });
- return p;
-}
-
-function orCreateUser(err, user) {
- var p = new Promise();
- if (user) {
- p.succeed(null, user);
- } else {
- User.create({}, function (err, user) {
- p.succeed(err, user);
- });
- }
- return p;
-}
-
-function assignToSession (sess, user, cred, fbData) {
- var p = new Promise();
- // Logic goes here
- p.succeed(sess, user, cred, fbData);
- return p;
-}
-
-function anon (req, res, uid, cred, info) {}
-
-function anon2 (req, res, provider, uid, cred, info) {}
-
-everyauth(
- function (req, res, provider, cred, info) {
- }
- , facebook(
- function (req, res, uid, cred, info) {
- }
- , userLogic(
- )
- )
- , twitter(
- function (req, res, uid, cred, info) {
- }
- )
-);
View
@@ -11,7 +11,7 @@ everyModule.submodule('oauth')
.init( function () {
this.oauth = new OAuth(this.appId(), this.appSecret(), this.apiHost());
})
- .configurable('apiHost appId appSecret myHostname')
+ .configurable('apiHost appId appSecret myHostname redirectPath')
.get('entryPath')
.step('getAuthUri')
.accepts('req res')
@@ -29,17 +29,17 @@ everyModule.submodule('oauth')
.step('fetchOAuthUser')
.accepts('accessToken refreshToken')
.promises('user')
+ .step('compile')
+ .accepts('accessToken refreshToken user')
+ .promises('auth')
.step('getSession')
.accepts('req')
.promises('session')
.step('addToSession')
.accepts('session')
.promises(null)
- .step('compile')
- .accepts('accessToken refreshToken user')
- .promises('auth')
.step('sendResponse')
- .accepts('req res auth')
+ .accepts('res')
.promises(null)
.getAuthUri( function (req, res) {
var oauth = this._oauth
@@ -66,117 +66,29 @@ everyModule.submodule('oauth')
});
return p;
})
- .getSession( function (req) {
- return req.session;
- })
.compile( function (accessToken, refreshToken, user) {
return {
- accessToken
- , refreshToken
- , user
+ accessToken: accessToken
+ , refreshToken: refreshToken
+ , user: user
};
- });
+ })
+ .getSession( function (req) {
+ return req.session;
+ })
+ .addToSession( function (session, auth) {
+ var _auth = session.auth || (session.auth = {})
+ , mod = _auth[this.name] || (_auth[this.name] = {});
+ for (var k in auth) {
+ mod[k] = auth[k];
+ }
+ // this._super() ?
+ })
+ .sendResponse( function (res) {
+ res.redirect(this.redirectPath());
+ })
// removeConfigurable
// removeStep
// undefinedSteps -> []
// How about module specific and more generic addToSession? Perhaps just do addToSession with null
-
-
-
-var oauth = module.exports =
-everyModule.submodule('oauth')
- .setters('apiHost entryUri callbackUri')
- .setupRoutes( function (mod, app) {
- app.get(mod._entryUri, mod.start('/auth/facebook'));
- // mod.start() creates a new instantiation of the promise chain
- // and returns the `trigger` of the first step
- app.get(mod._callbackUri, mod.start('auth/facebook/callback'));
- })
- // Define a sequence of steps named 'auth/facebook'
- .sequence('/auth/facebook')
- .step('requestAuthUri', function (substep) {
- substep('determineScope')
- .accepts('req res')
- .promises('scope')
- .define(fn)
- .error(fn);
- substep('generateAuthUri')
- .accepts('scope')
- .promises('authUri');
- substep('requestAuthUri')
- .accepts('authUri')
- .promises(null);
- })
- // reset vs bridge
- // bridge should create a hook for
- // instantiating a new chain of steps
- .sequence('/auth/facebook/callback')
- .step('retrieveCode')
- .accepts('req res')
- .promises('code')
- .step('retrieveAccessToken')
- .accepts('code')
- .promises('accessToken refreshToken')
- .step('getAuth')
- .accepts('accessToken refreshToken')
- .promises('auth');
- // define can define the step function
- // OR it can be the entry point for defining
- // the sub steps it is composed of
- .define( function (authRequest) {
- authRequest
- })
- .step('authCallback')
- .accepts('req res auth')
- .promises(null);
-
-oauth.step('authRequest/determineScope').define( function (req, res) {
- var scope = this._scope;
- if ('function' === typeof scope) {
- return scope(req);
- }
- return scope;
-});
-
-oauth.step('authRequest/generateAuthUri').define( function (scope) {
- var oauth = this._oauth
- , authUri = oauth.getAuthorizeUrl({
- redirect_uri: this._myHostname + this._callbackUri
- , scope: scope});
- return authUri;
-});
-
-oauth.step('authRequest/retrieveCode').define( function (authUri) {
- var res = this.cache.res;
- res.writeHead(303, {'Location': authUri});
- res.end();
-});
-
-
-// How to add steps to a module or to a composed step
-
-// Adds a series of steps
-oauth.step('authCallback', function (step) {
- step('addCronJob');
-});
-
-// Adds a single step
-oauth.step('authCallback');
-
-// Over-rides a sequence of substeps
-// composedOf vs override
-oauth.step('authCallback').override(function (step) {
- step(...);
-});
-
-oauth.step('authCallback').order('...');
-
-oauth.step('authCallback').addStep('addCronJob');
-
-oauth.step('authCallback').steps.order(...);
-
-oauth.step('authCallback').steps.add('addCronJob', {before: ''});
-
-oauth.step('authCallback').steps.add('addCronJob', {after: ''});
-

0 comments on commit f6a40e1

Please sign in to comment.