@Override public Link link() { return new Link( "rexsl:github", UriBuilder .fromUri("https://github.com/login/oauth/authorize") // @checkstyle MultipleStringLiterals (2 lines) .queryParam("client_id", "{client_id}") .queryParam("redirect_uri", "{redirect_uri}") .build(this.app, this.redirectUri()) ); }
/** * Retrieve Github access token. * @param code Github "authorization code" * @return The token * @throws IOException If failed */ private String token(final String code) throws IOException { final URI uri = UriBuilder .fromUri("https://github.com/login/oauth/access_token") .queryParam("client_id", "{id}") .queryParam("redirect_uri", "{uri}") .queryParam("client_secret", "{secret}") .queryParam("code", "{code}") .build( this.app, this.redirectUri(), this.key, code ); return new JdkRequest(uri) .method(Request.POST) .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML) .fetch().as(RestResponse.class) .assertStatus(HttpURLConnection.HTTP_OK) .as(XmlResponse.class) .xml().xpath("/OAuth/access_token/text()").get(0); }