io.vertx.ext.jwt.JWTOptions Java Examples
The following examples show how to use
io.vertx.ext.jwt.JWTOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebSocketServiceLoginTest.java From besu with Apache License 2.0 | 5 votes |
@Test public void websocketServiceWithGoodHeaderAuthenticationToken(final TestContext context) { final Async async = context.async(); final JWTOptions jwtOptions = new JWTOptions().setExpiresInMinutes(5).setAlgorithm("RS256"); final JsonObject jwtContents = new JsonObject().put("permissions", Lists.newArrayList("eth:*")).put("username", "user"); final String goodToken = jwtAuth.generateToken(jwtContents, jwtOptions); final String requestSub = "{\"id\": 1, \"method\": \"eth_subscribe\", \"params\": [\"syncing\"]}"; final String expectedResponse = "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0x1\"}"; RequestOptions options = new RequestOptions(); options.setURI("/"); options.setHost(websocketConfiguration.getHost()); options.setPort(websocketConfiguration.getPort()); final MultiMap headers = new VertxHttpHeaders(); if (goodToken != null) { headers.add("Authorization", "Bearer " + goodToken); } httpClient.websocket( options, headers, webSocket -> { webSocket.writeTextMessage(requestSub); webSocket.handler( buffer -> { context.assertEquals(expectedResponse, buffer.toString()); async.complete(); }); }); async.awaitSuccess(VERTX_AWAIT_TIMEOUT_MILLIS); }