Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added OAuth authentication, Project.searchAssignableUsers #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Bob Carroll <[email protected]> @rcarz
Kyle Chaplin <[email protected]> @chaplinkyle
Alesandro Lang <[email protected]> @alesandroLang
Javier Molina <[email protected]> @javinovich
Jochen Bedersdorfer <[email protected]> @beders
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jira-client is still under heavy development. Here's what works:
* Add and remove issue links
* Create sub-tasks
* Retrieval of Rapid Board backlog and sprints
* Search assignable users for a project
* Use OAuth to authenticate (see src/integrationtest/net/rcarz/jiraclient/OAuthTest for an example)


## Maven Dependency ##

Expand Down
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<name>Bob Carroll</name>
<email>[email protected]</email>
</developer>
<developer>
<id>beders</id>
<name>Jochen Bedersdorfer</name>
<email>[email protected]</email>
</developer>
</developers>

<parent>
Expand Down Expand Up @@ -71,5 +76,11 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.scribe</groupId>
<artifactId>scribe</artifactId>
<version>1.3.7</version>
</dependency>

</dependencies>
</project>
42 changes: 42 additions & 0 deletions src/integrationtest/java/net/rcarz/jiraclient/OAuthTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.rcarz.jiraclient;

import net.rcarz.jiraclient.oauth.OAuthRestClient;

import java.net.URI;

/**
* Example on how to use OAuth with JIRA and the Java Scribe project
* Follow instructions here: https://developer.atlassian.com/jiradev/api-reference/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-oauth-authentication
*
* See https://github.com/fernandezpablo85/scribe-java for an example on how to get a tokenSecret and accessToken.
* i.e
* <pre>
* JiraApi jiraApi = new JiraApi(url, privateKey)
* OAuthService service = new ServiceBuilder().provider(jiraApi).apiKey(consumerKey).apiSecret(privateKey).callback(yourCallbackURL).build();
* Token requestToken = service.getRequestToken();
* ...
* on callback from Jira with params.oauth_verifier:
* Verifier v = new Verifier(params.oauth_verifier.toString())
*String accessToken = service.getAccessToken(requestToken, v);
* </pre>
*
* Created by beders on 3/27/15.
*/
public class OAuthTest {
static String accessToken = "..."; // access token received for a user after the OAuth challenge is complete
static String tokenSecret = "..."; // acquired by service.getRequestToken().getSecret()
static String privateKey = "..."; // generated using keytool -genkeypair
static String endpointURL = "https://blabla.atlassian.net";
static String consumerName = "hardcoded-consumer"; // part of the OAuth configuration for JIRA

public static void main(String... args) {
JiraClient client = new JiraClient(endpointURL, null, new OAuthRestClient(URI.create(endpointURL), privateKey, consumerName, tokenSecret, accessToken));
try {
for (Project p : client.getProjects()) {
System.out.println(p);
}
} catch (JiraException e) {
e.printStackTrace();
}
}
}
49 changes: 49 additions & 0 deletions src/integrationtest/java/net/rcarz/jiraclient/ProjectTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package net.rcarz.jiraclient;

import org.junit.Before;
import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class ProjectTest {
static String url() {
return System.getenv("URL");
}
static String user() {
return System.getenv("USER");
}

static String pwd() {
return System.getenv("PASSWORD");
}
static String project() {
return System.getenv("PROJECT");
}

JiraClient client;
@Before
public void setUp() throws Exception {
client = new JiraClient(url(), new BasicCredentials(user(), pwd()));
}

@Test
public void listAssignableUsers() throws JiraException {
Project p = client.getProject(project());
List<User> users = p.searchAssignableUsers();
assertNotNull(users);
System.out.println(users);
}

@Test
public void listAssignableUsersIndex() throws JiraException {
Project p = client.getProject(project());
List<User> users = p.searchAssignableUsers(0,1);
assertNotNull(users);
assertEquals(1,users.size());
}


}
Loading