use of io.micronaut.http.uri.UriBuilder in project micronaut-starter by micronaut-projects.
the class GitHubRedirectService method constructOAuthRedirectUrl.
/**
* Creates redirect URI to github oauth auhtorise in order to receive the user access code.
*
* @param requestInfo origin request info
* @return URI to github oauth authorise
*/
protected URI constructOAuthRedirectUrl(RequestInfo requestInfo) {
try {
UriBuilder uriBuilder = UriBuilder.of(requestInfo.getServerURL()).path(requestInfo.getPath());
requestInfo.getParameters().forEachValue(uriBuilder::queryParam);
URI redirectUri = uriBuilder.build();
return UriBuilder.of(githubOAuthUrl).queryParam("scope", "user,repo").queryParam("client_id", gitHubConfiguration.getClientId()).queryParam("redirect_uri", redirectUri.toString()).queryParam("state", UUID.randomUUID().toString()).build();
} catch (Exception e) {
String msg = "Failed to construct redirect URI using request " + requestInfo + " to GiHub OAuth: " + e.getMessage();
LOG.error(msg, e);
throw new RuntimeException(msg);
}
}
Aggregations