공공기관 bot, mail기능을 작성하려고 하는데 인증에 실패합니다.

강강강_5d83f6

2024.04.23읽음 81

Authorization Code도 정상적으로 발행되지 않고
토큰인증시 401오류가 나옵니다.
Authorization Code : 
CLIENT_APP_NOT_FOUND 메세지가 나오는데 클라이언트 아이디는 몇번이나 확인했습니다.
jwt인증으로 토큰을 발급받았지만 401이 리턴됐습니다.
토큰인증 :  

Map<String, Object> headers = new HashMap<String, Object>();
headers.put("alg", "RS256");
headers.put("typ", "JWT");
Date iat = new Date();
Date exp = DateUtils.addMinutes(new Date(), 30);
String grantType = URLEncoder.encode("urn:ietf:params:oauth:grant-type:jwt-bearer",
StandardCharsets.UTF_8.toString());
RSAPublicKey publicKey = null;
RSAPrivateKey privateKey = RSAUtils.getPrivateKey("private.key"); 
Algorithm algorithmRS = Algorithm.RSA256(publicKey, privateKey);
String assertion = JWT.create().withHeader(headers).withIssuer(아이디) // Client ID
.withSubject(서비스어카운트) // Service Account
.withIssuedAt(iat).withExpiresAt(exp).sign(algorithmRS);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("grant_type", grantType));
params.add(new BasicNameValuePair("client_id", 아이디)); // Client ID
params.add(new BasicNameValuePair("client_secret", 시크릿)); // Client Secret
params.add(new BasicNameValuePair("assertion", assertion));
params.add(new BasicNameValuePair("scope", "bot")); 
URI uri = new URI("https://auth.gov-naverworks.com/oauth2/v2.0/token");
URIBuilder ub = new URIBuilder(uri);
...
이 코드로 토큰은 발행되었지만 api를 실행하니 401이 반환되었습니다.
token을 받아 실행한 코드입니다
봇아이디와 채널아이디는 몇번씩 확인하였습니다
String apiUrl = "https://www.worksapis.com/v1.0/bots/"+botId+"/channels/"+channelId+"/messages";
HttpPost method  = new HttpPost(apiUrl);
method.setHeader("Authorization", "Bearer " + accessToken);
method.setHeader("Content-Type","application/json; charset=UTF-8");
method.setEntity(new StringEntity("{ \"content\" : "+contents+" \r\n }", "UTF-8"));
CloseableHttpClient client = HttpClients.createDefault();
HttpResponse response = client.execute(method);
String Error = EntityUtils.toString(response.getEntity(), "UTF-8");
System.out.println(Error);

양쪽 인증 다 api 오류인것으로 추측되는데 해결할 방법이 있을까요?

댓글0

이전 글jwt를 사용하여 토큰 발급시 400 에러
다음 글date -> dateTime 변경되었나요?? ㅎㅎ?
목록

궁금한 점을 해결하지 못하셨나요?
지금 바로 NAVER WORKS 사용자들에게 물어보세요!