Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e9564f1

Browse filesBrowse files
committed
implement retrieving of access token
1 parent ba416b1 commit e9564f1
Copy full SHA for e9564f1

File tree

Expand file treeCollapse file tree

2 files changed

+102
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+102
-0
lines changed
+90Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package org.kohsuke.github;
2+
3+
import java.net.URL;
4+
import java.util.Date;
5+
import java.util.List;
6+
7+
/**
8+
*
9+
* @author janinko
10+
*/
11+
public class GHAuthorization {
12+
public static final String USER = "user";
13+
public static final String USER_EMAIL = "user:email";
14+
public static final String USER_FOLLOW = "user:follow";
15+
public static final String PUBLIC_REPO = "public_repo";
16+
public static final String REPO = "repo";
17+
public static final String REPO_STATUS = "repo:status";
18+
public static final String DELETE_REPO = "delete_repo";
19+
public static final String NOTIFICATIONS = "notifications";
20+
public static final String GIST = "gist";
21+
22+
private GitHub root;
23+
private int id;
24+
private String url;
25+
private List<String> scopes;
26+
private String token;
27+
private App app;
28+
private String note;
29+
private String note_url;
30+
private String updated_at;
31+
private String created_at;
32+
33+
public GitHub getRoot() {
34+
return root;
35+
}
36+
37+
public int getId() {
38+
return id;
39+
}
40+
41+
public List<String> getScopes() {
42+
return scopes;
43+
}
44+
45+
public String getToken(){
46+
return token;
47+
}
48+
49+
public URL getAppUrl(){
50+
return GitHub.parseURL(app.url);
51+
}
52+
53+
public String getAppName() {
54+
return app.name;
55+
}
56+
57+
public URL getApiURL(){
58+
return GitHub.parseURL(url);
59+
}
60+
61+
public String getNote() {
62+
return note;
63+
}
64+
65+
public URL getNoteUrl(){
66+
return GitHub.parseURL(note_url);
67+
}
68+
69+
public Date getCreatedAt() {
70+
return GitHub.parseDate(created_at);
71+
}
72+
73+
public Date getUpdatedAt() {
74+
return GitHub.parseDate(updated_at);
75+
}
76+
77+
/*package*/ GHAuthorization wrap(GitHub root) {
78+
this.root = root;
79+
return this;
80+
}
81+
82+
83+
84+
85+
86+
private static class App{
87+
private String url;
88+
private String name;
89+
}
90+
}

‎src/main/java/org/kohsuke/github/GitHub.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GitHub.java
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@
3939
import java.text.ParseException;
4040
import java.text.SimpleDateFormat;
4141
import java.util.Arrays;
42+
import java.util.Collection;
4243
import java.util.Date;
4344
import java.util.HashMap;
45+
import java.util.HashSet;
4446
import java.util.List;
4547
import java.util.Map;
4648
import java.util.Properties;
49+
import java.util.Set;
4750
import java.util.TimeZone;
4851

4952
import static org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.*;
@@ -303,6 +306,15 @@ public GHRepository createRepository(String name, String description, String hom
303306
return requester.method("POST").to("/user/repos", GHRepository.class).wrap(this);
304307
}
305308

309+
public GHAuthorization createToken(Collection<String> scope, String note, String noteUrl) throws IOException{
310+
Requester requester = new Requester(this)
311+
.with("scopes",scope)
312+
.with("note",note)
313+
.with("note_url",noteUrl);
314+
315+
return requester.method("POST").to("/authorizations", GHAuthorization.class).wrap(this);
316+
}
317+
306318
/**
307319
* Ensures that the credential is valid.
308320
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.