@POST
  @Path("authorize")
  @Produces(MediaType.TEXT_HTML)
  public Viewable handleAuthorizeForm(
      @Context UriInfo ui,
      @FormParam("response_type") String response_type,
      @FormParam("client_id") String client_id,
      @FormParam("redirect_uri") String redirect_uri,
      @FormParam("scope") String scope,
      @FormParam("state") String state,
      @FormParam("username") String username,
      @FormParam("password") String password) {

    try {
      responseType = response_type;
      clientId = client_id;
      redirectUri = redirect_uri;
      this.scope = scope;
      this.state = state;

      User user = null;
      String errorDescription = "Username or password do not match";
      try {
        user =
            management.verifyAppUserPasswordCredentials(
                services.getApplicationId(), username, password);
      } catch (UnactivatedAdminUserException uaue) {
        errorDescription = "user not activated";
      } catch (DisabledAdminUserException daue) {
        errorDescription = "user disabled";
      } catch (Exception e1) {
      }
      if ((user != null) && isNotBlank(redirect_uri)) {
        if (!redirect_uri.contains("?")) {
          redirect_uri += "?";
        } else {
          redirect_uri += "&";
        }
        redirect_uri +=
            "code="
                + management.getAccessTokenForAppUser(
                    services.getApplicationId(), user.getUuid(), 0);
        if (isNotBlank(state)) {
          redirect_uri += "&state=" + URLEncoder.encode(state, "UTF-8");
        }
        throw new RedirectionException(state);
      } else {
        errorMsg = errorDescription;
      }

      ApplicationInfo app = management.getApplicationInfo(applicationId);
      applicationName = app.getName();

      return handleViewable("authorize_form", this);
    } catch (RedirectionException e) {
      throw e;
    } catch (Exception e) {
      return handleViewable("error", e);
    }
  }
  @GET
  @Path("authorize")
  public Viewable showAuthorizeForm(
      @Context UriInfo ui,
      @QueryParam("response_type") String response_type,
      @QueryParam("client_id") String client_id,
      @QueryParam("redirect_uri") String redirect_uri,
      @QueryParam("scope") String scope,
      @QueryParam("state") String state) {

    try {
      responseType = response_type;
      clientId = client_id;
      redirectUri = redirect_uri;
      this.scope = scope;
      this.state = state;

      ApplicationInfo app = management.getApplicationInfo(applicationId);
      applicationName = app.getName();

      return handleViewable("authorize_form", this);
    } catch (RedirectionException e) {
      throw e;
    } catch (Exception e) {
      return handleViewable("error", e);
    }
  }