setUser doesn't do anything
import io.vertx.core.AsyncResult; | |
import io.vertx.core.Handler; | |
import io.vertx.core.json.JsonObject; | |
import io.vertx.ext.auth.AuthProvider; | |
import io.vertx.ext.auth.User | |
class GithubUser implements User { | |
String username | |
User original | |
public GithubUser(User original, String username) { | |
println "original : $original" | |
this.username = username | |
} | |
@Override | |
public User isAuthorised(String authority, Handler<AsyncResult<Boolean>> resultHandler) { | |
return original.isAuthorised(authority, resultHandler) | |
} | |
@Override | |
public User clearCache() { | |
return original.clearCache() | |
} | |
@Override | |
public JsonObject principal() { | |
return original.principal() | |
} | |
@Override | |
public void setAuthProvider(AuthProvider authProvider) { | |
original.setAuthProvider(authProvider) | |
} | |
} |
Vertx vertx = Vertx.vertx() | |
Router router = Router.router(vertx) | |
Map options = [ | |
clientID: '26e529e1a7637e236322', | |
clientSecret: 'b9c21eb9e330d9efc65156b7795eee30822d9e0b', | |
site: 'https://github.com/login', | |
tokenPath: '/oauth/access_token', | |
authorizationPath: '/oauth/authorize', | |
] | |
OAuth2Auth oauth = OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, options) | |
OAuth2AuthHandler handler = OAuth2AuthHandler.create(oauth, 'http://localhost:9000') | |
handler.setupCallback(router.get('/login/github')) | |
router.get('/protected').handler handler | |
router.get('/protected').handler { ctx -> | |
if (ctx.user) { | |
println "change user" | |
User u = new User(new GithubUser(ctx.user.delegate, 'toto')) | |
println u.getDelegate() | |
ctx.user = u | |
} | |
ctx++ | |
} | |
router.get('/protected').handler { | |
it.response.end "hello ${it.user}" | |
} | |
vertx.createHttpServer([host: 'localhost', port: 9000]).requestHandler(router.&accept).listen() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.