boolean verify_otp ( String userName , String otp ) { try { String authString = userName + ":" + otp ; String authStringEnc = Base64 . encodeBase64URLSafeString ( authString . getBytes ( ) ) ; BufferedReader in = attemptAuthentication ( authStringEnc ) ; String inputLine ; while ( ( inputLine = in . readLine ( ) ) != null ) { if ( inputLine . contains ( expectedOutput ) ) { return true ; } } } catch ( Exception ex ) { log . error ( "Failed verifying OATH OTP :" , ex ) ; } return false ; }
Access protectedUrl using userName and otp for basic auth . Check if what we get back contains expectedOutput .