Пример #1
0
  /**
   * This method is used to unregister the oauth application that has been registered at the device
   * authentication.
   *
   * @param profile Payload of the unregister request.
   * @param utils Server configurations
   * @return true if unregistration success, else false.
   * @throws AndroidAgentException
   */
  public boolean unregisterClient(UnregisterProfile profile, ServerConfig utils)
      throws AndroidAgentException {

    StringBuilder endPoint = new StringBuilder();
    endPoint.append(utils.getAPIServerURL());
    endPoint.append(Constants.DYNAMIC_CLIENT_REGISTER_ENDPOINT);
    endPoint.append("?" + USER_ID + "=" + profile.getUserId());
    endPoint.append("&" + CONSUMER_KEY + "=" + profile.getConsumerKey());
    endPoint.append("&" + APPLICATION_NAME + "=" + profile.getApplicationName());

    EndPointInfo endPointInfo = new EndPointInfo();
    endPointInfo.setHttpMethod(org.wso2.emm.agent.proxy.utils.Constants.HTTP_METHODS.DELETE);
    endPointInfo.setEndPoint(endPoint.toString());

    try {
      SendRequest sendRequestTask = new SendRequest();
      Map<String, String> responseParams = sendRequestTask.execute(endPointInfo).get();

      String statusCode = responseParams.get(Constants.STATUS);

      if (Constants.Status.ACCEPT.equalsIgnoreCase(statusCode)) {
        return true;
      } else {
        return false;
      }
    } catch (InterruptedException e) {
      String msg = "error occurred due to thread interruption";
      Log.e(TAG, msg);
      throw new AndroidAgentException(msg, e);
    } catch (ExecutionException e) {
      String msg = "error occurred while fetching credentials";
      Log.e(TAG, msg);
      throw new AndroidAgentException(msg, e);
    }
  }
  /**
   * This method is used to unregister the oauth application that has been registered at the device
   * authentication.
   *
   * @param profile Payload of the unregister request.
   * @param utils Server configurations
   * @return true if unregistration success, else false.
   * @throws AppCatalogException
   */
  public boolean unregisterClient(UnregisterProfile profile, ServerConfig utils, Context context)
      throws AppCatalogException {
    StringBuilder endPoint = new StringBuilder();
    endPoint.append(utils.getAPIServerURL(context));
    endPoint.append(Constants.DYNAMIC_CLIENT_REGISTER_ENDPOINT);
    endPoint.append("?" + USER_ID + "=" + profile.getUserId());
    endPoint.append("&" + CONSUMER_KEY + "=" + profile.getConsumerKey());
    endPoint.append("&" + APPLICATION_NAME + "=" + profile.getApplicationName());

    EndPointInfo endPointInfo = new EndPointInfo();
    endPointInfo.setHttpMethod(org.wso2.emm.agent.proxy.utils.Constants.HTTP_METHODS.DELETE);
    endPointInfo.setEndPoint(endPoint.toString());
    sendRequest(endPointInfo, null, Constants.DYNAMIC_CLIENT_UNREGISTER_REQUEST_CODE);
    return true;
  }
 /**
  * This method is used to register an oauth application in the backend.
  *
  * @param profile Payload of the register request.
  * @param utils Server configurations.
  * @return returns consumer key and consumer secret if success. Else returns null if it fails to
  *     register.
  * @throws AppCatalogException
  */
 public void getClientCredentials(
     RegistrationProfile profile,
     ServerConfig utils,
     Context context,
     String credentials,
     APIResultCallBack apiResultCallback)
     throws AppCatalogException {
   IdentityProxy.getInstance().setContext(context);
   EndPointInfo endPointInfo = new EndPointInfo();
   String endPoint = utils.getAPIServerURL(context) + Constants.DYNAMIC_CLIENT_REGISTER_ENDPOINT;
   endPointInfo.setHttpMethod(org.wso2.emm.agent.proxy.utils.Constants.HTTP_METHODS.POST);
   endPointInfo.setEndPoint(endPoint);
   endPointInfo.setRequestParams(profile.toJSON());
   endPointInfo.setHeader(BASIC_HEADER + credentials);
   endPointInfo.setRequestParamsMap(profile.toMap());
   sendRequest(endPointInfo, apiResultCallback, Constants.DYNAMIC_CLIENT_REGISTER_REQUEST_CODE);
 }
Пример #4
0
  /**
   * This method is used to register an oauth application in the backend.
   *
   * @param profile Payload of the register request.
   * @param utils Server configurations.
   * @return consumer key and consumer secret.
   * @throws AndroidAgentException
   */
  public String registerClient(RegistrationProfile profile, ServerConfig utils)
      throws AndroidAgentException {

    EndPointInfo endPointInfo = new EndPointInfo();
    String endPoint =
        utils.getAPIServerURL()
            + org.wso2.emm.agent.utils.Constants.DYNAMIC_CLIENT_REGISTER_ENDPOINT;
    endPointInfo.setHttpMethod(org.wso2.emm.agent.proxy.utils.Constants.HTTP_METHODS.POST);
    endPointInfo.setEndPoint(endPoint);
    endPointInfo.setRequestParams(profile.toJSON());

    try {
      SendRequest sendRequestTask = new SendRequest();
      Map<String, String> responseParams = sendRequestTask.execute(endPointInfo).get();

      if (responseParams != null) {
        String statusCode = responseParams.get(Constants.STATUS);
        if (Constants.Status.ACCEPT.equalsIgnoreCase(statusCode)) {
          return responseParams.get(Constants.RESPONSE);
        } else {
          return null;
        }
      } else {
        return null;
      }

    } catch (InterruptedException e) {
      String msg = "error occurred due to thread interruption";
      Log.e(TAG, msg);
      throw new AndroidAgentException(msg, e);
    } catch (ExecutionException e) {
      String msg = "error occurred while fetching credentials";
      Log.e(TAG, msg);
      throw new AndroidAgentException(msg, e);
    }
  }