public static Result addAccessToken() { String key = Utils.generateBigCode(); String secret = Utils.generateBigCode(); String accessToken = Authentication.calculateHMAC(key, secret); try { MasterUserDAO.getInstance().addAccessToken(key, accessToken); ObjectNode result = Json.newObject(); result.put("API-Key", key); result.put("API-Secret", secret); result.put("APi-Token", accessToken); return ok(result); } catch (Exception e) { return generateBadRequest("Failed to add a new access Token"); } }
public static Result getAccessToken() { if (!Utils.checkJsonInput(request())) { Logger.info("Access Token : Bad request data for watch request " + request().body()); return generateBadRequest("Bad input json"); } JsonNode jsonReq = request().body().asJson(); String key = jsonReq.get("API-Key").asText(); String secret = jsonReq.get("API-Secret").asText(); String accessToken = MasterUserDAO.getInstance().findKey(key); if (accessToken == null) return generateBadRequest("Kindly provide a valid Key"); if (accessToken.equals(Authentication.calculateHMAC(key, secret))) { ObjectNode result = Json.newObject(); result.put("API-Token", accessToken); return ok(result); } else { return generateBadRequest("Invalid Key Secret combination"); } }