Bibi's DevLog ๐Ÿค“๐ŸŽ

GitHub OAuth - Scopes for OAuth Apps ๋ณธ๋ฌธ

ํ”„๋กœ๊ทธ๋ž˜๋ฐ/Git & GIthub ๊นƒ๊ณผ ๊นƒํ—ˆ๋ธŒ

GitHub OAuth - Scopes for OAuth Apps

๋น„๋น„ bibi 2022. 6. 15. 00:06

https://docs.github.com/en/enterprise-server@2.21/developers/apps/building-oauth-apps/scopes-for-oauth-apps

 

GitHub OAuth - Scopes for OAuth Apps

  • Scope(๋ฒ”์œ„)๋Š” ๋‹น์‹ ์ด ์ •ํ™•ํžˆ ์–ด๋–ค ์ข…๋ฅ˜์˜ ์ ‘๊ทผ์„ ํ•„์š”๋กœ ํ•˜๋Š”์ง€๋ฅผ ๊ตฌ์ฒดํ™”ํ•ด์ค€๋‹ค.
  • scope๋Š” OAuth ํ† ํฐ์˜ ์ ‘๊ทผ์„ ์ œํ•œํ•œ๋‹ค.
  • ์‚ฌ์šฉ์ž๊ฐ€ ๊ฐ€์ง„ ๊ถŒํ•œ ์ด์ƒ์˜ ์–ด๋–ค ์ ‘๊ทผ๋„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.

๊นƒํ—™ OAuth ์•ฑ์„ ์„ค์ •ํ•  ๋•Œ, ์š”์ฒญ๋˜๋Š” scope๋“ค์ด ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ง„๋‹ค.

scope ํ™•์ธํ•˜๊ธฐ

๋‚ด๊ฐ€ ์–ด๋–ค OAuth scope๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ , API ๋™์ž‘์ด ์–ด๋–ค scope๋ฅผ ์Šน์ธํ•˜๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ํ—ค๋”๋ฅผ ๋ณด๋ฉด ๋œ๋‹ค.

$ curl -H "Authorization: token OAUTH-TOKEN" http(s)://[hostname]/api/v3/users/codertocat -I
HTTP/2 200
X-OAuth-Scopes: repo, user
X-Accepted-OAuth-Scopes: user
  • X-OAuth-Scopes : ๋‚ด ํ† ํฐ์ด ์ธ์ฆ๋ฐ›์€ scope๋“ค์˜ ๋ฆฌ์ŠคํŠธ.
  • X-Accepted-OAuth-Scopes : (API์˜)๋™์ž‘์ด ํ™•์ธํ•˜๋Š” scope๋“ค์˜ ๋ฆฌ์ŠคํŠธ.

์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ scope๋“ค

  • (no scope) (scope ์—†์Œ) : ๊ณต๊ฐœ์ ์ธ ์ •๋ณด์— ๋Œ€ํ•œ ์ฝ๊ธฐ ์ „์šฉ ๊ถŒํ•œ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค. (์‚ฌ์šฉ์ž ํ”„๋กœํ•„ ์ •๋ณด, ์ €์žฅ์†Œ ์ •๋ณด, gist๋ฅผ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค)
  • site_admin : GitHub Enterprise Server Administration API endpoints์— ๋Œ€ํ•œ ์‚ฌ์ดํŠธ ๊ด€๋ฆฌ์ž ์ ‘๊ทผ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค.
  • repo : private ์ €์žฅ์†Œ๋ฅผ ํฌํ•จํ•œ ๋ชจ๋“  ์ €์žฅ์†Œ ์ ‘๊ทผ ๊ถŒํ•œ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์ฝ”๋“œ์— ๋Œ€ํ•œ ์ฝ๊ธฐ/์“ฐ๊ธฐ ์ ‘๊ทผ, ์ปค๋ฐ‹ ์ƒํƒœ, ์ €์žฅ์†Œ์™€ ์กฐ์ง(organization) ํ”„๋กœ์ ํŠธ, invitation, collaborators, team memberships ์ถ”๊ฐ€ํ•˜๊ธฐ, ๋ฐฐํฌ ์ƒํƒœ, ์ €์žฅ์†Œ์™€ ์กฐ์ง์— ๋Œ€ํ•œ ์ €์žฅ์†Œ ์›นํ›…์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ์‚ฌ์šฉ์ž ํ”„๋กœ์ ํŠธ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๋Šฅ๋ ฅ๋„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค.
    • repo:status : public ๋ฐ private ์ €์žฅ์†Œ์˜ ์ปค๋ฐ‹ ์ƒํƒœ์— ๋Œ€ํ•œ ์ฝ๊ธฐ/์“ฐ๊ธฐ ์ ‘๊ทผ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค. ์ด scope๋Š” ์ฝ”๋“œ์— ๋Œ€ํ•œ ์ ‘๊ทผ ์Šน์ธ ์—†์ด, ์˜ค์ง ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž ๋˜๋Š” ์„œ๋น„์Šค๊ฐ€ private ์ €์žฅ์†Œ์˜ ์ปค๋ฐ‹ ์ƒํƒœ์— ๋Œ€ํ•ด ์ ‘๊ทผํ•˜๋„๋ก ํ•  ๋•Œ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
    • repo_deployment : public ๋ฐ private ์ €์žฅ์†Œ์˜ ๋ฐฐํฌ ์ƒํƒœ์— ๋Œ€ํ•œ ์ ‘๊ทผ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค. ์ด scope๋Š” ์ฝ”๋“œ์— ๋Œ€ํ•œ ์ ‘๊ทผ ์Šน์ธ ์—†์ด, ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž ๋˜๋Š” ์„œ๋น„์Šค๊ฐ€ ๋ฐฐํฌ ์ƒํƒœ ์— ์ ‘๊ทผํ•˜๋„๋ก ํ•  ๋•Œ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
    • public_repo : ์ ‘๊ทผ ๊ถŒํ•œ์„ public ์ €์žฅ์†Œ๋กœ ์ œํ•œํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” public ์ €์žฅ์†Œ ๋ฐ ์กฐ์ง์— ๋Œ€ํ•œ ์ฝ”๋“œ ์ฝ๊ธฐ/์“ฐ๊ธฐ ์ ‘๊ทผ, ์ปค๋ฐ‹ ์ƒํƒœ, ์ €์žฅ์†Œ ํ”„๋กœ์ ํŠธ, collaborators, ๋ฐฐํฌ ์ƒํƒœ๋ฅผ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ public ์ €์žฅ์†Œ๋ฅผ starํ•  ๋•Œ๋„ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
    • repo:invite : ์ €์žฅ์†Œ์— collaborator ์ดˆ๋Œ€์— ๋Œ€ํ•œ ์ˆ˜๋ฝ/๊ฑฐ์ ˆ ๊ถŒํ•œ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค. ์ด scope๋Š” ์ฝ”๋“œ์— ๋Œ€ํ•œ ์ ‘๊ทผ ์Šน์ธ ์—†์ด, ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž ๋˜๋Š” ์„œ๋น„์Šค๊ฐ€ ์ดˆ๋Œ€ ๊ถŒํ•œ์— ์ ‘๊ทผํ•˜๋„๋ก ํ•  ๋•Œ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
  • admin:repo_hook : public ๋ฐ private ์ €์žฅ์†Œ์˜ ์ €์žฅ์†Œ ํ›…(repository hook)์— ๋Œ€ํ•œ ์ฝ๊ธฐ, ์“ฐ๊ธฐ, ping, ์‚ญ์ œ ์ ‘๊ทผ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค. repo์™€ public_repo scope๋Š” ์ €์žฅ์†Œ ํ›…์„ ํฌํ•จํ•œ ๋ชจ๋“  ์ €์žฅ์†Œ ์ ‘๊ทผ ๊ถŒํ•œ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค. ์ €์žฅ์†Œ ํ›…์— ๋Œ€ํ•ด์„œ๋งŒ ์ ‘๊ทผ์„ ์ œํ•œํ•˜๊ณ  ์‹ถ์„ ๋•Œ admin:repo_hook์„ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.
    • write:repo_hook : public ๋ฐ private ์ €์žฅ์†Œ์˜ ์ €์žฅ์†Œ ํ›…(repository hook)์— ๋Œ€ํ•œ ์ฝ๊ธฐ, ์“ฐ๊ธฐ, ping ์ ‘๊ทผ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค.
    • read:repo_hook : public ๋ฐ private ์ €์žฅ์†Œ์˜ ์ €์žฅ์†Œ ํ›…(repository hook)์— ๋Œ€ํ•œ ์ฝ๊ธฐ, ping ์ ‘๊ทผ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค.
  • admin:org : ์กฐ์ง(organization)๊ณผ ๊ทธ ํŒ€, ํ”„๋กœ์ ํŠธ, ๋ฉค๋ฒ„์‹ญ์— ๋Œ€ํ•œ ๋ชจ๋“  ์ ‘๊ทผ ๊ถŒํ•œ์„ ๊ฐ–์Šต๋‹ˆ๋‹ค.
    • write:org : ์กฐ์ง ๋ฉค๋ฒ„์‹ญ, ์กฐ์ง ํ”„๋กœ์ ํŠธ, ํŒ€ ๋ฉค๋ฒ„์‹ญ์— ๋Œ€ํ•œ ์ฝ๊ธฐ/์“ฐ๊ธฐ ์ ‘๊ทผ์ž…๋‹ˆ๋‹ค.
    • read:org : ์กฐ์ง ๋ฉค๋ฒ„์‹ญ, ์กฐ์ง ํ”„๋กœ์ ํŠธ, ํŒ€ ๋ฉค๋ฒ„์‹ญ์— ๋Œ€ํ•œ ์ฝ๊ธฐ ์ „์šฉ ์ ‘๊ทผ์ž…๋‹ˆ๋‹ค.
  • admin:public_key : ๊ณต๊ฐœ ํ‚ค (public key)์— ๋Œ€ํ•œ ๋ชจ๋“  ์ ‘๊ทผ ๊ถŒํ•œ์„ ๊ฐ–์Šต๋‹ˆ๋‹ค.
    • write:public_key : ๊ณต๊ฐœ ํ‚ค (public key)์— ๋Œ€ํ•œ ์ƒ์„ฑ, ๋ฆฌ์ŠคํŠธ, ์ƒ์„ธ๋ณด๊ธฐ ์ ‘๊ทผ ๊ถŒํ•œ์„ ๊ฐ–์Šต๋‹ˆ๋‹ค.
    • read:public_key : ๊ณต๊ฐœ ํ‚ค (public key)์— ๋Œ€ํ•œ ๋ฆฌ์ŠคํŠธ, ์ƒ์„ธ๋ณด๊ธฐ ์ ‘๊ทผ ๊ถŒํ•œ์„ ๊ฐ–์Šต๋‹ˆ๋‹ค.
  • admin:org_hook : ์กฐ์ง ํ›…(organization hooks)์— ๋Œ€ํ•œ ์ฝ๊ธฐ, ์“ฐ๊ธฐ, ping, ์‚ญ์ œ ์ ‘๊ทผ ๊ถŒํ•œ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค. (์ฐธ๊ณ  : OAuth ํ† ํฐ์€ OAuth ์•ฑ์— ์˜ํ•ด ์ƒ์„ฑ๋œ ์กฐ์ง ํ›… ๋™์ž‘์— ๋Œ€ํ•ด์„œ๋งŒ ์‹คํ–‰ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. Personal access token์€ ์‚ฌ์šฉ์ž์— ์˜ํ•ด ์ƒ์„ฑ๋œ ์กฐ์ง ํ›… ๋™์ž‘์„ ์‹คํ–‰ํ•  ๋•Œ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.)
  • gist : gist์— ๋Œ€ํ•œ ์“ฐ๊ธฐ ์ ‘๊ทผ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค.
  • notifications : ๋‹ค์Œ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค - ์‚ฌ์šฉ์ž์˜ notification์— ๋Œ€ํ•œ ์ฝ๊ธฐ ์ ‘๊ทผ, ์“ฐ๋ ˆ๋“œ์— ๋Œ€ํ•ด ์ฝ๊ธฐ ํ‘œ์‹œ๋ฅผ ํ•˜๋Š” ์ ‘๊ทผ, ์ €์žฅ์†Œ ์ ‘๊ทผ์„ ๋ณด๊ธฐ/๋ณด์ง€ ์•Š๊ธฐ, ๊ทธ๋ฆฌ๊ณ  ์“ฐ๋ ˆ๋“œ ๊ตฌ๋…์— ๋Œ€ํ•œ ์ฝ๊ธฐ/์“ฐ๊ธฐ/์‚ญ์ œ ์ ‘๊ทผ.
  • user : ํ”„๋กœํ•„ ์ •๋ณด์— ๋Œ€ํ•œ ์ฝ๊ธฐ/์“ฐ๊ธฐ ์ ‘๊ทผ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค. ์ด scope๊ฐ€ user:email๊ณผ user:follow๋ฅผ ํฌํ•จํ•จ์— ์œ ์˜ํ•˜์‹ญ์‹œ์˜ค.
    • read:user : ์‚ฌ์šฉ์ž์˜ ํ”„๋กœํ•„ ์ •๋ณด ์ฝ๊ธฐ ์ ‘๊ทผ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค.
    • user:email : ์‚ฌ์šฉ์ž์˜ ์ด๋ฉ”์ผ ์ฃผ์†Œ ์ฝ๊ธฐ ์ ‘๊ทผ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค.
    • user:follow : ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž์— ๋Œ€ํ•œ follow / unfollow ์ ‘๊ทผ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค.
  • delete_repo : ๊ด€๋ฆฌ ๊ฐ€๋Šฅํ•œ ์ €์žฅ์†Œ์˜ ์‚ญ์ œ ์ ‘๊ทผ์„ ์Šน์ธํ•ฉ๋‹ˆ๋‹ค.
  • write:discussion : team discussion์— ๋Œ€ํ•œ ์ฝ๊ธฐ/์“ฐ๊ธฐ ์ ‘๊ทผ์„ ํ—ˆ์šฉํ•ฉ๋‹ˆ๋‹ค.
    • read:discussion : team discussion์— ๋Œ€ํ•œ ์ฝ๊ธฐ ์ ‘๊ทผ์„ ํ—ˆ์šฉํ•ฉ๋‹ˆ๋‹ค.
  • admin:gpg_key : GPG ํ‚ค์— ๋Œ€ํ•œ ์™„์ „ํ•œ ๊ด€๋ฆฌ ๊ถŒํ•œ.
    • write:gpg_key : GPG ํ‚ค์— ๋Œ€ํ•œ ์ƒ์„ฑ, ๋ฆฌ์ŠคํŠธ, ์ƒ์„ธ๋ณด๊ธฐ ๊ถŒํ•œ.
    • read:gpg_key : GPG ํ‚ค์— ๋Œ€ํ•œ ๋ฆฌ์ŠคํŠธ, ์ƒ์„ธ๋ณด๊ธฐ ๊ถŒํ•œ.

์ฐธ๊ณ 

๋‹น์‹ ์˜ OAuth ์•ฑ์€ ์ฒซ ๋ฆฌ๋‹ค์ด๋ ‰์…˜์—์„œ scope๋ฅผ ์š”์ฒญํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. %20์„ ๊ณต๋ฐฑ์œผ๋กœ ํ•˜์—ฌ ์—ฌ๋Ÿฌ ๊ฐœ์˜ scope๋ฅผ ๋ช…์‹œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

https://github.com/login/oauth/authorize?
  client_id=...&
  scope=user%20repo_deployment

์š”์ฒญ๋œ scope์™€ ์Šน์ธ๋œ scope

scope ํŠน์„ฑ์€ ํ† ํฐ์— ๋Œ€ํ•ด ์‚ฌ์šฉ์ž์— ์˜ํ•ด ์Šน์ธ๋œ ๋ฒ”์œ„๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ, ์ด ๋ฒ”์œ„๋Š” ๋‹น์‹ ์ด ์š”์ฒญํ•œ ๊ฒƒ๊ณผ ๋™์ผํ•ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ, ์‚ฌ์šฉ์ž๋Š” ๊ทธ๋“ค์˜ scope๋ฅผ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋‹น์‹ ์˜ ์•ฑ์ด ๋‹น์‹ ์ด ์ฒ˜์Œ ์š”์ฒญํ•œ ๊ฒƒ ๋ณด๋‹ค ๋” ์ ์€ ์ ‘๊ทผ๊ถŒํ•œ์„ ๊ฐ–๋„๋ก ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ, ์‚ฌ์šฉ์ž๋Š” OAuth ํ๋ฆ„์ด ์™„๋ฃŒ๋œ ํ›„์— ํ† ํฐ scope๋ฅผ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹น์‹ ์€ ์ด ๊ฐ€๋Šฅ์„ฑ์— ๋Œ€ํ•ด ์œ ์˜ํ•˜๋ฉฐ ๋‹น์‹ ์˜ ์•ฑ์˜ ๋™์ž‘์„ ์ ์ ˆํžˆ ์กฐ์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋‹น์‹ ์ด ์ฒ˜์Œ ์š”์ฒญํ•œ ๊ฒƒ๋ณด๋‹ค ์ ์€ ์ ‘๊ทผ๊ถŒํ•œ์„ ์Šน์ธ๋ฐ›๋„๋ก ์‚ฌ์šฉ์ž๊ฐ€ ์„ ํƒํ–ˆ์„ ๋•Œ์˜ ์—๋Ÿฌ ์ผ€์ด์Šค๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒƒ์€ ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์•ฑ์€ ์‚ฌ์šฉ์ž์—๊ฒŒ ๊ฒฝ๊ณ ํ•˜๊ฑฐ๋‚˜ ์•ˆ๋‚ด๋ฅผ ํ•จ์œผ๋กœ์จ ๊ทธ๋“ค์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์ด ์ค„์–ด๋“ค๊ฑฐ๋‚˜ ์–ด๋–ค ๋™์ž‘์„ ์‹คํ–‰ํ•  ์ˆ˜ ์—†์Œ์„ ์•Œ๋ฆด ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋˜ํ•œ, ์•ฑ์€ ์‚ฌ์šฉ์ž์—๊ฒŒ ์ถ”๊ฐ€์ ์ธ ์Šน์ธ์„ ๋‹ค์‹œ ๋ฐ›๊ธฐ ์œ„ํ•ด OAuth ํ๋ฆ„์œผ๋กœ ๋˜๋Œ์•„๊ฐ€๋„๋ก ์‚ฌ์šฉ์ž๋ฅผ ๋ณด๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์‚ฌ์šฉ์ž๋Š” ์–ธ์ œ๋‚˜ ๊ฑฐ์ ˆํ•  ์ˆ˜ ์žˆ์Œ์„ ์žŠ์ง€ ๋งˆ์‹ญ์‹œ์˜ค.

Basics of Authentication guide๋ฅผ ํ™•์ธํ•˜์‹ญ์‹œ์˜ค. ์ด ๊ฐ€์ด๋“œ๋Š” ์ˆ˜์ • ๊ฐ€๋Šฅํ•œ ํ† ํฐ scope๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ํŒ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

์ •๊ทœํ™”๋œ scope

์—ฌ๋Ÿฌ scope๋“ค์„ ์š”์ฒญํ•  ๋•Œ, ํ† ํฐ์€ scope์˜ ์ •๊ทœํ™”๋œ ๋ฆฌ์ŠคํŠธ๋กœ ์ €์žฅ๋˜๋ฉฐ, ์š”์ฒญํ•œ ๋‹ค๋ฅธ scope์—์„œ ์ด๋ฏธ ํฌํ•จํ•˜๋Š” scope๋Š” ์•”๋ฌต์ ์œผ๋กœ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, user,gist,user:email ์„ ์š”์ฒญํ•˜๋Š” ๊ฒƒ์€ ํ† ํฐ์— user์™€ gist scope๋งŒ์„ ๋‚จ๊ธธ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์™œ๋ƒํ•˜๋ฉด user scope์— user:emailscope์˜ ์ ‘๊ทผ์ด ์Šน์ธ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.