๐Ÿ” OAuth 2.0

๊ฐ€์˜ยท2021๋…„ 8์›” 3์ผ
0

์„ธ ์ข…๋ฅ˜์˜ ์ฃผ์ฒด

  1. client ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ kyrics
  2. ์‚ฌ์šฉ์ž(=resource owner) ์œค๊ฐ€์˜
  3. API ์„œ๋ฒ„ youtube

๊ณผ์ •์— ์ต์ˆ™ํ•ด์ง€๊ธฐ

  1. ์šฐ์„  ์‚ฌ์šฉ์ž๊ฐ€ ์šฐ๋ฆฌ ์„œ๋ฒ„์—๊ฒŒ ์ ‘์†์„ ํ•œ๋‹ค.

  2. ์„œ๋ฒ„(resource server์˜ client)์˜ ํ™”๋ฉด์— ์ธ์ฆ์š”์ฒญํ™”๋ฉด์ด ๋‚˜์˜จ๋‹ค.

  3. ์‚ฌ์šฉ์ž๊ฐ€ ๋™์˜๋ฅผ ํ•˜๋ฉด resource server๋กœ ์ ‘์†ํ•˜๊ฒŒ ๋œ๋‹ค.

    ๐Ÿ‘‰๐Ÿป "Redirect to Google's OAuth 2.0 server

  4. scope list๋ฅผ ๋ณด์—ฌ์ฃผ๊ณ  resource server๊ฐ€ resource owner์—๊ฒŒ accept๋ฅผ ์š”์ฒญํ•œ๋‹ค.

    1. authorize code๋ฅผ ๋ฐœ๊ธ‰ํ•œ๋‹ค.
    2. ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์ „๋‹ฌํ•œ๋‹ค.
  5. ํด๋ผ์ด์–ธํŠธ๊ฐ€code, client id, client secretkey๋ฅผ resource server์—๊ฒŒ ๋‹ค์‹œ ๋ณด๋‚ธ๋‹ค.

  6. ๋ฌด๊ฒฐ์„ฑ/๊ถŒํ•œ ํ™•์ธ ํ›„์—

  7. access token์„ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ฐœ๊ธ‰ํ•œ๋‹ค.

  8. ํด๋ผ์ด์–ธํŠธ๋Š” ๋ฐœ๊ธ‰๋ฐ›์€ access token์œผ๋กœ API๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

redirect sample url

์•„๋ž˜ ์ƒ˜ํ”Œ URL์€ ์‚ฌ์šฉ์ž๋ฅผ ๋Œ€์‹ ํ•˜์—ฌ YouTube Data API ์š”์ฒญ์„ ์ œ์ถœํ•˜๊ธฐ ์œ„ํ•ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋Œ€ํ•œ ๊ถŒํ•œ ๋ถ€์—ฌ๋ฅผ ์š”์ฒญํ•˜๋Š” Google ์ธ์ฆ ์„œ๋ฒ„ URI๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

https://accounts.google.com/o/oauth2/auth?
  client_id=1084945748469-eg34imk572gdhu83gj5p0an9fut6urp5.apps.googleusercontent.com&
  redirect_uri=http%3A%2F%2Flocalhost%2Foauth2callback&
  scope=https://www.googleapis.com/auth/youtube&
  response_type=code&
  access_type=offline

scope : ์–ด๋–ค ๊ถŒํ•œ์„ ์š”์ฒญํ•˜๋Š”์ง€์˜ ๋ฒ”์œ„๋ฅผ ๋ช…์‹œ

์šฐ๋ฆฌ์˜ ๊ฒฝ์šฐ๋Š” https://developers.google.com/youtube/v3/docs/captions/download ์—ฌ๊ธฐ์—์„œ authorization scope ๋“ค ์ค‘ ํ•„์š”ํ•œ ๊ฒƒ๋“ค์„ ์ŠคํŽ˜์ด์Šค๋ฅผ ๊ตฌ๋ถ„์ž๋กœ ๋„ฃ์–ด์ฃผ๋ฉด ๋œ๋‹ค. โ‡’ ๊ทผ๋ฐ ์ด๊ฑธ url์ธ์ฝ”๋”ฉํ•ด์„œ ๋„ฃ์–ด์ค˜์•ผํ•จ์š”

access_type : ์˜คํ”„๋ผ์ธ ์˜จ๋ผ์ธ, ์˜คํ”„๋ผ์ธ์€ refresh token๊นŒ์ง€ ๋ฐœ๊ธ‰. access token๋งŒ๋ฃŒ์‹œ refresh token ์‚ฌ์šฉํ•ด์„œ access token ์ƒˆ๋กœ ๋ฐœ๊ธ‰ ๊ฐ€๋Šฅ

redirect url : access token์„ ๋ฐ›์œผ๋ ค๊ณ  ํ•˜๋Š” ๊ณณ(client)์˜ url์ด๋‹ค. resource server๋Š” ์ธ์ฆ ์ ˆ์ฐจ ํ›„ ์ด๊ณณ์œผ๋กœ access token์„ ๋ณด๋‚ธ๋‹ค.

์ด ์™ธ ํŒŒ๋ผ๋ฏธํ„ฐ ์ƒ์„ธ ์ •๋ณด ๐Ÿ‘‰๐Ÿป here!

0๊ฐœ์˜ ๋Œ“๊ธ€