Home - RWB0104/api.itcode.dev-oauth2 GitHub Wiki

OAuth2.0 Backend API

์ด ๋ฌธ์„œ๋Š” OAuth2.0 ํ”„๋กœ์ ํŠธ ์ธ์ฆ์„œ๋ฒ„์˜ API ๋ช…์„ธ์„œ์ž„.

์ œ๊ณตํ•˜๋Š” API๋Š” ์•„๋ž˜์™€ ๊ฐ™์Œ.

  • AgreementAPI /oauth2/api/agreement - ์ •๋ณด ์ œ๊ณต ๋™์˜ API
  • LoginAPI /oauth2/api/login - ๋กœ๊ทธ์ธ API
  • LogoutAPI /oauth2/api/logout - ๋กœ๊ทธ์•„์›ƒ API
  • RevokeAPI /oauth2/api/revoke - ์—ฐ๋™ ํ•ด์ œ API
  • UserInfoAPI/oauth2/api/userinfo - ์‚ฌ์šฉ์ž ์ •๋ณด API



LoginAPI

๋กœ๊ทธ์ธ API

/oauth2/api/login

ํ”Œ๋žซํผ ๋กœ๊ทธ์ธ URL API

API_KEY, SECRET_KEY, CALLBACK_URL์„ ํ†ตํ•ด ํ”Œ๋žซํผ ๋กœ๊ทธ์ธ URL์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

ํ”Œ๋žซํผ ๋กœ๊ทธ์ธ ๊ฒฐ๊ณผ์— ๋”ฐ๋ผ ์ •์ƒ์ผ ๊ฒฝ์šฐ code๋ฅผ, ๋น„์ •์ƒ์ผ ๊ฒฝ์šฐ error๋ฅผ URL ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋‹ด์•„ CALLBACK_URL๋กœ ๋ฆฌ๋‹ค์ด๋ ‰์…˜ํ•œ๋‹ค.

์š”์ฒญ

GET https://api.itcode.dev/oauth2/api/login/{:platform}
parameter type data required description
{:platform} path String Y ํ”Œ๋žซํผ (์†Œ๋ฌธ์ž ํ‘œ๊ธฐ)

์‘๋‹ต

{
	"flag": true,
	"title": "success",
	"message": "naver authrorization url response success",
	"body": "https://nid.naver.com/oauth2.0/authorize?response_type=code&client_id=czCaqAOB1aAjNRk6N_Oq&redirect_uri=https%3A%2F%2Fproject.itcode.dev%2Foauth2%2Fcallback%3Fplatform%3Dnaver&state=b73ed0eb-abcc-4f95-b1d9-d52623e90946"
}

์œ„ ์‘๋‹ต์€ https://api.itcode.dev/oauth2/api/login/naver์˜ ์˜ˆ์‹œ๋‹ค.

parameter data description
flag boolean ๋™์ž‘ ๊ฒฐ๊ณผ
title String ์ œ๋ชฉ
message String ๋‚ด์šฉ
body String ํ”Œ๋žซํผ ๋กœ๊ทธ์ธ URL

์ •๋ณด ์ œ๊ณต ๋™์˜ ๊ฐฑ์‹  URL API

์ •๋ณด ์ œ๊ณต ๋™์˜๋ฅผ ์žฌ์„ ํƒํ•  ์ˆ˜ ์žˆ๋Š” URL์„ ์ƒ์„ฑํ•˜์—ฌ ๋ฐ˜ํ™˜ํ•˜๋Š” API.

์žฌ๋™์˜๊ฐ€ ์ด๋ฃจ์–ด์ง„ ํ›„ ๋‹ค์‹œ ํ•œ ๋ฒˆ ๋กœ๊ทธ์ธ ๊ณผ์ •์„ ๊ฑฐ์ณ ๊ฐฑ์‹ ๋œ ๋‚ด์šฉ์ด ๋ฐ˜์˜๋œ ์ธ์ฆ ์ •๋ณด๋ฅผ ๋‹ค์‹œ ์ƒ์„ฑํ•œ๋‹ค.

์ง€์›ํ•˜๋Š” ํ”Œ๋žซํผ์€ ์•„๋ž˜ ๋‘ ํ”Œ๋žซํผ์ด๋‹ค.

  • NAVER - ํ•„์ˆ˜, ์ถ”๊ฐ€ ์ •๋ณด์— ๊ด€๊ณ„์—†์ด ์ž„์˜๋กœ ํ—ˆ๊ฐ€/๊ฑฐ๋ถ€๊ฐ€ ๊ฐ€๋Šฅํ•จ
  • KAKAO - ์ถ”๊ฐ€์— ํ•ด๋‹นํ•˜๋Š” ์ •๋ณด๋งŒ ํ—ˆ๊ฐ€/๊ฑฐ๋ถ€๊ฐ€ ๊ฐ€๋Šฅํ•˜๋ฉฐ, ์ด๋ฏธ ํ—ˆ๊ฐ€ํ•œ ์ •๋ณด๋Š” ๊ฑฐ๋ถ€ ๋ถˆ๊ฐ€

Google์˜ ๊ฒฝ์šฐ, ์š”์ฒญํ•˜๋Š” ์ •๋ณด๊ฐ€ ํ”„๋กœํ•„ ์ •๋ณด๋ฅผ ๋ฒ—์–ด๋‚˜์ง€ ์•Š์œผ๋ฏ€๋กœ ๋ณ„๋„์˜ ๋™์˜ ๊ณผ์ •์ด ์—†์–ด์„œ ์˜๋ฏธ๊ฐ€ ์—†๋‹ค.

GitHub์˜ ๊ฒฝ์šฐ, OAuth ์•ฑ์€ ํ”„๋กœํ•„ ์ •๋ณด๋งŒ์„ ๊ฐ€์ ธ์˜ค๋ฏ€๋กœ ๋ณ„๋„์˜ ๋™์˜ํ•ญ๋ชฉ์ด ์—†๋‹ค.

์š”์ฒญ

PUT https://api.itcode.dev/oauth2/api/login/put
Cookie: access={:access};
parameter type data required description
{:access} Cookie String Y ์ธ์ฆ ์ฟ ํ‚ค

์‘๋‹ต

{
	"flag": true,
	"title": "success",
	"message": "naver reauthrorization url response success",
	"body": "https://nid.naver.com/oauth2.0/authorize?auth_type=reprompt&state=08199e0e-ef61-444a-8d4f-f3c048b771f0&response_type=code&client_id=czCaqAOB1aAjNRk6N_Oq&redirect_uri=https%3A%2F%2Fproject.itcode.dev%2Foauth2%2Fcallback%3Fplatform%3Dnaver"
}

์œ„ ์‘๋‹ต์€ https://api.itcode.dev/oauth2/api/login/put์˜ ์˜ˆ์‹œ๋‹ค.

parameter data description
flag boolean ๋™์ž‘ ๊ฒฐ๊ณผ
title String ์ œ๋ชฉ
message String ๋‚ด์šฉ
body String ์ •๋ณด ์ œ๊ณต ๋™์˜ ๊ฐฑ์‹  URL URL

๋กœ๊ทธ์ธ API

ํ”Œ๋žซํผ ๋กœ๊ทธ์ธ ๊ฒฐ๊ณผ๋กœ ๋ฐœ๊ธ‰๋ฐ›์€ code๋ฅผ Access Token์œผ๋กœ ๊ตํ™˜ํ•˜์—ฌ ์„œ๋น„์Šค ์ธ์ฆ ํ† ํฐ์„ ์ƒ์„ฑํ•˜๋Š” API.

์ƒ์„ฑํ•œ ์ธ์ฆ ํ† ํฐ์„ ์ฟ ํ‚ค์— ์ €์žฅํ•˜์—ฌ ๋กœ๊ทธ์ธ ์ฒ˜๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ•œ๋‹ค.

Access Token๊ณผ Refresh Token์„ JWT๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์ œ๊ณตํ•˜๋ฉฐ, ์ธ์ฆ์ด ํ•„์š”ํ•œ ๊ฐ์ข… ์š”์ฒญ์— ํ•ด๋‹น ์ฟ ํ‚ค๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

์š”์ฒญ

POST https://api.itcode.dev/oauth2/api/login/{:platform}

{
    "code": {:code},
    "state": {:state}
}
parameter type data required description
{:platform} path String Y ํ”Œ๋žซํผ (์†Œ๋ฌธ์ž ํ‘œ๊ธฐ)
{:code} body String Y ์ ‘๊ทผ ์ฝ”๋“œ
{:state} body String Y ๊ณ ์œ  ์ƒํƒœ๊ฐ’

์‘๋‹ต

{
	"flag": true,
	"title": "success",
	"message": "authorized success",
	"body": null
}
# Header
Set-Cookie: access={access JWT}
Set-Cookie: refresh={refresh JWT}

Set-Cookie ํ—ค๋”๋ฅผ ํ†ตํ•ด ์ธ์ฆ ์ฟ ํ‚ค๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

parameter data description
flag boolean ๋™์ž‘ ๊ฒฐ๊ณผ
title String ์ œ๋ชฉ
message String ๋‚ด์šฉ
body null null

์ž๋™ ๋กœ๊ทธ์ธ API

access, refresh ์ฟ ํ‚ค๋ฅผ ๊ฒ€์ฆํ•˜์—ฌ ์œ ํšจํ•  ๊ฒฝ์šฐ ์ž๋™๋กœ๊ทธ์ธ์„ ์ง„ํ–‰ํ•˜๋Š” API.

์ฟ ํ‚ค์˜ ๋ณด๊ด€ ์—ฌ๋ถ€์— ๋”ฐ๋ผ ๋งค์ปค๋‹ˆ์ฆ˜์ด ๋‹ฌ๋ผ์ง„๋‹ค.

access ์ฟ ํ‚ค๋ฅผ ๋ณด์œ ํ•˜๊ณ  ์žˆ์„ ๊ฒฝ์šฐ, ์ด๋ฏธ ์ธ์ฆ ์ •๋ณด๋ฅผ ๋ณด์œ ํ•˜๊ณ ์žˆ๋Š” ์…ˆ์ด๋ฏ€๋กœ ๋ณ„๋‹ค๋ฅธ ๋™์ž‘์„ ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š์œผ๋ฉฐ ์ฆ‰์‹œ ํ™ˆ์œผ๋กœ ๋ฆฌ๋‹ค์ด๋ ‰์…˜ ์‹œํ‚จ๋‹ค. ์ด ๋•Œ refresh ํ† ํฐ์˜ ์œ ๋ฌด๋Š” ์‹ ๊ฒฝ์“ฐ์ง€ ์•Š๋Š”๋‹ค.

refresh ์ฟ ํ‚ค๋งŒ ๋ณด์œ ํ•˜๊ณ  ์žˆ์„ ๊ฒฝ์šฐ, Access Token์„ ๊ฐฑ์‹ ํ•˜์—ฌ ๋กœ๊ทธ์ธ ์ ˆ์ฐจ๋ฅผ ์ˆ˜ํ–‰ํ•œ๋‹ค. ์ด ๋•Œ Set-Cookie ํ—ค๋”๋ฅผ ํ†ตํ•ด ์ƒˆ๋กœ์šด ์ธ์ฆ ์ •๋ณด๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

์š”์ฒญ

POST https://api.itcode.dev/oauth2/api/login/auto
Cookie: access={:access}; refresh={:refresh};
parameter type data required description
{:access} Cookie String N ์ธ์ฆ ์ฟ ํ‚ค
{:refresh} Cookie String Y ๋ฆฌํ”„๋ ˆ์‰ฌ ์ฟ ํ‚ค

์‘๋‹ต

{
	"flag": true,
	"title": "success",
	"message": "auto authorized success",
	"body": null
}
# Header
Set-Cookie: access={access JWT}
Set-Cookie: refresh={refresh JWT}

refresh ์ฟ ํ‚ค๋งŒ์„ ๋ณด์œ ํ•˜๊ณ  ์žˆ์–ด์„œ Access Token์„ ๊ฐฑ์‹ ํ•œ ๊ฒฝ์šฐ์—๋งŒ Set-Cookie๊ฐ€ ํฌํ•จ๋œ๋‹ค.

parameter data description
flag boolean ๋™์ž‘ ๊ฒฐ๊ณผ
title String ์ œ๋ชฉ
message String ๋‚ด์šฉ
body null null



LogoutAPI

๋กœ๊ทธ์•„์›ƒ API

/oauth2/api/logout

๋กœ๊ทธ์•„์›ƒ API

๋กœ๊ทธ์•„์›ƒ์„ ์ˆ˜ํ–‰ํ•˜๋Š” API.

access, refresh ์ฟ ํ‚ค๋ฅผ ์‚ญ์ œํ•œ๋‹ค.

์š”์ฒญ

POST https://api.itcode.dev/oauth2/api/logout

์‘๋‹ต

{
	"flag": true,
	"title": "success",
	"message": "logout success",
	"body": null
}
# Header
Set-Cookie: access={access JWT}
Set-Cookie: refresh={refresh JWT}
parameter data description
flag boolean ๋™์ž‘ ๊ฒฐ๊ณผ
title String ์ œ๋ชฉ
message String ๋‚ด์šฉ
body null null

Max-Age 0์ธ ์ฟ ํ‚ค๋กœ ๋งŒ๋“ค์–ด Set-Cookie๋กœ ๋ฎ์–ด์”Œ์›Œ ์‚ญ์ œํ•œ๋‹ค.




RevokeAPI

์—ฐ๋™ ํ•ด์ œ API

/oauth2/api/revoke

์—ฐ๋™ ํ•ด์ œ URL API

ํ”Œ๋žซํผ ์—ฐ๋™์„ ํ•ด์ œํ•˜์—ฌ ๊ด€๋ จ ์ •๋ณด์™€ ์ •๋ณด ์ œ๊ณต ๋™์˜ ๋‚ด์—ญ์„ ์ „๋ถ€ ์‚ญ์ œํ•˜๋Š” API.

์ถ”ํ›„ ๋‹ค์‹œ ์„œ๋น„์Šค์— ๋กœ๊ทธ์ธ์„ ์ˆ˜ํ–‰ํ•˜๋ฉด, ์ด์ „ ์ •๋ณด๋“ค์ด ๋ชจ๋‘ ํŒŒ๊ธฐ๋๊ธฐ ๋•Œ๋ฌธ์— ์•ฝ๊ด€ ๋ฐ ์ •๋ณด ์ œ๊ณต ๋™์˜๋ฅผ ๋‹ค์‹œ ์ˆ˜ํ–‰ํ•ด์•ผํ•œ๋‹ค.

ํ”Œ๋žซํผ ์—ฐ๋™ ํ•ด์ œ ํ›„ ๋กœ๊ทธ์•„์›ƒ์„ ์ง„ํ–‰ํ•˜๋ฉฐ, ํ‘œ๋ฉด์ ์ธ ๋™์ž‘์€ ๋กœ๊ทธ์•„์›ƒ ๋™์ž‘๊ณผ ์™„์ „ํžˆ ๋™์ผํ•˜๋‹ค.

์š”์ฒญ

DELETE https://api.itcode.dev/oauth2/api/revoke
Cookie: access={:access};
parameter type data required description
{:access} Cookie String Y ์ธ์ฆ ์ฟ ํ‚ค

์‘๋‹ต

{
	"flag": true,
	"title": "success",
	"message": "logout success",
	"body": null
}
# Header
Set-Cookie: access={access JWT}
Set-Cookie: refresh={refresh JWT}
parameter data description
flag boolean ๋™์ž‘ ๊ฒฐ๊ณผ
title String ์ œ๋ชฉ
message String ๋‚ด์šฉ
body null null



UserInfoAPI

์‚ฌ์šฉ์ž ์ •๋ณด API

/oauth2/api/userinfo

์‚ฌ์šฉ์ž ์ •๋ณด API

Access Token์„ ํ†ตํ•ด ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ์ „๋‹ฌ๋ฐ›๋Š” API.

์ด ๋•Œ ์ „๋‹ฌ๋ฐ›๋Š” ์ •๋ณด๋Š” ์ฒซ ๋กœ๊ทธ์ธ ์‹œ ์ œ๊ณต ๋™์˜ํ•œ ์ •๋ณด๋งŒ์„ ๊ฐ€์ ธ์˜จ๋‹ค.

ํ”Œ๋žซํผ๋งˆ๋‹ค ์ „๋‹ฌํ•ด์ฃผ๋Š” ๋ฐ์ดํ„ฐ์˜ ์Šคํ‚ค๋งˆ์™€ ํ˜•์‹์ด ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์—, ์ธ์ฆ ์„œ๋ฒ„์—์„œ ์ด๋ฅผ ์ ์ ˆํžˆ ๊ฐ€๊ณตํ•˜์—ฌ ์ผ๊ด„๋œ ํ˜•ํƒœ์˜ ์‘๋‹ต์œผ๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

์š”์ฒญ

GET https://api.itcode.dev/oauth2/api/userinfo
Cookie: access={:access};
parameter type data required description
{:access} Cookie String Y ์ธ์ฆ ์ฟ ํ‚ค

์‘๋‹ต

{
	"flag": true,
	"title": "success",
	"message": "user info response success",
	"body": {
		"email": "[email protected]",
		"name": "name",
		"profile": "https://phinf.pstatic.net/contact/PROFILE.png",
		"platform": "naver"
	}
}

์œ„ ์‘๋‹ต์€ ๋„ค์ด๋ฒ„ ์‚ฌ์šฉ์ž ์ •๋ณด ์‘๋‹ต์˜ ์˜ˆ์‹œ๋‹ค.

parameter data description
flag boolean ๋™์ž‘ ๊ฒฐ๊ณผ
title String ์ œ๋ชฉ
message String ๋‚ด์šฉ
body Object ์‚ฌ์šฉ์ž ์ •๋ณด JSON
email String ์ด๋ฉ”์ผ
name String ์ด๋ฆ„
profile String ํ”„๋กœํ•„ ์‚ฌ์ง„ URL
platform String ํ”Œ๋žซํผ
โš ๏ธ **GitHub.com Fallback** โš ๏ธ