gulp-serve icon indicating copy to clipboard operation
gulp-serve copied to clipboard

Gulp serve , with oauth callback

Open pradeepmurugesan opened this issue 8 years ago • 1 comments

Hi, this is more of a query, not a bug.

I am having a UI built using angular js and we use gulp to package the same.

Our application is though a Java web app so we use https://github.com/eirslett/frontend-maven-plugin to build and copy the UI component into the webapp directory.

We use Oauth's Authorization code grant to authenticate the users and the callback url will be handled by the java's callback servlet.

Since the login is dependent on the Java callback servlet, development cycle is becoming hectic.

Is there a way to make the gulp serve also serve the callback redirect from the oauth server so that we can take the java app out of equation during our development phase ?

I mean asking like can I have gulp serve (webserver) to serve one more route (/callback) and then redirect to home page after successful authentication. Is that possible ?

pradeepmurugesan avatar Sep 28 '16 15:09 pradeepmurugesan

You've got a few ways of solving this:

  1. use a web proxy, e.g. nginx, and just match the callback route to another handler
  2. see if your frontend stack can handle it for you (e.g. you said you're using Angular, so use $locationProvider.html5Mode(true); and connect-history-api-fallback as a gulp-serve middleware) This is usually preferred, as your callback almost always has to set state on the client.

In the gulpfile:

var history = require('connect-history-api-fallback');

// ...

gulp.task('statics', g.serve({
  root: ['./.tmp', '...'],
  middlewares: [history({})],
  // ... and so forth

BTW, the Auth0 devs have some really good examples to go with their Oauth solutions: https://github.com/auth0-samples/auth0-angularjs-samples/

I guess the callback Angular controller can then talk to your servlet and do the necessary token hand-off.

opyate avatar Jun 27 '17 17:06 opyate