2023-06-13 10:13:39 +08:00
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
2023-06-05 15:06:52 +08:00
|
|
|
import com.njcn.web.utils.RestTemplateUtil;
|
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
|
|
|
|
import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint;
|
|
|
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
|
|
|
|
|
|
import java.net.URI;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author hongawen
|
|
|
|
|
* @version 1.0.0
|
|
|
|
|
* @date 2021年12月14日 12:55
|
|
|
|
|
*/
|
|
|
|
|
public class AuthTest extends BaseJunitTest {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TokenEndpoint tokenEndpoint;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SneakyThrows
|
|
|
|
|
@Test
|
|
|
|
|
public void test(){
|
2023-06-30 11:37:36 +08:00
|
|
|
String userUrl = "http://127.0.0.1:10214/oauth/token";
|
2023-06-05 15:06:52 +08:00
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(userUrl)
|
2023-06-30 11:37:36 +08:00
|
|
|
.queryParam("grant_type", "sms_code")
|
|
|
|
|
.queryParam("client_id", "app")
|
2023-06-05 15:06:52 +08:00
|
|
|
.queryParam("client_secret", "njcnpqs")
|
2023-06-30 11:37:36 +08:00
|
|
|
.queryParam("phone", "root")
|
|
|
|
|
.queryParam("smsCode", "98746312123");
|
2023-06-05 15:06:52 +08:00
|
|
|
URI uri = builder.build().encode().toUri();
|
|
|
|
|
|
2023-06-13 10:13:39 +08:00
|
|
|
ResponseEntity<OAuth2AccessToken> userEntity = RestTemplateUtil.post(uri, OAuth2AccessToken.class);
|
2023-06-05 15:06:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|