1

We are using Play 2 authenticate plugin for a REST API and I would like to simply return 200 or 403 for login attempts.

The plugin's code looks like this:

public static Result loginAndRedirect(final Context context,
        final AuthUser loginUser) {
    storeUser(context.session(), loginUser);
    return Controller.redirect(getJumpUrl(context));
}

Is there any way to avoid the redirect without forking the plugin project?

ndeverge
  • 21,378
  • 4
  • 56
  • 85
Petteri H
  • 11,779
  • 12
  • 64
  • 94
  • 1
    Did you take a look at the Resolver ? https://github.com/joscha/play-authenticate/blob/master/samples/java/Getting%20Started.md#configure-the-resolver – ndeverge Nov 22 '12 at 08:12

2 Answers2

1

I ended up handling this at the controller:

public static Result login() {   
    Result r = MyUsernamePasswordAuthProvider.handleLogin(ctx());
    if (r instanceof Redirect && PlayAuthenticate.getUser(session()) != null) {
        return ok();
    }
    return forbidden();
}

There might be better ways to do this though.

Petteri H
  • 11,779
  • 12
  • 64
  • 94
1

I just stumbled in the same scenario, and as nico_ekito pointed out, this can be achieved by extending PlayAuthenticate.Resolver and overriding:

@Override
    public Call afterAuth() {
        return routes.Application.restAfterAuth();
    }

So you can return any route of your app.

andraus
  • 106
  • 5