Search in sources :

Example 6 with UriBuilder

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);
    }
}
Also used : UriBuilder(io.micronaut.http.uri.UriBuilder) URI(java.net.URI)

Aggregations

UriBuilder (io.micronaut.http.uri.UriBuilder)6 NonNull (io.micronaut.core.annotation.NonNull)2 URI (java.net.URI)2 StringUtils (io.micronaut.core.util.StringUtils)1 HttpHeaders (io.micronaut.http.HttpHeaders)1 HttpRequest (io.micronaut.http.HttpRequest)1 HttpResponse (io.micronaut.http.HttpResponse)1 HttpStatus (io.micronaut.http.HttpStatus)1 MutableHttpResponse (io.micronaut.http.MutableHttpResponse)1 NettyHttpParameters (io.micronaut.http.netty.NettyHttpParameters)1 QueryStringDecoder (io.netty.handler.codec.http.QueryStringDecoder)1 Singleton (jakarta.inject.Singleton)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1