4 minute read

๊ธฐํš ์‹œ๋ฆฌ์ฆˆ: Web Authentication

  1. Cookie & Session & JWT
  2. OAuth ๐Ÿ‘ˆ
  3. OpenID Connect(OIDC)
  4. SSO
  5. SAML

์ด ๊ธ€์€ OAuth๋ฅผ ๊ณต๋ถ€ํ•˜๋ฉด์„œ ๊ฐœ์ธ์ ์œผ๋กœ ์ •๋ฆฌํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค. ์ง€์ ๊ณผ ์กฐ์–ธ์€ ์–ธ์ œ๋‚˜ ํ™˜์˜์ž…๋‹ˆ๋‹ค ใ…Žใ…Ž

OAuth 2.0์— ๋Œ€ํ•œ ์ž…๋ฌธ์œผ๋กœ๋Š” ์ƒํ™œ์ฝ”๋”ฉ์˜ WEB2 - OAuth 2.0 ๊ฐ•์ขŒ๋ฅผ ์ถ”์ฒœํ•ฉ๋‹ˆ๋‹ค ๐Ÿ˜Š


OAuth๋Š” โ€œ๊ตฌ๊ธ€๋กœ ๋กœ๊ทธ์ธโ€, โ€œํŽ˜์ด์Šค๋ถ์œผ๋กœ ๋กœ๊ทธ์ธโ€๊ณผ ๊ฐ™์€ ์ธ์ฆ(Authentication)์„ ์ด์šฉํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” ํ”„๋กœํ† ์ฝœ์ด๋‹ค! OAuth๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด, ์™ธ๋ถ€์˜ ์จ๋“œํŒŒํ‹ฐ ์„œ๋น„์Šค์— ๊ฐœ์ธ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜์ง€ ์•Š์œผ๋ฉด์„œ, ๊ทธ๊ณณ์˜ ์„œ๋น„์Šค๋ฅผ ์ด์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์žฅ์ ์ด ์žˆ๋‹ค!!


Motivation.

OAuth๊ฐ€ ํƒ„์ƒํ•˜๊ฒŒ ๋œ ๊ฐ€์žฅ ํฐ ์ด์œ ๋Š” โ€œThird Party Application์— ์•„์ด๋””์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ œ๊ณตํ•˜๊ณ  ์‹ถ์ง€ ์•Š๋‹คโ€์ด๋‹ค. ๋งŒ์•ฝ ์•„์ด๋””์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ, ๋˜๋Š” ๊ฐœ์ธ์ •๋ณด ๋“ฑ์„ ์—ฌ๋Ÿฌ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ž…๋ ฅํ•˜๊ณ , ๊ทธ๊ณณ์˜ DB์— ์ €์žฅํ•œ๋‹ค๋ฉด ํ”ผ์‹ฑ๊ณผ ํ•ดํ‚น์— ๋‘”๊ฐํ•ด์ง€๊ณ  ๋ฌด์—‡๋ณด๋‹ค ํ•ด๋‹น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๋ณด์•ˆ์ ์œผ๋กœ ์•ˆ์ „ํ•˜๋‹ค๋Š” ๋ณด์žฅ์ด ์—†๊ธฐ ๋•Œ๋ฌธ์— ํฐ ์ž ์žฌ์  ์œ„ํ—˜์ด ์žˆ์—ˆ๋‹ค ๐Ÿ˜Ž

์ด๋Ÿฐ ๋ฌธ์ œ ์ƒํ™ฉ์„ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด 2007๋…„, Twitter์˜ ์ฃผ๋„๋กœ OAuth 1.0์ด ํƒ„์ƒํ•œ๋‹ค! ๐Ÿ˜†


OAuth 1.0

Image from here

OAuth 1.0์€ ์œ„์™€ ๊ฐ™์€ ํ”Œ๋กœ์šฐ๋กœ ์ธ์ฆ์„ ์ง„ํ–‰ํ•œ๋‹ค. OAuth 1.0์˜ ํ”Œ๋กœ์šฐ์— ์ฐธ๊ฐ€ํ•˜๋Š” ๊ฐ ์ฃผ์ฒด๋ฅผ ์‚ดํŽด๋ณด๋ฉด,

1. User ๋˜๋Š” Resource Owner

ํŠน์ • ์„œ๋น„์Šค๋ฅผ ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” ์ฃผ์ฒด. ์—ฌ๊ธฐ์„œ๋Š” GitHub์ด ๊ทธ ํŠน์ • ์„œ๋น„์Šค์ด๋‹ค.

2. Consumer ๋˜๋Š” Client

ํŠน์ • ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•˜๋Š” ์ฃผ์ฒด. OAuth ์ œ๊ณต์ž์—๊ฒŒ ์ธ์ฆ๊ณผ ๊ถŒํ•œ์„ ์š”์ฒญํ•œ๋‹ค.

3. Service Provider / OAuth Provider ๋˜๋Š” Resource Server

OAuth ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•˜๋Š” ์ฃผ์ฒด.

๋ฐ‘์ค„๋กœ ํ‘œ์‹œ๋œ ๋ถ€๋ถ„์ด OAuth ๊ณต์‹ ๋ฉ”๋‰ด์–ผ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ์šฉ์–ด๋‹ค.


์žฅ์ .

  • Consumer๊ฐ€ ID/PW ์—†์ด ์ธ์ฆ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Œ.
  • Consumer๊ฐ€ ์ œ๊ณตํ•˜๋Š” API์— ์ œํ•œ์ ์œผ๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ถŒํ•œ ์ œ์–ด๋„ ๊ฐ€๋Šฅ
  • User๊ฐ€ OAuth Provider์˜ ๊ด€๋ฆฌ ํŽ˜์ด์ง€์—์„œ Consumer์˜ ๊ถŒํ•œ์„ ์ทจ์†Œํ•  ์ˆ˜๋„ ์žˆ์Œ.
  • PW๊ฐ€ ๋ณ€๊ฒฝ๋˜์–ด๋„ ์ธ์ฆ ํ† ํฐ(access token)์€ ๊ณ„์† ์œ ํšจํ•จ*

* OAuth 1.0์˜ ์žฅ์ ์ด์ž ๋‹จ์ 

๋‹จ์ .

  • ๊ตฌํ˜„์ด ๋ณต์žกํ•จ.
  • ์›น์—์„  ์ž˜ ์‚ฌ์šฉํ–ˆ์œผ๋‚˜ ๋ชจ๋ฐ”์ผ ํ™˜๊ฒฝ์—์„œ ์ง€์›์ด ๋ถ€์กฑ.
  • ์ธ์ฆ ํ† ํฐ(access token)์ด ๋งŒ๋ฃŒ๋˜์ง€ ์•Š์Œ.
    • OAuth 2.0์—์„œ refresh token์„ ๋„์ž…ํ•ด ํ•ด๊ฒฐํ–ˆ๋‹ค!

OAuth 2.0

OAuth 1.0์˜ ๋‹จ์ ์„ ๋ณด์™„ํ•ด 2012๋…„, OAuth 2.0์ด ๊ณต๊ฐœ๋œ๋‹ค. OAuth 2.0์€ ๊ธฐ๋Šฅ์„ ๋‹จ์ˆœํ™”ํ•˜๊ณ , ํ™•์žฅ์„ฑ(scalability)์„ ๋” ๊ฐ•ํ™”ํ–ˆ๋‹ค๊ณ  ํ•œ๋‹ค.

OAuth 1.0์€ ๊ณต๊ฐœ๋œ ์ดํ›„์— ํ‘œ์ค€์œผ๋กœ ์ธ์ • ๋ฐ›์•˜์ง€๋งŒ, OAuth 2.0์€ ์ฒ˜์Œ๋ถ€ํ„ฐ ํ‘œ์ค€์„ ์—ผ๋‘ํ•ด๋‘๊ณ  ๊ฐœ๋ฐœํ–ˆ๋‹ค๊ณ  ํ•œ๋‹ค. OAuth 2.0๋ถ€ํ„ฐ https๊ฐ€ ํ•„์ˆ˜๊ฐ€ ๋˜์–ด ํ† ํฐ ์ „์†ก์— ๋Œ€ํ•œ ๋ณด์•ˆ์ด ๊ฐ•ํ™”๋˜์—ˆ๋‹ค.

ํŽ˜์ด์ฝ”์˜ ์‹ค์ œ OAuth 2.0์˜ ํ”„๋กœ์„ธ์Šค๋‹ค. ์ƒํ™œ์ฝ”๋”ฉ์˜ WEB2 - OAuth 2.0 ๊ฐ•์ขŒ์—์„œ ์„ค๋ช…ํ•˜๋Š” OAuth ํ”Œ๋กœ์šฐ๋ฅผ ์ดํ•ดํ–ˆ๋‹ค๋ฉด, ์œ„์˜ ๊ณผ์ •๋„ ์‰ฝ๊ฒŒ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ์ด๋‹ค ๐Ÿ˜Ž

Access Token & Refresh Token

OAuth 2.0์€ access_token, refresh_token ๋‘ ๊ฐ€์ง€ ํ† ํฐ์„ ์‚ฌ์šฉํ•ด ๋™์ž‘ํ•œ๋‹ค.

Access Token.

Client๊ฐ€ Resource Server์— ์œ ์ €์˜ ๋ฆฌ์†Œ์Šค์— ์ ‘๊ทผํ•  ๋•Œ, ๊ถŒํ•œ์„ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•œ ์šฉ๋„๋กœ ์‚ฌ์šฉ๋˜๋Š” ํ† ํฐ์ด๋‹ค. OAuth 2.0์˜ 4๊ฐ€์ง€ ๊ถŒํ•œ ์š”์ฒญ ๋ฐฉ์‹ ๋ชจ๋‘ ์š”์ฒญ ์ ˆ์ฐจ๋ฅผ ์ •์ƒ์ ์œผ๋กœ ๋งˆ์น˜๋ฉด ์ด access_token์„ ๋ฐœ๊ธ‰๋ฐ›๊ฒŒ ๋œ๋‹ค. Client๋Š” Resource Server์˜ API๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๊ณ  ํ•  ๋•Œ, ๋ฐ˜๋“œ์‹œ ์ด access_token์„ ํ—ค๋”๋‚˜ URI Parameter์— ์ฒจ๋ถ€ํ•ด์•ผ ํ•œ๋‹ค.

Refresh Token.

access_token์€ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์‹œ๊ฐ„์ด ์ œํ•œ๋˜์–ด ์žˆ๋‹ค. ๋งŒ์•ฝ access_token์ด ๋งŒ๋ฃŒ๋˜์–ด Client๊ฐ€ Resource Server์˜ API๋ฅผ ์ •์ƒ์ ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๊ฒŒ ๋œ๋‹ค๋ฉด, Client๋Š” ์ด refresh_token์„ Resource Server์— ๋ณด๋‚ด access_token์˜ ๊ฐฑ์‹ ์„ ์š”์ฒญํ•œ๋‹ค. Server๋Š” refresh_token์ด ์œ ํšจํ•˜๋‹ค๋ฉด, ์ƒˆ๋กœ์šด access_token์„ ๋ฐœ๊ธ‰ํ•ด Client์—๊ฒŒ ์ „๋‹ฌํ•œ๋‹ค.

Authentication Methods

OAuth 2.0์—์„œ๋Š” 4๊ฐ€์ง€ ์ •๋ณด์˜ ์ธ์ฆ ๋ฐฉ์‹์„ ์ง€์›ํ•œ๋‹ค. ๊ฐ๊ฐ์€ access_token์„ ์–ป๋Š” ๋ฐฉ์‹์— ๋”ฐ๋ผ ๋ถ„๋ฅ˜๋œ๋‹ค.

  • Authorization Code Grant ๐Ÿ”ฅ
  • Implicit Grant
  • Resource Owner Password Credentials Grant
  • Client Credentials Grant

์ƒํ™œ์ฝ”๋”ฉ ๊ฐ•์ขŒ์—์„œ ๋‹ค๋ฃฌ ๋ฐฉ์‹์ด โ€œAuthorization Code Grantโ€ ๋ฐฉ์‹์ด๋‹ค. ํŽ˜์ด์ฝ”์˜ OAuth 2.0 ํ”Œ๋กœ์šฐ ์—ญ์‹œ โ€œAuthorization Code Grantโ€ ๋ฐฉ์‹์„ ๋”ฐ๋ฅธ๋‹ค.


๋งบ์Œ๋ง

OAuth 2.0๋ฅผ ํ™•์žฅํ•œ ํ”„๋กœํ† ์ฝœ์ด ๋ฐ”๋กœ OpenID Connect๋ผ๊ณ  ํ•œ๋‹ค. ๋‹ค์Œ ํฌ์ŠคํŠธ์—์„œ๋Š” ์ด OpenID Connect์— ๋Œ€ํ•ด ์‚ดํŽด๋ณด๊ฒ ๋‹ค ๐Ÿ˜Ž

OpenID Connect(OIDC)


Reference