API ์ธ์ฆ ํ† ํฐ

ย ์นด์นด์˜ค T ๋น„์ฆˆ๋‹ˆ์Šค API ์†Œ๊ฐœ
์นด์นด์˜ค T ๋น„์ฆˆ๋‹ˆ์Šค API ๋ฅผ ์ด์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” API ์ธ์ฆ ํ† ํฐ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

์ค€๋น„

biz.cs@kakaomobility.com ์œผ๋กœ ํ† ํฐ ์š”์ฒญ ์ด๋ฉ”์ผ์„ ๋ณด๋‚ด์ฃผ์„ธ์š”.
์นด์นด์˜ค T ๋น„์ฆˆ๋‹ˆ์Šค ์šด์˜์ž๊ฐ€ ์ „๋‹ฌํ•ด ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ์ „๋‹ฌ๋ฐ›์œผ์‹  ํ† ํฐ์œผ๋กœ API ํ˜ธ์ถœ์— ์‚ฌ์šฉํ•  API ์ธ์ฆ ํ† ํฐ์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

API ์ธ์ฆ ํ† ํฐ ์ƒ์„ฑ

API ์ธ์ฆ ํ† ํฐ์€ ํ•ด์‹ฑ(HmacSHA1)์„ ํ†ตํ•ด ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
์นด์นด์˜ค T ๋น„์ฆˆ๋‹ˆ์Šค ์šด์˜์ž๋กœ๋ถ€ํ„ฐ ์ „๋‹ฌ๋ฐ›์€ ํ† ํฐ์€ ํ•ด์‹ฑ์— ํ•„์š”ํ•œ Secret ์œผ๋กœ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.
ํ•ด์‹ฑ ๋  Message ๋Š” ๋‹ค์Œ์ฒ˜๋Ÿผ ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค.
Message ํฌ๋งท
โ€œ{๋‚œ์ˆ˜}\n{์š”์ฒญ๋  API URL}\n{์š”์ฒญ๋  API HttpMethod}\n{๊ธฐ์—… ID}\n{API์ธ์ฆํ† ํฐ์„ ์ƒ์„ฑํ•œ ์œ ๋‹‰์Šค์‹œ๊ฐ„(์ดˆ)}\n{๋‚œ์ˆ˜}โ€
Message ์˜ˆ์‹œ
โ€96292\nhttps://mob-b2b-dev.kakao.com/external/v2/orders\nGET\n00000000\n1698650510315\n96292โ€
๊ธฐ์—… ID ๋Š” ์นด์นด์˜ค T ๋น„์ฆˆ๋‹ˆ์Šค ๊ด€๋ฆฌ์‹œ์Šคํ…œ > ์„ค์ • > ๊ณ„์ •์ •๋ณด > T ๋น„์ฆˆ ID ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”.

API ์ธ์ฆ ํ† ํฐ ์ƒ์„ฑ ์˜ˆ์ œ

Java

import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import javax.xml.bind.DatatypeConverter; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.Date; import java.util.Random; public class ApiAuthTokenMaker { /** * ์นด์นด์˜ค T ๋น„์ฆˆ๋‹ˆ์Šค ๊ด€๋ฆฌ์‹œ์Šคํ…œ > ์„ค์ • > ๊ณ„์ •์ •๋ณด > T ๋น„์ฆˆ ID ๊ธฐ์ž… */ private static final String CORPORATION_ID = ""; /** * ์นด์นด์˜ค T ๋น„์ฆˆ ์šด์˜์ž๋กœ๋ถ€ํ„ฐ ์ด๋ฉ”์ผ๋กœ ์ „๋‹ฌ๋ฐ›์€ ํ† ํฐ ๊ธฐ์ž… */ private static final String SECRET = ""; private static final String HASH_ALGORITHM = "HmacSHA1"; public String makeApiAuthToken() throws NoSuchAlgorithmException, InvalidKeyException { Integer nonce = new Random().nextInt(100000); String url = "https://mob-b2b-dev.kakao.com/external/v2/orders"; String httpMethod = "GET"; Long timestamp = new Date().getTime(); String message = String.format("%s\n%s\n%s\n%s\n%s\n%s", nonce, url, httpMethod, CORPORATION_ID, timestamp, nonce); Mac sha1_HMAC = Mac.getInstance(HASH_ALGORITHM); SecretKeySpec secret_key = new SecretKeySpec(SECRET.getBytes(), HASH_ALGORITHM); sha1_HMAC.init(secret_key); byte[] hash = sha1_HMAC.doFinal(message.getBytes()); return DatatypeConverter.printBase64Binary(hash); } }
Java
๋ณต์‚ฌ

C#

using System; using System.Security.Cryptography; using System.Text; public class ApiAuthTokenMaker { private static readonly string CORPORATION_ID = ""; //์นด์นด์˜ค T ๋น„์ฆˆ๋‹ˆ์Šค ๊ด€๋ฆฌ์‹œ์Šคํ…œ > ์„ค์ • > ๊ณ„์ •์ •๋ณด > T ๋น„์ฆˆ ID ๊ธฐ์ž… private static readonly string SECRET = ""; //์นด์นด์˜ค T ๋น„์ฆˆ ์šด์˜์ž๋กœ๋ถ€ํ„ฐ ์ด๋ฉ”์ผ๋กœ ์ „๋‹ฌ๋ฐ›์€ ํ† ํฐ ๊ธฐ์ž… public string MakeApiAuthToken() { int nonce = new Random().Next(); string url = "https://mob-b2b-dev.kakao.com/external/v2/orders"; string httpMethod = "GET"; long timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds(); string message = string.Format("{0}\n{1}\n{2}\n{3}\n{4}\n{0}", nonce, url, httpMethod, CORPORATION_ID, timestamp); byte[] key = Encoding.UTF8.GetBytes(SECRET); HMACSHA1 hmacsha1 = new HMACSHA1(key); byte[] resultValue = hmacsha1.ComputeHash(Encoding.UTF8.GetBytes(message)); return Convert.ToBase64String(resultValue); } }
C#
๋ณต์‚ฌ