{"id":27255458,"url":"https://github.com/kyungjunnoh/springboot-github-oauth2","last_synced_at":"2026-05-07T01:32:24.396Z","repository":{"id":103583302,"uuid":"449029857","full_name":"KyungJunNoh/springboot-github-Oauth2","owner":"KyungJunNoh","description":"[2022년 01월] Puzzle 팀 프로젝트를 진행하면서 Oauth2 를 연동했던 과정을 기록한 레포지토리","archived":false,"fork":false,"pushed_at":"2022-01-17T20:11:08.000Z","size":771,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-02T20:42:50.948Z","etag":null,"topics":["github","oauth2-server","springboot"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KyungJunNoh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-01-17T19:52:55.000Z","updated_at":"2024-03-10T11:36:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"4130bacb-7470-4ff9-aa30-1963f34b30dd","html_url":"https://github.com/KyungJunNoh/springboot-github-Oauth2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/KyungJunNoh/springboot-github-Oauth2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyungJunNoh%2Fspringboot-github-Oauth2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyungJunNoh%2Fspringboot-github-Oauth2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyungJunNoh%2Fspringboot-github-Oauth2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyungJunNoh%2Fspringboot-github-Oauth2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KyungJunNoh","download_url":"https://codeload.github.com/KyungJunNoh/springboot-github-Oauth2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyungJunNoh%2Fspringboot-github-Oauth2/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266026162,"owners_count":23866030,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["github","oauth2-server","springboot"],"created_at":"2025-04-11T02:19:46.813Z","updated_at":"2026-05-07T01:32:19.355Z","avatar_url":"https://github.com/KyungJunNoh.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 코멘트\n- [Puzzle 서비스](https://github.com/Frame-in-Puzzle) 에서 Oauth 를 사용하기 위해 공부했습니다.\n- Google, Kakao, Naver Oauth는 구현 해본 결과 Gitub와 비슷하여 제외 했습니다.\n- 이 레포지토리는 Github Oauth에 중점을 맞춘 레포지토리입니다.\n- [김준서님](https://velog.io/@max9106) Oauth 할때, 평소 자료 찾아볼 때 정말 많은 도움이 됐습니다. 감사합니다 !!\n- 이 레포지토리를 보시는 분들 모두 [김준서님 Velog](https://velog.io/@max9106) 에서 많은 지식 얻어가세요 !! \n\n# Oauth 로직\n1. 우선 프론트 페이지 에서 https://github.com/login/oauth/authorize?client_id=ccd48be96c643940df44\u0026scope=id,name,email,avatar_url 로 요청을 보낸다.\n   위 링크는 깃허브 Oauth 로그인 폼 페이지 이며 중간에 client_id 에 따라서 어떤 개발자가 만든 Oauth 로그인 폼 페이지 인지 달라진다.\n   위 링크안에서 로그인을 하면 깃허브에서 해당 유저의 정보와 관련된 매 요청마다 다른 `Authorization code` 를 QueryString 으로 발급해준다.\n`http://localhost:8080/redirect/oauth?code=8ffa2a38c846dfb1bb21`\n-\u003e 여기서 code = ‘이부분’ 이 `Authorizationg code` 이다.\n\n\n2. 발급받은 프론트는 백엔드에게 `Authorization code`를\n   `http://localhost:8080/login/oauth/github?code=8ffa2a38c846dfb1bb21`\n   이런식으로 넘겨준다.\n\n\n3. 프론트에게 `Authorization code` 를 받은 백엔드는 Spring의 WebClient라는 모듈을 사용하여 Github의 Authorization Server 에 `Authorization code` 를 넘겨주어(요청하여)  Resource Server 에 해당되는 AccessToken을 보냈을때 해당되는 유저의 정보를 가져올 수 있게 해주는 인증 역할을 하는 AccessToken을 발급해준다.\n\n```\n여기서잠깐, WebClient란?\n간단히 설명하자면 Spring 어플리케이션이 다른 곳으로 HTTP request를 보낼 때 사용하는 모듈이다.\n\n우리가 만드는 Oauth 로직은 spring 서버에서 Gituhb Oauth Server 에 access token 이나, 유저 정보를 얻어오기 위한 요청을 보낼때 사용된다.\n```\n\n4. Authorization Server 에서 받은 AccessToken 을 유저의 정보(자원)를 담아두고 있는 Resource Server에 보내주어 AccessToken 에 해당하는 유저의 정보(자원) 을 우리 Spring Server에 보내준다.\n\n\n5. Spring Server 에서는 받은 정보를 이용하여 DB 에 정보를 저장한다.\n   이때, saveOrUpdate라는 메소드(저장하거나 혹은 업데이트) 를 사용하는데\n   이 메소드는 매 요청마다 update를 한다.\n   (그 이유는 깃허브유저가 정보를 변경했을 수도 있기 때문이다.)\n\n\n6. 마지막으로 각종정보를 담은 LoginResponse (dto) 를 사용하여 프론트에게 유저 정보를 보내준다.\n\n### 용어 정리\n* Resource Owner: 말 그대로 사용자라고 생각하면 된다. 사람이 될 수도 있고, Application 자체가 될 수도 있다.(ex. 나)\n* Client Application: 사용자가 사용하는 서비스 애플리케이션. 서버, 데스크톱 등 어떤 기기든 될 수 있다.(ex. velog)\n* Resource Server: OAuth를 통해 인증, 인가를 제공해주는 서버. 자원 서버. 자원(이름, 이메일, 프로필 사진 등)을 제공해준다.(ex. github, naver, kakao, google)\n* Authorization Server: OAuth를 통해 인증, 인가를 제공해주는 서버. 인증 서버. 토큰을 발급해준다.(ex. github, naver, kakao, google)\n\n\u003cimg src=\"img/logic.png\"\u003e\n\n\n### Reference By\n\u003e 정말 감사합니다.   \n\u003e + https://velog.io/@max9106/OAuth\n\u003e + 여러 개발자분들의 블로그","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyungjunnoh%2Fspringboot-github-oauth2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkyungjunnoh%2Fspringboot-github-oauth2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyungjunnoh%2Fspringboot-github-oauth2/lists"}