Skip to content

Commit

Permalink
Add Functionality of OTP to github
Browse files Browse the repository at this point in the history
close hub4j#602 by adding an API to request a token using an OTP.
  • Loading branch information
madhephaestus committed Nov 9, 2019
1 parent 09b41d4 commit 62bf691
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,22 @@ public GHAuthorization createToken(Collection<String> scope, String note, String

return requester.method("POST").to("/authorizations", GHAuthorization.class).wrap(this);
}

/**
* Creates a new authorization.
*
* The token created can be then used for {@link GitHub#connectUsingOAuth(String)} in the future.
*
* @see <a href="http://developer.github.com/v3/oauth/#create-a-new-authorization">Documentation</a>
*/
public GHAuthorization createTokenOtp(Collection<String> scope, String note, String noteUrl, String OTP) throws IOException{
Requester requester = new Requester(this)
.with("scopes", scope)
.with("note", note)
.with("note_url", noteUrl);
// Add the OTP from the user
requester.setHeader("x-github-otp", OTP);

This comment has been minimized.

Copy link
@madhephaestus

madhephaestus Nov 9, 2019

Author Owner

This is the only change from the normal createToken above. It adds the header section defining an otp, and passes in the OTP from the user as data.

return requester.method("POST").to("/authorizations", GHAuthorization.class).wrap(this);
}
/**
* @see <a href="https://developer.github.com/v3/oauth_authorizations/#get-or-create-an-authorization-for-a-specific-app">docs</a>
*/
Expand Down

0 comments on commit 62bf691

Please sign in to comment.