API

공개 앱 토큰 발급 및 연동

작성일 2026.11.23 | 수정일 2026.11.23

새로 만드는 앱에는 OAuth 2.1 보안 규칙이 적용됩니다. OAuth 2.1은 OAuth 2.0에서 안전하지 않다고 판단된 방식(implicit 발급, PKCE 없는 code 교환 등)을 뺀 규격입니다.

  • 콘솔 「개발 → 내 앱 → 앱 설정 → OAuth2 클라이언트」에 OAuth 2.1 표시가 있으면 이 문서를 따릅니다.

  • 표시가 없는 기존 앱은 지금처럼 동작합니다. 적용하기 문서를 참고해 주세요.

  • 본인 계정만 쓰는 개인 연동(「개발 → OAuth2」)은 토큰 발급 및 연동 문서를 참고해 주세요.

기존 앱과 달라지는 점

항목

OAuth 2.1 앱

승인 방식

response_type=code 만 받습니다. implicit(token) 발급은 쓸 수 없습니다.

PKCE

승인 요청에 code_challenge(S256)가 필수입니다.

Redirect URI

등록한 값과 글자 그대로 같아야 합니다. https 주소나 로컬 개발용 loopback 주소만 등록할 수 있습니다.

클라이언트 인증

code 교환 · 토큰 갱신 모두 client_id · client_secret 이 필요합니다.

access token

1시간

refresh token

갱신해도 값이 바뀌지 않습니다. 30일 동안 쓰지 않으면 만료됩니다.

토큰 전달

API를 부를 때 Authorization: Bearer 헤더로만 보냅니다.

토큰 오류 형식

RFC 6749 형식 {"error": "...", "error_description": "..."} 입니다.

Step 1: Redirect URI 등록

앱 설정 「OAuth2 클라이언트」의 Redirect URI에 승인 후 돌아올 주소를 넣고 저장합니다. 등록하지 않으면 승인 요청이 InvalidHostName 으로 거절됩니다.

등록할 수 있는 주소

  • https:// 로 시작하는 주소 — 예: https://yourapp.com/oauth/callback

  • 로컬 개발용 loopback 주소 — http://127.0.0.1, http://[::1], http://localhost (포트 자유)

등록할 수 없는 주소

  • loopback이 아닌 http:// 주소

  • custom scheme — 예: myapp://callback

  • fragment(#)나 사용자 정보(user@)가 들어간 주소

  • 공백이나 한글 등 ASCII 밖의 글자가 들어간 주소. 인코딩해서 등록합니다.

승인 요청의 redirect_uri 는 등록한 값과 글자 하나까지 같아야 합니다. 끝 슬래시(/), 대소문자, 쿼리, :443 같은 기본 포트 표기가 달라도 거절됩니다. loopback 주소만 포트가 달라도 됩니다(데스크톱 앱이 빈 포트를 골라 쓰는 경우). localhost 와 127.0.0.1 은 서로 다른 주소로 봅니다.

lightbulb

Redirect URI는 앱 하나에 한 개만 등록할 수 있습니다. 개발 · 운영 주소를 함께 써야 한다면 앱을 나눠 만들어 주세요.

Step 2: PKCE 값 만들기

승인 요청마다 새로 만듭니다.

  • code_verifier: 43~128자의 임의 문자열. 서버 세션에 보관했다가 Step 4에서 보냅니다.

  • code_challenge: code_verifier 의 SHA-256 해시를 base64url(패딩 없음)로 인코딩한 값(43자)

// Node 18 이상
const crypto = require('node:crypto')

const codeVerifier = crypto.randomBytes(32).toString('base64url')
const codeChallenge = crypto
  .createHash('sha256')
  .update(codeVerifier)
  .digest('base64url')
const state = crypto.randomBytes(16).toString('hex')
// codeVerifier 와 state 를 사용자 세션에 저장합니다.

Step 3: 사용자 승인 요청

사용자를 아래 주소로 보냅니다. 사용자가 솔라피에 로그인해 권한에 동의하면 Redirect URI로 돌아옵니다.

GET https://api.solapi.com/oauth2/v1/authorize

쿼리 파라미터

필수

설명

client_id

true

앱의 Client ID

response_type

true

code

redirect_uri

true

Step 1에서 등록한 주소

scope

true

요청할 권한. 공백으로 구분합니다 (예: users:read message:read)

state

true

CSRF 방지용 임의 문자열. 돌아올 때 그대로 돌려줍니다.

code_challenge

true

Step 2에서 만든 값

code_challenge_method

true

S256 (plain 은 받지 않습니다)

https://api.solapi.com/oauth2/v1/authorize
  ?client_id=your_client_id
  &response_type=code
  &redirect_uri=https%3A%2F%2Fyourapp.com%2Foauth%2Fcallback
  &scope=users%3Aread%20message%3Aread
  &state=a1b2c3d4e5f6
  &code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
  &code_challenge_method=S256

승인하면 Redirect URI로 code 와 state 가 붙어 돌아옵니다. 돌아온 state 가 세션에 저장한 값과 같은지 반드시 확인합니다.

https://yourapp.com/oauth/callback?code=solapi_oac_...&state=a1b2c3d4e5f6

실패하면 error 가 붙어 돌아옵니다.

https://yourapp.com/oauth/callback?error=invalid_request&error_description=...&state=a1b2c3d4e5f6

error

뜻

unsupported_response_type

response_type 이 code 가 아닙니다.

invalid_request

code_challenge 가 없거나, S256 이 아니거나, 형식이 틀렸습니다.

invalid_scope

없는 권한이거나 앱에 등록하지 않은 권한입니다.

앱이 없거나(InvalidClientId), 꺼져 있거나(InactiveClient), redirect_uri 가 등록한 값과 다르면(InvalidHostName) Redirect URI로 돌려보내지 않고 바로 오류로 응답합니다.

이미 승인한 사용자이고 앱의 권한이 바뀌지 않았다면 동의 화면 없이 바로 돌아옵니다.

Step 4: 액세스 토큰 발급

받은 code 를 토큰으로 바꿉니다. 반드시 서버에서 요청합니다. client_secret 을 브라우저 · 앱 코드에 넣지 마세요.

POST https://api.solapi.com/oauth2/v1/access_token

본문 파라미터

필수

설명

grant_type

true

authorization_code

code

true

Step 3에서 받은 값 (solapi_oac_ 로 시작)

redirect_uri

true

Step 3에서 보낸 값과 글자 그대로 같은 값

code_verifier

true

Step 2에서 만든 값

client_id

true

Client ID. HTTP Basic 인증 헤더로 보낼 수도 있습니다.

client_secret

true

Client Secret. HTTP Basic 인증 헤더로 보낼 수도 있습니다.

POST /oauth2/v1/access_token HTTP/1.1
Host: api.solapi.com
Authorization: Basic base64(your_client_id:your_client_secret)
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code=solapi_oac_...&redirect_uri=https%3A%2F%2Fyourapp.com%2Foauth%2Fcallback&code_verifier=...
{
  "access_token": "eyJ...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "solapi_art_...",
  "scope": "users:read message:read"
}

응답의 scope 는 사용자가 실제로 승인한 권한입니다. 요청한 권한보다 적을 수 있으니 확인 후 기능을 제한해 주세요.

lightbulb

code는 5분 안에 한 번만 쓸 수 있습니다. 네트워크 오류로 응답을 받지 못했더라도 같은 code로 다시 요청하지 마세요. 이미 쓴 code가 다시 오면 탈취로 보고, 그 code로 발급한 refresh token까지 폐기합니다. 응답을 받지 못했다면 Step 3 승인 요청부터 다시 진행합니다.

Step 5: API 호출

access token을 Authorization 헤더에 담아 보냅니다. 쿼리나 본문으로 보내면 거절됩니다.

GET /users/v1/member HTTP/1.1
Host: api.solapi.com
Authorization: Bearer eyJ...

access token은 1시간 동안 쓸 수 있습니다. 요청마다 새로 받지 말고 만료 전까지 재사용해 주세요.

Step 6: 토큰 갱신

access token이 만료되면 refresh token으로 새로 받습니다.

본문 파라미터

필수

설명

grant_type

true

refresh_token

refresh_token

true

solapi_art_ 로 시작하는 값

scope

false

받은 권한보다 좁혀서 받을 때만 넣습니다. 넓힐 수는 없습니다.

client_id · client_secret

true

Step 4와 같습니다.

POST /oauth2/v1/access_token HTTP/1.1
Host: api.solapi.com
Authorization: Basic base64(your_client_id:your_client_secret)
Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token&refresh_token=solapi_art_...

응답 모양은 Step 4와 같고, refresh_token 은 보낸 값 그대로 돌려줍니다(값이 바뀌지 않습니다).

refresh token이 폐기되는 경우

아래 경우에는 갱신이 invalid_grant 로 실패합니다. 사용자에게 Step 3 승인부터 다시 받아야 합니다.

  • 30일 동안 갱신에 쓰지 않았을 때 (쓸 때마다 30일이 다시 시작됩니다)

  • 사용자가 비밀번호를 바꿨을 때

  • 사용자가 앱 승인을 철회했을 때

  • 같은 사용자가 다시 승인해 새 토큰을 받았을 때 (이전 refresh token 폐기)

  • 이미 쓴 code가 다시 교환 요청됐을 때

lightbulb

refresh token은 비밀번호처럼 다룹니다. 서버의 비밀 저장소에만 두고, 코드 · 로그 · 브라우저 저장소에 남기지 마세요.

토큰 오류

토큰 발급 · 갱신 오류는 아래 형식입니다. error_description 은 영어입니다.

{
  "error": "invalid_grant",
  "error_description": "The authorization code has expired."
}

error

상태

뜻

해결

invalid_client

401

클라이언트 인증이 없거나 틀렸거나, 앱이 꺼져 있습니다.

Client ID · Secret 확인, Secret을 재생성했다면 새 값으로 교체

unauthorized_client

400

앱에 허용되지 않은 grant입니다.

grant_type 확인

invalid_request

400

redirect_uri 나 code_verifier 가 없습니다.

필수 파라미터 확인

invalid_grant

400

code · refresh token이 만료 · 폐기됐거나, 이미 쓴 code이거나, redirect_uri · code_verifier 가 맞지 않습니다.

승인 요청부터 다시 진행

invalid_scope

400

갱신 때 보낸 scope 가 받은 권한을 넘습니다.

scope 를 빼거나 좁히기

연동 예시 (Node.js · Express)

const crypto = require('node:crypto')
const express = require('express')
const session = require('express-session')

const CLIENT_ID = process.env.SOLAPI_CLIENT_ID
const CLIENT_SECRET = process.env.SOLAPI_CLIENT_SECRET
const REDIRECT_URI = 'https://yourapp.com/oauth/callback'
const API = 'https://api.solapi.com'

const app = express()
app.use(session({ secret: process.env.SESSION_SECRET, resave: false, saveUninitialized: false }))

app.get('/login', (req, res) => {
  const verifier = crypto.randomBytes(32).toString('base64url')
  const state = crypto.randomBytes(16).toString('hex')
  req.session.oauth = { verifier, state }
  const url = new URL(`${API}/oauth2/v1/authorize`)
  url.search = new URLSearchParams({
    client_id: CLIENT_ID,
    response_type: 'code',
    redirect_uri: REDIRECT_URI,
    scope: 'users:read',
    state,
    code_challenge: crypto.createHash('sha256').update(verifier).digest('base64url'),
    code_challenge_method: 'S256'
  })
  res.redirect(url.toString())
})

app.get('/oauth/callback', async (req, res) => {
  const saved = req.session.oauth
  delete req.session.oauth
  if (!saved || req.query.state !== saved.state) return res.status(400).send('state 불일치')
  if (req.query.error) return res.status(400).send(req.query.error)

  const tokenRes = await fetch(`${API}/oauth2/v1/access_token`, {
    method: 'POST',
    headers: {
      Authorization: 'Basic ' + Buffer.from(`${CLIENT_ID}:${CLIENT_SECRET}`).toString('base64'),
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    body: new URLSearchParams({
      grant_type: 'authorization_code',
      code: req.query.code,
      redirect_uri: REDIRECT_URI,
      code_verifier: saved.verifier
    })
  })
  const token = await tokenRes.json()
  if (!tokenRes.ok) return res.status(400).send(token.error)
  // token.refresh_token 은 서버 비밀 저장소에 저장합니다.
  res.send('연동되었습니다.')
})

app.listen(3000)