public OTPDevice enrollFactor ( long userId , long factorId , String displayName , String number ) throws OAuthSystemException , OAuthProblemException , URISyntaxException { cleanError ( ) ; prepareToken ( ) ; URIBuilder url = new URIBuilder ( settings . getURL ( Constants . ENROLL_FACTOR_URL , userId ) ) ; OneloginURLConnectionClient httpClient = new OneloginURLConnectionClient ( ) ; OAuthClient oAuthClient = new OAuthClient ( httpClient ) ; OAuthClientRequest bearerRequest = new OAuthBearerClientRequest ( url . toString ( ) ) . buildHeaderMessage ( ) ; Map < String , String > headers = getAuthorizedHeader ( ) ; bearerRequest . setHeaders ( headers ) ; HashMap < String , Object > params = new HashMap < String , Object > ( ) ; params . put ( "factor_id" , factorId ) ; params . put ( "display_name" , displayName ) ; params . put ( "number" , number ) ; String body = JSONUtils . buildJSON ( params ) ; bearerRequest . setBody ( body ) ; OTPDevice otpDevice = null ; OneloginOAuthJSONResourceResponse oAuthResponse = oAuthClient . resource ( bearerRequest , OAuth . HttpMethod . POST , OneloginOAuthJSONResourceResponse . class ) ; if ( oAuthResponse . getResponseCode ( ) == 200 ) { JSONObject data = oAuthResponse . getData ( ) ; otpDevice = new OTPDevice ( data ) ; } else { error = oAuthResponse . getError ( ) ; errorDescription = oAuthResponse . getErrorDescription ( ) ; } return otpDevice ; }
Enroll a user with a given authentication factor .