I am new to Okta world.
I am trying to get access token using a POST call in a spring boot app but every time I get “java.net.ConnectException: Connection refused: no further information”.
Below is what I have done:-
-
Created an application using okta developer console.
-
I have tested my resources ( another spring boot application) by following authorization code flow. It means I am getting the auth code from oidcdebugger site and using that auth code when I trigger below command in HTTPie demo site , I get the access token. PFB command -
" http -f https://{my-domain}/oauth2/default/v1/token
grant_type=authorization_code
code={auth code got from }
client_id={my-client-id}
client_secret={my-secret}
redirect_uri=http://localhost:8181/api/v1/helloToken " -
I can even get access token from POSTMAN too , where I set header ‘content-type’ as ‘application/x-www-form-urlencoded’ and do a POST call to below URL -
https://{my-doamin}/oauth2/default/v1/token?client_id={my-client-id}&client_secret={client-secret}&grant_type=authorization_code&redirect_uri=http://localhost:8181/api/v1/helloToken&code={auth code} -
Now I want to get token from Spring Boot app using POST call, for that I have done below code
My ServiceImpl
@Service
public class OktaTokenServiceImpl implements OktaTokenService{
@Override
public OktaToken getToken(String authToken) {
WebClient webClient = WebClient
.builder()
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
.baseUrl(OktaTokenService.baseUrl)
.build();
URI uri;
try {
uri = new URI("/v1/token/" +"?client_id="+"my-client-id"+"&"
+"client_secret="+"my-secret"+"&"
+"grant_type="+"authorization_code"+"&"
+"redirect_uri="+"http://localhost:8181/api/v1/helloToken"+"&"
+"code="+authToken);
System.out.println("complete URL" +uri.toString());
Mono<OktaToken> oktaToken = webClient
.post()
.uri(uri)
.retrieve()
.bodyToMono(OktaToken.class);
if (oktaToken.blockOptional().isPresent()) {
return oktaToken.blockOptional().get();
} else return null;
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
My URL which I hit from POSTMAN
“http://localhost:8181/api/v1/getToken/{my-auth-code}”
Exception which I get
2021-04-25 18:37:25.860 ERROR 15288 — [nio-8181-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path threw exception [Request processing failed; nested exception is org.springframework.web.reactive.function.client.WebClientRequestException: Connection refused: no further information: /127.0.0.1:80; nested exception is io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: /127.0.0.1:80] with root cause
java.net.ConnectException: Connection refused: no further information
Please help me to get this resolved and please share your experience if you have faced same issue.