FirebaseChannel { public String createFirebaseToken(Game game, String userId) { final AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService(); final BaseEncoding base64 = BaseEncoding.base64(); String header = base64.encode("{\"typ\":\"JWT\",\"alg\":\"RS256\"}".getBytes()); String channelKey = game.getChannelKey(userId); String clientEmail = appIdentity.getServiceAccountName(); long epochTime = System.currentTimeMillis() / 1000; long expire = epochTime + 60 * 60; Map<String, Object> claims = new HashMap<String, Object>(); claims.put("iss", clientEmail); claims.put("sub", clientEmail); claims.put("aud", IDENTITY_ENDPOINT); claims.put("uid", channelKey); claims.put("iat", epochTime); claims.put("exp", expire); String payload = base64.encode(new Gson().toJson(claims).getBytes()); String toSign = String.format("%s.%s", header, payload); AppIdentityService.SigningResult result = appIdentity.signForApp(toSign.getBytes()); return String.format("%s.%s", toSign, base64.encode(result.getSignature())); } private  FirebaseChannel(); static FirebaseChannel getInstance(); void sendFirebaseMessage(String channelKey, Game game); String createFirebaseToken(Game game, String userId); HttpResponse firebasePut(String path, Object object); HttpResponse firebasePatch(String path, Object object); HttpResponse firebasePost(String path, Object object); HttpResponse firebaseGet(String path); HttpResponse firebaseDelete(String path);  }
@Test public void createFirebaseToken() throws Exception { Game game = new Game(); String jwt = firebaseChannel.createFirebaseToken(game, "userId"); assertThat(jwt).matches("^([\\w+/=-]+\\.){2}[\\w+/=-]+$"); }