diff --git a/src/main/java/org/kohsuke/github/GHKey.java b/src/main/java/org/kohsuke/github/GHKey.java index e9692453d..91632cf17 100644 --- a/src/main/java/org/kohsuke/github/GHKey.java +++ b/src/main/java/org/kohsuke/github/GHKey.java @@ -10,9 +10,9 @@ import org.apache.commons.lang.builder.ToStringBuilder; public class GHKey { /*package almost final*/ GitHub root; - private String url, key, title; - private boolean verified; - private int id; + protected String url, key, title; + protected boolean verified; + protected int id; public int getId() { return id; diff --git a/src/main/java/org/kohsuke/github/GHMyself.java b/src/main/java/org/kohsuke/github/GHMyself.java index 7a612007a..70e732ac9 100644 --- a/src/main/java/org/kohsuke/github/GHMyself.java +++ b/src/main/java/org/kohsuke/github/GHMyself.java @@ -34,6 +34,9 @@ public class GHMyself extends GHUser { /** * Returns the read-only list of all the pulic keys of the current user. * + * NOTE: When using OAuth authenticaiton, the READ/WRITE User scope is + * required by the GitHub APIs, otherwise you will get a 404 NOT FOUND. + * * @return * Always non-null. */ @@ -41,6 +44,21 @@ public class GHMyself extends GHUser { return Collections.unmodifiableList(Arrays.asList(root.retrieve().to("/user/keys", GHKey[].class))); } + /** + * Returns the read-only list of all the pulic verified keys of the current user. + * + * Differently from the getPublicKeys() method, the retrieval of the user's + * verified public keys does not require any READ/WRITE OAuth Scope to the + * user's profile. + * + * @return + * Always non-null. + */ + public List getPublicVerifiedKeys() throws IOException { + return Collections.unmodifiableList(Arrays.asList(root.retrieve().to( + "/users/" + getLogin() + "/keys", GHVerifiedKey[].class))); + } + /** * Gets the organization that this user belongs to. */ diff --git a/src/main/java/org/kohsuke/github/GHVerifiedKey.java b/src/main/java/org/kohsuke/github/GHVerifiedKey.java new file mode 100644 index 000000000..d81597d74 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHVerifiedKey.java @@ -0,0 +1,13 @@ +package org.kohsuke.github; + +public class GHVerifiedKey extends GHKey { + + public GHVerifiedKey() { + this.verified = true; + } + + @Override + public String getTitle() { + return (title == null ? "key-" + id : title); + } +}