[Spring] Spring에서 깃허브 OAuth 로그인하기

2023. 9. 1. 19:02·Framework/SpringBoot

OAuth 앱 등록하기

깃허브에서 Setting > Developer Setting > OAuth Apps > Register a new application 으로 이동하여 OAuth 로그인을 할 앱을 등록해줍니다.

저는 현재 서버를 배포하지 않고 로컬에서 작업하고 있기 때문에 Hompage URL은 http://localhost:8080으로 해줬습니다.

 

Authorization callback URL에는 로그인 후 돌아갈 즉 redirect url을 입력해주세요

 

토큰 생성하기

Register application을 누르고 바로 다음 화면에서 Generate a new client secret을 클릭하면 토큰이 발급됩니다.

발급받은 토큰은 Spring에서 사용되니 어딘가에 복사 해놓으세요

Spring 설정

build.gradle

implementation 'org.springframework.boot:spring-boot-starter-oauth2-authorization-server'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-security

OAuth를 등록하려면 security가 있어야 합니다.

dependencies에 위 코드를 추가하여 의존성을 추가합니다.

 

application.properties

spring.security.oauth2.client.registration.github.client-id=YOUR_GITHUB_CLIENT_ID
spring.security.oauth2.client.registration.github.client-secret=YOUR_GITHUB_CLIENT_SECRET

application.properties 파일에 위 코드를 추가해주세요

그리고 YOUR... 부분에 ID와 발급한 토큰을 입력합니다.

 

 

 

이제 스프링 서버를 실행하고 localhost:8080에 접속하면 깃허브 로그인 창이 나오게 됩니다!

'Framework > SpringBoot' 카테고리의 다른 글

[SpringBoot] 스프링 부트 data.sql이 실행되지 않을 때 (data.sql not working)  (0) 2023.12.24
[Spring] Rest Template란?  (0) 2023.09.09
[SpringBoot] @OneToMany, @ManyToOne, @ManyToMany 연관 관계 매핑, @JoinTable  (0) 2023.08.30
[SpringBoot]스프링 시큐리티란? (Spring Security)  (0) 2023.08.23
[SpringBoot] AnnotationException: targets an unknown entity named : 조인 맵핑 시 데이터 타입이 다를 경우 발생하는 에러  (0) 2023.06.25
'Framework/SpringBoot' 카테고리의 다른 글
  • [SpringBoot] 스프링 부트 data.sql이 실행되지 않을 때 (data.sql not working)
  • [Spring] Rest Template란?
  • [SpringBoot] @OneToMany, @ManyToOne, @ManyToMany 연관 관계 매핑, @JoinTable
  • [SpringBoot]스프링 시큐리티란? (Spring Security)
hurlud
hurlud
나와 같은 궁금증을 가진 사람들을 위해 오늘도! 🐥
  • hurlud
    주독야독
    hurlud
  • 전체
    오늘
    어제
  • 최근 글

    • ALL (106)
      • CS (13)
      • Linux (2)
      • Deploy (7)
        • AWS (6)
        • Docker (1)
      • IDE (13)
        • IntelliJ (5)
        • Android Studio (8)
      • DB (10)
        • MySQL (6)
        • MongoDB (4)
      • Programming Language (20)
        • JavaScript (10)
        • Java (8)
        • Python (2)
      • Framework (32)
        • Node.js (6)
        • SpringBoot (17)
        • React (6)
        • NestJS (2)
      • Git | Github (4)
      • ETC (5)
      • Akka (0)
  • 링크

    • 깃허브
  • hELLO· Designed By정상우.v4.10.0
hurlud
[Spring] Spring에서 깃허브 OAuth 로그인하기
상단으로

티스토리툴바