실무에서 활용한 기술

[Zoom API 연동 ] Zoom Server-to-Server OAuth 연동

러쉬봠 2023. 8. 4. 11:08

Zoom API는 JSON 웹 토큰(JWT)을 사용하였는데 JWT 앱 유형은 더 이상 사용되지 않습니다. 서버 간 OAuth앱 또는 OAuth앱을 생성하여 계정에서 JWT앱의 기능을 대체하는 것이 좋습니다.

기존에는 JWT 값을 DB에 저장해서 조회한 다음에 API를 돌렸던 구조라면 sts oauth 는 전달한 id, secret 값으로 엑세스 토큰값을 조회한 다음 그걸로 API를 사용

 

1. Postman을 통해 API 테스트

  • POST https://zoom.us/oauth/token?grant_type=account_credentials&account_id= {accountId}
  • HTTP/1.1
  • Host: zoom.us
  • Authorization: Basic Base64Encoder(clientId:clientSecret)

accountId, clientId,  clientSecret OAuth에서 생성된 값

 

- https://developers.zoom.us/docs/api/rest/postman/ -> Zoom Developer Postman Workspace  로 이동 -> Get Started Fast with Zoom APIs -> Server-to-Server OAuth App -> (post) Get access token 에서 postman test 예시가 있습니다.

 

결과 값 : { “Access_token“: String, “Token_type”: “bearer”, “Expire_in”: long, “scope” : [String] }

 

2. Java 코드 적용

Token값을 조회하기 위해 Service로직에 추가

public static ZoomMeetingsModel postZoomMeetingsToken(Map<String, Object> param) {
		HttpClient httpclient = getHttpClient();
		HttpResponse response = null;
		try {
			String url = "https://zoom.us/oauth/token?grant_type=account_credentials&account_id=" + param.get("account_id");
			String userName = (String) param.get("client_id");
			String password = (String) param.get("client_secret");
			String credentials = userName + ":" + password;
			String encodedValue = Base64.encodeBase64String(credentials.getBytes());
			HttpPost httpPost = new HttpPost(url);
			httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
			httpPost.setHeader("Authorization", "Basic " + encodedValue);

			List<NameValuePair> params = new ArrayList<NameValuePair>();
			Set<String> paramSet = param.keySet();
			for (String key : paramSet) {
				params.add(new BasicNameValuePair(key, CommonUtil.getString(param.get(key))));
			}

			if (log.isInfoEnabled()) {
				log.info("[ZOOM Token 조회] " + params);
			}

			response = httpclient.execute(httpPost);
			int statusCode = response.getStatusLine().getStatusCode();

			if (log.isInfoEnabled()) {
				log.info("[ZOOM Token 결과] " + response);
			}

			if (statusCode == 200) {
				HttpEntity httpEntity = response.getEntity();
				BufferedReader br = new BufferedReader(new InputStreamReader(httpEntity.getContent(), Charset.forName("UTF-8")));
				StringBuilder contentBuilder = new StringBuilder();
				String buffer = null;
				while ((buffer = br.readLine()) != null) {
					contentBuilder.append(buffer);
				}
				String result = contentBuilder.toString();
				return new Gson().fromJson(result, ZoomMeetingsModel.class);
			}
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		return null;
	}
  • account_id, client_id, client_secret은 파라미터로 전달받아서 사용.
    (앱을 통해 생성된 공통 사용 값이기에 properties에 등록)
  • userName과 password는 Base64를 통해 암호화 진행
  • API가 통신이 성공하였다면 결과 값 : { “Access_token“: String, “Token_type”: “bearer”, “Expire_in”: long, “scope” : [String] }
  • Json 형태로 반환해준다.
  • Contorller에서 ZoomModel zoomToken = Functions.postZoomMeetingsToken(map)으로 결과값 받아온다.
  • ZoomModel에 access_token을 담을 수 있는 변수 선언
  • getAccess_token으로 값 사용

참조 : https://developers.zoom.us/docs/internal-apps/s2s-oauth/

참조 : https://www.ibm.com/docs/ko/odmoc?topic=rulesets-using-rest-api-call-ruleset

 

Server-to-Server OAuth

The Zoom Developer Platform is an open platform that allows third-party developers to build applications and integrations upon Zoom’s video-first unified communications platform.

developers.zoom.us