use of io.helidon.security.integration.webserver.WebSecurity in project helidon by oracle.
the class GoogleBuilderMain method start.
static int start(int port) {
Security security = Security.builder().addProvider(GoogleTokenProvider.builder().clientId("your-client-id.apps.googleusercontent.com")).build();
WebSecurity ws = WebSecurity.create(security);
Routing.Builder routing = Routing.builder().register(ws).get("/rest/profile", WebSecurity.authenticate(), (req, res) -> {
Optional<SecurityContext> securityContext = req.context().get(SecurityContext.class);
res.headers().contentType(MediaType.TEXT_PLAIN.withCharset("UTF-8"));
res.send("Response from builder based service, you are: \n" + securityContext.flatMap(SecurityContext::user).map(Subject::toString).orElse("Security context is null"));
req.next();
}).register(StaticContentSupport.create("/WEB"));
theServer = GoogleUtil.startIt(port, routing);
return theServer.port();
}
Aggregations