- React + Vite + Tailwind 프론트엔드 - Express + Sequelize + MariaDB 백엔드 - 넥슨 OAuth 2.0 인증 (캐릭터 목록 조회) - 주간 보스 결정석 수익 계산기 UI (리스트형) - Docker Compose + Caddy 리버스 프록시 설정 - 보스/난이도 이미지 에셋 포함 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
import axios from 'axios';
|
|
|
|
const NEXON_API_BASE = 'https://open.api.nexon.com';
|
|
const NEXON_OPENID_BASE = 'https://openid.nexon.com';
|
|
|
|
export async function exchangeToken(code) {
|
|
const { data } = await axios.post(
|
|
`${NEXON_OPENID_BASE}/oauth2/token`,
|
|
new URLSearchParams({
|
|
grant_type: 'authorization_code',
|
|
client_id: process.env.NEXON_CLIENT_ID,
|
|
client_secret: process.env.NEXON_CLIENT_SECRET,
|
|
code,
|
|
}),
|
|
{ headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }
|
|
);
|
|
return data;
|
|
}
|
|
|
|
export async function refreshToken(refreshToken) {
|
|
const { data } = await axios.post(
|
|
`${NEXON_OPENID_BASE}/oauth2/token`,
|
|
new URLSearchParams({
|
|
grant_type: 'refresh_token',
|
|
client_id: process.env.NEXON_CLIENT_ID,
|
|
client_secret: process.env.NEXON_CLIENT_SECRET,
|
|
refresh_token: refreshToken,
|
|
}),
|
|
{ headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }
|
|
);
|
|
return data;
|
|
}
|
|
|
|
export async function getUserInfo(accessToken) {
|
|
const { data } = await axios.get(`${NEXON_OPENID_BASE}/api/v1/user/info`, {
|
|
headers: { Authorization: `Bearer ${accessToken}` },
|
|
});
|
|
return data.result;
|
|
}
|
|
|
|
export async function getCharacterList(accessToken) {
|
|
const { data } = await axios.get(`${NEXON_API_BASE}/maplestory/v1/character/list`, {
|
|
headers: { Authorization: `Bearer ${accessToken}` },
|
|
});
|
|
return data;
|
|
}
|
|
|
|
export async function getCharacterOcid(characterName) {
|
|
const { data } = await axios.get(`${NEXON_API_BASE}/maplestory/v1/id`, {
|
|
params: { character_name: characterName },
|
|
headers: { 'x-nxopen-api-key': process.env.NEXON_API_KEY },
|
|
});
|
|
return data.ocid;
|
|
}
|
|
|
|
export async function getCharacterBasic(ocid) {
|
|
const { data } = await axios.get(`${NEXON_API_BASE}/maplestory/v1/character/basic`, {
|
|
params: { ocid },
|
|
headers: { 'x-nxopen-api-key': process.env.NEXON_API_KEY },
|
|
});
|
|
return data;
|
|
}
|