Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Request as other user 2-Legged OAuth

Juan Luis Bujeda Gracia
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 29, 2018

Hi,

I'm trying to send a post request to Jira using 2-Legged OAuth, but I don't know where to put the username to be impersonated

private JSONObject handlePostRequest(PropertiesCall arguments) {
        Map<String, String> properties = propertiesClient.getPropertiesOrDefaults();
        String url = properties.get(JIRA_HOME) + arguments.getApi();
        try {
            OAuthParameters parameters = this.getOAuthParameters();
            HttpResponse response = sendResponsePostFromUrl(parameters, new GenericUrl(url), arguments);
            return parseResponse(response);
        } catch (HttpResponseException e) {
            log.error(e.getMessage());
            return new JSONObject(e.getContent());
        } catch (Exception e) {
            log.error(e.getMessage());
            return null;
        }
    }

private static HttpResponse sendResponsePostFromUrl(OAuthParameters parameters, GenericUrl jiraUrl,
            PropertiesCall arguments) throws IOException {
        HttpRequestFactory requestFactory = new NetHttpTransport().createRequestFactory(parameters);
        HttpRequest request = requestFactory.buildPostRequest(jiraUrl,
                ByteArrayContent.fromString("application/json", arguments.getParametros()));
        return request.execute();
    }

 

0 answers

Suggest an answer

Log in or Sign up to answer