LearnersGuild / idm

identity management service
MIT License
2 stars 24 forks source link

if already authenticated, redirect when visiting /sign-in or /sign-up #90

Closed jeffreywescott closed 8 years ago

jeffreywescott commented 8 years ago

Depends on #88. This cannot be merged before #88.

Fixes #87.

Note: because we do server-side rendering, there is some special-case stuff to handle redirection to a location outside of the IDM service; it has to happen client-side. It will be clear if you look at redirectIfSignedIn in common/routes/index.jsx.

heyheyjp commented 8 years ago

Not sure if I've missed something with setup, but I'm running into this error:

AuthorizationError: The redirect_uri MUST match the registered callback URL for this application.
   at Strategy.OAuth2Strategy.authenticate (/Users/essjay-lg/Development/lg/idm/node_modules/passport-oauth2/lib/strategy.js:131:25)
   at attempt (/Users/essjay-lg/Development/lg/idm/node_modules/passport/lib/middleware/authenticate.js:348:16)
   at authenticate (/Users/essjay-lg/Development/lg/idm/node_modules/passport/lib/middleware/authenticate.js:349:7)
   at github.js:119:14
   at Layer.handle [as handle_request] (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/layer.js:95:5)
   at next (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/route.js:131:13)
   at Route.dispatch (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/route.js:112:3)
   at Layer.handle [as handle_request] (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/layer.js:95:5)
   at /Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:277:22
   at Function.process_params (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:330:12)
   at next (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:271:10)
   at extendJWTExpiration (/Users/essjay-lg/Development/lg/idm/node_modules/@learnersguild/idm-jwt-auth/lib/middlewares.js:140:5)
   at Layer.handle [as handle_request] (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/layer.js:95:5)
   at trim_prefix (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:312:13)
   at /Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:280:7
   at Function.process_params (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:330:12)
   at next (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:271:10)
   at _callee$ (/Users/essjay-lg/Development/lg/idm/node_modules/@learnersguild/idm-jwt-auth/lib/middlewares.js:65:15)
   at tryCatch (/Users/essjay-lg/Development/lg/idm/node_modules/regenerator-runtime/runtime.js:62:40)
   at GeneratorFunctionPrototype.invoke [as _invoke] (/Users/essjay-lg/Development/lg/idm/node_modules/regenerator-runtime/runtime.js:336:22)
   at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/Users/essjay-lg/Development/lg/idm/node_modules/regenerator-runtime/runtime.js:95:21)
   at step (/Users/essjay-lg/Development/lg/idm/node_modules/@learnersguild/idm-jwt-auth/lib/middlewares.js:92:191)
   at /Users/essjay-lg/Development/lg/idm/node_modules/@learnersguild/idm-jwt-auth/lib/middlewares.js:92:451
   at new Promise (/Users/essjay-lg/Development/lg/idm/node_modules/core-js/modules/es6.promise.js:193:7)
   at /Users/essjay-lg/Development/lg/idm/node_modules/@learnersguild/idm-jwt-auth/lib/middlewares.js:92:99
   at refreshUserFromIDMService (/Users/essjay-lg/Development/lg/idm/node_modules/@learnersguild/idm-jwt-auth/lib/middlewares.js:77:16)
   at Layer.handle [as handle_request] (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/layer.js:95:5)
   at trim_prefix (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:312:13)
   at /Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:280:7
   at Function.process_params (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:330:12)
   at next (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:271:10)
   at addUserToRequestFromJWT (/Users/essjay-lg/Development/lg/idm/node_modules/@learnersguild/idm-jwt-auth/lib/middlewares.js:119:5)
   at Layer.handle [as handle_request] (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/layer.js:95:5)
   at trim_prefix (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:312:13)
   at /Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:280:7
   at Function.process_params (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:330:12)
   at next (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:271:10)
   at initialize (/Users/essjay-lg/Development/lg/idm/node_modules/passport/lib/middleware/initialize.js:53:5)
   at Layer.handle [as handle_request] (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/layer.js:95:5)
   at trim_prefix (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:312:13)
   at /Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:280:7
   at Function.process_params (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:330:12)
   at next (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:271:10)
   at Function.handle (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:176:3)
   at router (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:46:12)
   at server.js:52:7
   at Layer.handle [as handle_request] (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/layer.js:95:5)
   at trim_prefix (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:312:13)
   at /Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:280:7
   at Function.process_params (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:330:12)
   at next (/Users/essjay-lg/Development/lg/idm/node_modules/express/lib/router/index.js:271:10)
   at SendStream.error (/Users/essjay-lg/Development/lg/idm/node_modules/serve-static/index.js:120:7)
   at emitOne (events.js:90:13)
   at SendStream.emit (events.js:182:7)
   at SendStream.error (/Users/essjay-lg/Development/lg/idm/node_modules/serve-static/node_modules/send/index.js:274:17)
   at SendStream.onStatError (/Users/essjay-lg/Development/lg/idm/node_modules/serve-static/node_modules/send/index.js:391:12)
   at next (/Users/essjay-lg/Development/lg/idm/node_modules/serve-static/node_modules/send/index.js:682:16)
   at onstat (/Users/essjay-lg/Development/lg/idm/node_modules/serve-static/node_modules/send/index.js:671:14)
   at FSReqWrap.oncomplete (fs.js:82:15)

Haven't yet tried to debug in any way.

jeffreywescott commented 8 years ago

I hit that, too, and it was b/c my .env.development had APP_BASEURL rather than APP_BASE_URL.

heyheyjp commented 8 years ago

Hrm...APP_BASE_URL should no longer be required in the .env file if NODE_ENV=development.

The merged config changes have hard-coded defaults...?

jeffreywescott commented 8 years ago

Line 27 of config/default.js, maybe?

heyheyjp commented 8 years ago

Ahhhh. Yup. Bug. Need to override this for development.js and test.js, too. Thx.

heyheyjp commented 8 years ago

Alrighty. Everything discussed looks to have either been addressed here or w/ new issues, so LGTM! 👍