文件名从 iailab-plat-sdk/src/main/java/com/iailab/sdk/auth/client/IailabAuthClient.java 修改 |
| | |
| | | * @Description |
| | | * @createTime 2025年02月18日 |
| | | */ |
| | | public class IailabAuthClient { |
| | | public class IailabClient { |
| | | |
| | | private static final RestTemplate restTemplate = new RestTemplate(); |
| | | |
| | |
| | | private static String CLIENT_ID = SdkAutoConfiguration.CLIENT_ID; |
| | | private static String CLIENT_SECRET = SdkAutoConfiguration.CLIENT_SECRET; |
| | | private static String USERNAME = SdkAutoConfiguration.USERNAME; |
| | | private static String PASSWORD = SdkAutoConfiguration.PASSWORD; |
| | | |
| | | private static final String GRAND_TYPE = "password"; |
| | | private static final String GRAND_TYPE = "client_credentials"; |
| | | |
| | | private static final String SCOPE = "user.read user.write"; |
| | | |
| | | private static final String CHARSET = "utf-8"; |
| | | |
| | | private static final IailabAuthClient iailabAuthClient = new IailabAuthClient(); |
| | | private static final IailabClient iailabClient = new IailabClient(); |
| | | |
| | | public static IailabAuthClient getInstance() { |
| | | return iailabAuthClient; |
| | | public static IailabClient getInstance() { |
| | | return iailabClient; |
| | | } |
| | | |
| | | |
| | |
| | | headers.setContentType(MediaType.APPLICATION_JSON_UTF8); |
| | | // 1.2 构建authenticate请求URL |
| | | String authenticateUrl = BASE_URL + "/system/oauth2/token?" |
| | | // 密码模式的参数 |
| | | // 客户端模式的参数 |
| | | + "&grant_type=" + GRAND_TYPE |
| | | + "&username=" + USERNAME |
| | | + "&password=" + PASSWORD |
| | | + "&scope=" + SCOPE; |
| | | // 2. 执行请求 |
| | | ResponseEntity<Map<String, Object>> exchange = restTemplate.exchange( |
| | |
| | | Object code = authMap.get("code"); |
| | | if (SdkErrorCodeConstants.AUTH_BAD_CREDENTIALS.getCode().equals(code)) { |
| | | throw exception(SdkErrorCodeConstants.AUTH_BAD_CREDENTIALS); |
| | | } else if (SdkErrorCodeConstants.AUTH_LOGIN_BAD_CREDENTIALS.getCode().equals(code)) { |
| | | throw exception(SdkErrorCodeConstants.AUTH_LOGIN_BAD_CREDENTIALS); |
| | | } else if (SdkErrorCodeConstants.OAUTH2_CLIENT_REDIRECT_URI_NOT_MATCH.getCode().equals(code)) { |
| | | throw exception(SdkErrorCodeConstants.OAUTH2_CLIENT_REDIRECT_URI_NOT_MATCH); |
| | | } else if (SdkErrorCodeConstants.OAUTH2_CLIENT_CLIENT_SECRET_ERROR.getCode().equals(code)) { |