๋ณธ๋ฌธ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

๐Ÿ”‘ ์—˜๋ฆฌ์Šค ๋กœ๊ทธ์ธ ์—ฐ๋™ ๊ฐœ๋ฐœ ๊ฐ€์ด๋“œ

์ด ๋ฌธ์„œ๋Š” ์—˜๋ฆฌ์Šค์— OAuth ๊ธฐ๋ฐ˜์œผ๋กœ ๋กœ๊ทธ์ธ์„ ์—ฐ๋™ํ•˜๊ธฐ ์œ„ํ•œ ๊ฐœ๋ฐœ์ ˆ์ฐจ๋ฅผ ์•ˆ๋‚ดํ•ฉ๋‹ˆ๋‹ค.

1. ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋“ฑ๋กโ€‹

์—˜๋ฆฌ์Šค ๋กœ๊ทธ์ธ์„ ์—ฐ๋™ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋จผ์ € ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ด๋ฆ„๊ณผ Redirect URI ๋ฅผ ๋“ฑ๋กํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. backend@elicer.com ๋ฉ”์ผ๋กœ ์•„๋ž˜ ์ •๋ณด๋ฅผ ๋ณด๋‚ด์ฃผ์‹œ๋ฉด ๋‚ด๋ถ€์—์„œ ๋“ฑ๋ก ํ›„ ์•ˆ๋‚ด๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค.

  • ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ด๋ฆ„
  • Redirect URI (์ตœ๋Œ€ 5๊ฐœ, https ํ•„์ˆ˜)
    • ๋กœ๊ทธ์ธ ์™„๋ฃŒ ์ดํ›„ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ›์•„๋ณผ ํŽ˜์ด์ง€์˜ ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค. (์˜ˆ์‹œ: https://my-site.com/elice/ouath/okay)

๋‚ด๋ถ€ ๋“ฑ๋ก ํ”„๋กœ์„ธ์Šค๊ฐ€ ์™„๋ฃŒ๋œ ํ›„ ์•„๋ž˜์˜ ์ •๋ณด๋ฅผ ์•ˆ๋‚ดํ•ด๋“œ๋ฆฝ๋‹ˆ๋‹ค.

  • client_id
  • client_secret
  • ELICE_WEB_URL (๊ฐœ๋ฐœ)
  • ELICE_SERVER_URL (๊ฐœ๋ฐœ)
  • ELICE_WEB_URL (์šด์˜)
  • ELICE_SERVER_URL (์šด์˜)

2. ์—˜๋ฆฌ์Šค ๋กœ๊ทธ์ธ ์—ฐ๋™ URL ์ƒ์„ฑํ•˜๊ธฐโ€‹

์—˜๋ฆฌ์Šค ๋กœ๊ทธ์ธ ์—ฐ๋™ ๋ฒ„ํŠผ์„ ํด๋ฆญํ–ˆ์„ ๋•Œ ์—˜๋ฆฌ์Šค ๋กœ๊ทธ์ธ ํ™”๋ฉด์œผ๋กœ ์ด๋™์‹œํ‚ค๊ธฐ ์œ„ํ•œ API ํ˜ธ์ถœ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์†Œ๊ฐœํ•ฉ๋‹ˆ๋‹ค.

์•„๋ž˜์˜ ์š”์ฒญ ๋ณ€์ˆ˜๋ฅผ ์ฑ„์›Œ API ๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ์‚ฌ์šฉ์ž๋Š” ์—˜๋ฆฌ์Šค ๋กœ๊ทธ์ธ ํ™”๋ฉด์œผ๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ๋ฉ๋‹ˆ๋‹ค.

ํ•ด๋‹น ๋กœ๊ทธ์ธ ํ™”๋ฉด์—์„œ ์‚ฌ์šฉ์ž๊ฐ€ ๋กœ๊ทธ์ธ์„ ์™„๋ฃŒํ•˜๋ฉด ๊ฒฐ๊ณผ์™€ ํ•จ๊ป˜ Redirect URI ๋กœ ๋‹ค์‹œ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ๋ฉ๋‹ˆ๋‹ค.

์š”์ฒญ URL ์ •๋ณด

๋ฉ”์„œ๋“œ์š”์ฒญ URL์‘๋‹ต ํ˜•ํƒœ์„ค๋ช…
GEThttps://{ELICE_WEB_URL}/oauth/authorizeURL ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ์—˜๋ฆฌ์Šค ๋กœ๊ทธ์ธ ์ธ์ฆ ์š”์ฒญ

์š”์ฒญ ๋ณ€์ˆ˜ ์ •๋ณด

์š”์ฒญ ๋ณ€์ˆ˜๋ช…ํƒ€์ž…ํ•„์ˆ˜ ์—ฌ๋ถ€๊ธฐ๋ณธ๊ฐ’์„ค๋ช…
client_idstringY-์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋“ฑ๋ก ์‹œ ๋ฐœ๊ธ‰๋ฐ›์€ Client ID ๊ฐ’
redirect_uristringY-์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋“ฑ๋ก ์‹œ ์ž…๋ ฅํ•œ Redirect URI ๊ฐ’ ์ค‘ ํ•˜๋‚˜ (URL ์ธ์ฝ”๋”ฉ ์ ์šฉ ํ•„์š”)
statestringY-๋ณด์•ˆ์„ ์œ„ํ•ด ๋งค๋ฒˆ ์ƒˆ๋กญ๊ฒŒ ์ƒ์„ฑํ•˜๋Š” ๋žœ๋คํ•œ ๋ฌธ์ž์—ด ๊ฐ’
scopestringYread์ฝค๋งˆ๋กœ ๊ตฌ๋ถ„๋˜๋Š” ๊ถŒํ•œ์˜ ๋ชฉ๋ก
langstringYko์‚ฌ์šฉ ์–ธ์–ด๋ฅผ ๊ตฌ๋ถ„ํ•˜๊ธฐ ์œ„ํ•œ ๊ฐ’

์š”์ฒญ๋ฌธ ์˜ˆ์‹œ

curl -X GET "https://\{ELICE_WEB_URL\}/oauth/authorize?client_id=myclientid&redirect_uri=redirect_uri=https%3A%2F%2Fmy-site.com%2Felice%2Fouath%2Fokay&state=om22bsq0jz&scope=read&lang=ko"

์‘๋‹ต ์˜ˆ์‹œ

HTTP/1.1 302 Found
Location: https://my-site.com/elice/ouath/okay?code=okaycode12345&state=om22bsq0jz

3. ์ ‘๊ทผ ํ† ํฐ ๋ฐœ๊ธ‰ ์š”์ฒญโ€‹

Redirect URI ๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ๋˜๋ฉฐ ์ฟผ๋ฆฌ ์ŠคํŠธ๋ง์„ ํ†ตํ•ด ์ „๋‹ฌ๋ฐ›์€ ์ธ์ฆ ์ฝ”๋“œ(code)๋Š” ์ ‘๊ทผ ํ† ํฐ(access token)์„ ๋ฐœ๊ธ‰๋ฐ›๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

์ธ์ฆ ์ฝ”๋“œ๋Š” ์ผํšŒ์šฉ์ด๋ฉฐ, ์ ‘๊ทผ ํ† ํฐ์„ 1ํšŒ ๋ฐœ๊ธ‰ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋œ ํ›„ ์žฌ์‚ฌ์šฉ์ด ๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์ ‘๊ทผ ํ† ํฐ์€ ์ดํ›„ ์œ ์ €์ •๋ณด API ๋“ฑ ์—˜๋ฆฌ์Šค REST API ๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

์ด API ๋Š” ์‚ฌ์šฉ์ž์˜ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์•„๋‹Œ ์„œ๋ฒ„์—์„œ ์‹คํ–‰๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์š”์ฒญ URL ์ •๋ณด

๋ฉ”์„œ๋“œ์š”์ฒญ URL์‘๋‹ต ํ˜•ํƒœ์„ค๋ช…
POSThttps://{ELICE_SERVER_URL}/oauth/tokenjson์ ‘๊ทผ ํ† ํฐ ๋ฐœ๊ธ‰ ์š”์ฒญ

์š”์ฒญ ๋ณ€์ˆ˜ ์ •๋ณด

์š”์ฒญ ๋ณ€์ˆ˜๋ช…ํƒ€์ž…ํ•„์ˆ˜ ์—ฌ๋ถ€๊ธฐ๋ณธ๊ฐ’์„ค๋ช…
client_idstringY-์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋“ฑ๋ก ์‹œ ๋ฐœ๊ธ‰๋ฐ›์€ Client ID ๊ฐ’
client_secretstringY-์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋“ฑ๋ก ์‹œ ๋ฐœ๊ธ‰๋ฐ›์€ Client Secret ๊ฐ’
codestringY-Redirect URI ๋ฅผ ํ†ตํ•ด ์ „๋‹ฌ ๋ฐ›์€ ์ธ์ฆ ์ฝ”๋“œ ๊ฐ’

์š”์ฒญ๋ฌธ ์˜ˆ์‹œ

curl -X POST "https://\{ELICE_SERVER_URL\}/oauth/token" \
-H "Content-Type: application/json" \
-d '{"client_id":"myclientid","client_secret":"myclientsecret","code": "okaycode12345"}'

์‘๋‹ต ์ •๋ณด

ํ•„๋“œํƒ€์ž…์„ค๋ช…
access_tokenstring์ ‘๊ทผ ํ† ํฐ (๋ฐœ๊ธ‰์œผ๋กœ๋ถ€ํ„ฐ 1์‹œ๊ฐ„ ์ดํ›„ ๋งŒ๋ฃŒ)

์‘๋‹ต ์˜ˆ์‹œโ€‹

HTTP/1.1 200 OK
Content-Type: application/json

{
"access_token": "your_access_token"
}

4. ์ ‘๊ทผ ํ† ๊ทผ์„ ์ด์šฉํ•˜์—ฌ ์œ ์ € ์ •๋ณด API ํ˜ธ์ถœํ•˜๊ธฐโ€‹

์ ‘๊ทผ ํ† ํฐ์„ ์‚ฌ์šฉํ•˜์—ฌ ์œ ์ € ์ •๋ณด ์กฐํšŒ API๋ฅผ ํ˜ธ์ถœ ํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์š”์ฒญ URL ์ •๋ณด

๋ฉ”์„œ๋“œ์ธ์ฆ์š”์ฒญ URL์‘๋‹ต ํ˜•ํƒœ์„ค๋ช…
GETOAuth2.0https://{ELICE_SERVER_URL}/oauth/accountJSON์œ ์ € ์ •๋ณด ์กฐํšŒ

์š”์ฒญ ๋ณ€์ˆ˜ ์ •๋ณด

์š”์ฒญ ๋ณ€์ˆ˜๋Š” ๋ณ„๋„๋กœ ์—†์œผ๋ฉฐ, ์š”์ฒญ URL๋กœ ํ˜ธ์ถœํ•  ๋•Œ ์•„๋ž˜์™€ ๊ฐ™์ด ์š”์ฒญ ํ—ค๋”์— ์ ‘๊ทผ ํ† ํฐ ๊ฐ’์„ ์ „๋‹ฌํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์š”์ฒญ ํ—ค๋”

์š”์ฒญ ํ—ค๋”๋ช…์„ค๋ช…
Authorization๋‹ค์Œ ํ˜•ํƒœ์˜ ๊ฐ’ : Bearer {์ ‘๊ทผ ํ† ํฐ}

์š”์ฒญ๋ฌธ ์˜ˆ์‹œ

curl -X GET "https://\{ELICE_SERVER_URL\}/oauth/account" \
-H "Authorization: Bearer your_access_token"

์‘๋‹ต ์ •๋ณด

ํ•„๋“œํƒ€์ž…ํ•„์ˆ˜ ์—ฌ๋ถ€์„ค๋ช…
idStringY๋™์ผ์ธ ์‹๋ณ„ ์ •๋ณด
fullnameStringY์‚ฌ์šฉ์ž ์ด๋ฆ„
emailStringY์‚ฌ์šฉ์ž ๋ฉ”์ผ ์ฃผ์†Œ
phoneStringY์‚ฌ์šฉ์ž ํœด๋Œ€์ „ํ™”๋ฒˆํ˜ธ
profile_urlStringY์‚ฌ์šฉ์ž ํ”„๋กœํ•„ ์‚ฌ์ง„ URL
localeStringY์‚ฌ์šฉ์ž ์ง€์—ญ์ •๋ณด

์‘๋‹ต ์˜ˆ์‹œโ€‹

HTTP/1.1 200 OK
Content-Type: application/json

{
"id": 12345,
"fullname": "John Doe",
"email": "john.doe@example.com",
"phone": "010-1234-5678",
"profile_url": "https://example.com/profile/johndoe",
"locale": "ko"
}