FeignClient create POST with application/x-www-form-urlencoded body
https://stackoverflow.com/questions/61901362/feignclient-create-post-with-application-x-www-form-urlencoded-bodyFeignClient create POST with application/x-www-form-urlencoded bodycurl -X POST \https:/
·
FeignClient create POST with application/x-www-form-urlencoded body
curl -X POST \
https://auth.beyondtime-stage.io/auth/realms/master/protocol/openid-connect/token \
-H 'cache-control: no-cache' \
-H 'content-type: application/x-www-form-urlencoded' \
-d 'username=admin&password=pass123&client_id=admin-cli&grant_type=password'
import com.beyondtime.recruitmentservice.seafarer.entity.AuthTokenRequest;
import com.beyondtime.recruitmentservice.seafarer.entity.KeycloakAccessToken;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@FeignClient(name = "beyondtime-io-kc-client", url = "${btio.keycloakUrl}", path = "/", configuration = KeycloakAdminClient.Configuration.class)
public interface KeycloakAdminClient {
@PostMapping(value="realms/master/protocol/openid-connect/token", consumes = "application/x-www-form-urlencoded")
KeycloakAccessToken getAuthToken(@RequestBody AuthTokenRequest authTokenRequest);
class Configuration {
@Bean
Encoder feignFormEncoder(ObjectFactory<HttpMessageConverters> converters) {
return new SpringFormEncoder(new SpringEncoder(converters));
}
}
}
Request object:
@Getter
@Setter
public class AuthTokenRequest {
private String username;
private String password;
private String client_id;
private String grant_type;
}
Response object:
@Getter
@Setter
public class KeycloakAccessToken {
@JsonProperty("access_token")
private String accessToken;
}
更多推荐
已为社区贡献3条内容
所有评论(0)