Skip to content

Commit a4b8b9b

Browse files
committed
Merge pull request hub4j#61 from lucamilanesio/master
Fetching of user's verified keys through standard OAuth scope.
2 parents 4e8e28d + 4b52414 commit a4b8b9b

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/main/java/org/kohsuke/github/GHKey.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
public class GHKey {
1111
/*package almost final*/ GitHub root;
1212

13-
private String url, key, title;
14-
private boolean verified;
15-
private int id;
13+
protected String url, key, title;
14+
protected boolean verified;
15+
protected int id;
1616

1717
public int getId() {
1818
return id;

src/main/java/org/kohsuke/github/GHMyself.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,31 @@ public List<String> getEmails() throws IOException {
3434
/**
3535
* Returns the read-only list of all the pulic keys of the current user.
3636
*
37+
* NOTE: When using OAuth authenticaiton, the READ/WRITE User scope is
38+
* required by the GitHub APIs, otherwise you will get a 404 NOT FOUND.
39+
*
3740
* @return
3841
* Always non-null.
3942
*/
4043
public List<GHKey> getPublicKeys() throws IOException {
4144
return Collections.unmodifiableList(Arrays.asList(root.retrieve().to("/user/keys", GHKey[].class)));
4245
}
4346

47+
/**
48+
* Returns the read-only list of all the pulic verified keys of the current user.
49+
*
50+
* Differently from the getPublicKeys() method, the retrieval of the user's
51+
* verified public keys does not require any READ/WRITE OAuth Scope to the
52+
* user's profile.
53+
*
54+
* @return
55+
* Always non-null.
56+
*/
57+
public List<GHVerifiedKey> getPublicVerifiedKeys() throws IOException {
58+
return Collections.unmodifiableList(Arrays.asList(root.retrieve().to(
59+
"/users/" + getLogin() + "/keys", GHVerifiedKey[].class)));
60+
}
61+
4462
/**
4563
* Gets the organization that this user belongs to.
4664
*/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.kohsuke.github;
2+
3+
public class GHVerifiedKey extends GHKey {
4+
5+
public GHVerifiedKey() {
6+
this.verified = true;
7+
}
8+
9+
@Override
10+
public String getTitle() {
11+
return (title == null ? "key-" + id : title);
12+
}
13+
}

0 commit comments

Comments
 (0)