-
-
Save aesteve/dd771f51929c9a366839 to your computer and use it in GitHub Desktop.
setUser doesn't do anything
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
pmlopes
commented
Dec 16, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment