Getting 401 error while fetching Zoom Access Token

Hello Zoom Team,

I am using Android Meeting Sdk with SDK app with version 5.7.1.1267 and creating Json Web Token in backend which is required to fetch Zoom Access Token using jwt.io library and following code:

Date now = new Date(nowMillis);
long expMillis = nowMillis + 86400;
Date exp = new Date(expMillis);
String jwtToken = Jwts.builder()
.claim(“name”, “Jane Doe”)
.claim(“email”, “jane@example.com”)
.setSubject(“jane”)
.setId(UUID.randomUUID().toString())
.setIssuedAt(now)
.setExpiration(exp)
.compact();

I am sending https://api.zoom.us/v2/users/me/token to get Zoom Access Token, but I am not getting token, I am getting error 401.

Please help me out from this situation and suggest changes to be done.

Thank you
Megha

Hi @Megha1 ,

Moved this to the correct topic and someone from there will be able to assist you :slight_smile:

Gianni

Hi @gianni.zoom,

Should I switch to API And Webhooks?

Hi @Megha1 , it should be in Android Meeting SDK where I moved it; I’ll move it back there.

Hi @gianni.zoom, Please tell who can assist me?

Thank you

@Megha1 – this is my mistake. You placed in the right spot initially because the error is pertaining to the API. Please excuse me, so I’ll move it back.

In this post you said the request is working in Postman, but not via your front end code:

Could you please clarify if that is still the case?

Thanks!

Hi @gianni.zoom,

That was my previous discussion but now I am using Android Meeting Sdk with SDK app with version 5.7.1.1267 and creating Json Web Token in backend using java and maven which is required to fetch Zoom Access Token using jwt.io library and following code to generate token :

String secret = SDK_SECRET;
Key hmacKey = new SecretKeySpec(Base64.getDecoder().decode(secret),
SignatureAlgorithm.HS256.getJcaName());
long nowMillis = System.currentTimeMillis()/1000;
Date now = new Date(nowMillis);
long expMillis = nowMillis + 86400;
Date exp = new Date(expMillis);
String jwtToken = Jwts.builder()
.claim(“name”, “Jane Doe”)
.claim(“email”, “jane@example.com”)
.setSubject(“jane”)
.setId(UUID.randomUUID().toString())
.setIssuedAt(now)
.setExpiration(exp)
.signWith(hmacKey);
.compact();

I am using SDK_KEY and SDK_SECRET given in Sdk app and using this method to hit the API :

try {
String zoomUrl = “https://api.zoom.us/v2/users/me/token”;
URL url = new URL(zoomUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(“POST”);
connection.setRequestProperty (“Authorization”, jwtToken);
connection.setDoOutput(true);
int responseCode = connection.getResponseCode();
String responseFromZoom = “”;
String zoomResult = “”;
InputStream is = connection.getInputStream();
BufferedReader responseReader = new BufferedReader(new InputStreamReader(is));
while ((responseFromZoom = responseReader.readLine()) != null) {
zoomResult += responseFromZoom;
}
responseReader.close();
} catch (Exception exception) {
exception.printStackTrace();
}

I am sending https://api.zoom.us/v2/users/me/token to get Zoom Access Token, but I am not getting token, I am getting error 401 in response from zoom.

Please help me out from this situation and tell me where I am going wrong and suggest changes to be done to correct this.

Thank you
Megha

Hi @gianni.zoom ,

I tried another method to create JWT:

Date currentDate = new Date();
long currentTime = currentDate.getTime()/1000;
String secret = SDK_SECRET;
JsonObject payload = new JsonObject();
payload.addProperty(“appKey”, appProps.getProperty(“zoom.sdkKey”));
payload.addProperty(“iat”, currentTime);
payload.addProperty(“exp”, currentTime+86400);
payload.addProperty(“tokenExp”, currentTime+86400);
JsonObject header = new JsonObject();
header.addProperty(“alg”, “HS256”);
header.addProperty(“typ”, “JWT”);

String jwtToken;
try {
String signature = hmacSha256(
Base64.getEncoder().encodeToString(header.toString().getBytes(“UTF-8”))
+ “.” + Base64.getEncoder().encodeToString(payload.toString().getBytes(“UTF-8”)),
secret);
jwtToken = Base64.getEncoder().encodeToString(header.toString().getBytes(“UTF-8”)) + “.” + Base64.getEncoder().encodeToString(payload.toString().getBytes(“UTF-8”)) + “.” + signature;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return “”;
}

private static String encode(byte bytes) {
return Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
}

private String hmacSha256(String data, String secret) {
    try {
        byte[] hash = secret.getBytes(StandardCharsets.UTF_8);
        Mac sha256Hmac = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKey = new SecretKeySpec(hash, "HmacSHA256");
        sha256Hmac.init(secretKey);
        byte[] signedBytes = sha256Hmac.doFinal(data.getBytes(StandardCharsets.UTF_8));
        return encode(signedBytes);
    } catch (Exception ex) {
        ex.printStackTrace();
    	return null;
    }
}		

and using same method to fetch ZAK but this is also not working as I am getting same 401 error.

Please suggest me what should I do next and where I am wrong if possible as I tried with postman also and I am getting same there with message “Invalid access token”.

Thank you

Hi @Megha1 ,

Thanks for this! Can you send your full details to developersupport@zoom.us addressed to me so I can help debug and test on my end?

Thank you!

Hi @gianni.zoom,

Thanks for the post, I will mail there

1 Like

Thank you @Megha1!

Max